代码之家  ›  专栏  ›  技术社区  ›  CaptainHastings

请批评我的服务器设计

  •  0
  • CaptainHastings  · 技术社区  · 17 年前

    1. Client through the UI requests for price.
    2. My server accepts the message, formats it and then asynchronously
       sends to the analytical server.
    3. When the response from the analytical server arrives, format and send
       the response to the client UI.
    4. If the client likes the price, he/she will request to trade.
    5. Repeat steps 2 & 3.
    

    就设计服务器的其余部分而言,我考虑使用4个阻塞队列。当价格请求到来时,我会立即将请求插入队列(队列1)。然后,我有一个处理器,它从队列1中取出消息,对其进行格式化并将其放入另一个队列(队列2)。处理器类内部包含一个线程池(Executors.fixedThreadpool),每条消息的格式化都发生在一个单独的线程中。

    然后,我有一个包含另一个线程池的调度程序类。此调度程序类负责从Queue2获取消息并将其写入分析服务器。

    当我从分析服务器收到消息时,我将其插入另一个队列(Queue3)。我有另一个线程池,它将消息从队列中取出并格式化,然后将其放入另一个队列中(Queue4)。最后,我有另一个线程池,其中有来自Queue4的弹出消息,并发布到客户端。

    1. Allow me to tune the size of the thread pools. 
    2. Further, if needed, I can publish the messages contained in these queues
       thus allowing me to monitor all the messages that flows through my server.
    

    4 回复  |  直到 17 年前
        1
  •  2
  •   ChssPly76    17 年前

        2
  •  1
  •   Noon Silk    17 年前

    所以,如果处理消息的时间超过1秒,听起来你最终会有500个线程?

        3
  •  0
  •   kopos    14 年前

    有哪些不同的方法可以将消息从分析服务器发送回主服务器(然后主服务器将其转发给客户端)?

        4
  •  0
  •   Abe    14 年前

    在我看来,这种有4个队列的设计有点过头了。你应该使用责任链设计模式,而不是这些队列。如果你使用 Netty 有了它的编码器/解码器和处理程序,你就不需要所有这些队列了。Netty还提供了一个内存感知线程池执行器,可以在另一个线程中处理事件,同时检查内存。