1

我正在设计一个(近乎)实时的 Netty 服务器,用于将大量非常小的消息分发给 Internet 上的大量客户端。在内部,尽可能快地进行测试,我发现我可以毫不费力地处理 10k 个客户端,但是现在我们正在尝试通过互联网,延迟、带宽等变化非常大,我们遇到了可怕的 outOfMemory问题,即使有 2 GB 的 RAM。

我尝试了各种解决方法(将套接字堆栈大小设置得更小,设置高低水位标记,取消太旧的东西),它们有一点帮助,但它们似乎只有一点点帮助。有什么好的方法可以优化 Netty 以在没有明显延迟的情况下发送大量的小消息?此外,大部分消息仅包含一种消息,如果它没有到达,我并不特别在意。我会使用 UDP,但因为我们不控制客户端,所以这不太可能。是否可以单独为此类消息设置单独的超时而不影响其他消息?

您能提供的任何见解将不胜感激。

4

3 回答 3

0

You don't say whether the subscription stream is constant or bursty. You also don't say whether there is a minimum number of messages / second the client must support.

Given that I don't know anything about Redis, are any of the following practical?

  • For the messages you don't care about, if channel.isWritable() == false, discard immediately. Unfortunately I don't know of a way to cancel messages that are in Netty's send buffer. You wouldn't be able to cancel messages that have been passed to the TCP send buffer anyway so it's not really something to rely on.
  • Slow reception from the subscription to the rate of the slowest client.
  • Determine which clients can't keep up (maybe use the write timeout handler) and move them to a separate subscription which can be slowed down. Duplicate the published messages to both subscriptions.
  • Can you split the messages to send to the clients across different subscriptions. If a client can't keep up unsubscribe it from the unimportant messages.

If your average send rate is higher than the client can support over time then there isn't really a solution other than negotiating a change in requirements to reduce the maximum allowable throughput.

于 2012-09-25T09:36:15.163 回答
0

您可能想研究负载平衡方法。它用于使用硬件和软件在分布式系统中分配工作负载。适合您系统的详细信息取决于几个因素,包括硬件升级等。当然,2GB 的 RAM 对于服务器 10k 用户来说相当小,您需要增加此限制。

于 2012-09-24T15:02:03.710 回答
0

通常,如果看到 outOfMemory,您可以使用线程转储工具来转储线程。或者使用 jvirtualvm 和 jconsole 之类的东西来找出哪个类没有被 GC 并继续吃掉你的记忆。2Gigs 对于现在的 64 位机器来说并不大。试着把这个数字变大到 3 或 4 G 左右,看看你是否没有遇到 OOM。如果您发现可以在 LAN 中轻松处理 10k 连接,请尝试在您的 netty 处理程序中添加一个小延迟。检查会发生什么。

于 2012-09-24T13:56:53.347 回答