分布式系统 [英] Distributed System

查看:145
本文介绍了分布式系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用Java创建一个分布式框架,需要一些帮助来整理客户端/经理/工作人员情况的实现,如下面的伪代码所述。

I am looking to create a distributed framework in Java and need some help sorting out the implementation of a client/manager/worker situation as described in my pseudocode below.

Manager
BEGIN
    WHILE(true)     
        RECEIVE message FROM client
            IF (worker_connections > 0) THEN            
            FOR (i=0;i<worker_connections;i++) 
                SEND message TO worker[i]
            FOR (i=0;i<worker_connections;i++) 
                RECIEVE result[i] FROM worker[i]             
            SEND merge(result[]) TO client
            ELSE            
            SEND "No workers available" TO client
            END IF
    END WHILE
END

Client
BEGIN
    RECEIVE message FROM user
    SEND message TO manager
    RECEIVE message FROM manager
END

Worker
BEGIN
    WHILE(true)
        RECEIVE message FROM manager
         result = doSomething(message)
         SEND result TO manager
    END WHILE
END

到目前为止,我已经按照伪代码的描述实现了客户端,但是我遇到了经理/工作人员部分的问题,所以目前客户端只收到没有工人可用的消息。管理器可以接受多个连接,每个连接都作为线程运行,但如何区分客户端连接和工作者连接?如何跟踪当前连接的工作人员数量?

So far I have implemented the client as described in the pseudocode but i'm having problems with the manager/worker part so at the moment the client just receives the message that no workers are available. The manager can accept multiple connections, each connection is run as a thread but how do I differentiate between a client connection and worker connection? How do I keep track of the number of workers currently connected?

客户,经理和工作人员是不同机器的代表,但我只在一台机器上开发(用Java)。

The client, manager and workers are representations of different machines however I am only developing on one machine (in Java).

推荐答案


  • 问。如何区分客户端连接和工作者连接?

  • A.使用两个端口,一个用于监听来自工作人员和一个来自客户端的连接。

  • 问:如何跟踪当前连接的工作人员数量?

  • A。每次工人连接/断开连接时,都要有注册机制(可能在工人列表中)注册/取消注册。

    • Q. How do I differentiate between a client connection and worker connection?
    • A. Use two ports, one to listen to connections from workers and one from clients.
    • Q. How do I keep track of the number of workers currently connected?
    • A. Have a registration mechanism (maybe in a list of workers) to register/deregister each time a worker connects/disconnects.
    • 这篇关于分布式系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆