将文件数据发送到多个客户端?
我试图找出为同时处理多个客户端的客户端/服务器系统编写数据传输代码的最佳方法。
我已经保留了连接的客户端列表(顺便说一句,我正在使用 NIO 非阻塞框架)。
每次读/写传递都迭代每个客户端并将缓冲区数据写入每个通道,这是否会降低性能?有更好/更有效的方法吗?
我一直在考虑根据客户端数量划分缓冲区大小。这是一个可行的解决方案吗?
I'm trying to figure out the best way to go about writing data transfer code for a client/server system that handles multiple clients at once.
I'm already keeping a List of clients who connect (I'm using NIO non-blocking framework btw).
Isn't it costly on performance to iterate through every client with each read/write pass and write the buffer data to each channel? Is there a better/more efficient way of doing it?
I've been thinking about dividing up the buffer size based on the number of clients. Is that a viable solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您处理大量客户端时,使用选择器(正如您似乎正在做的那样)确实值得(以及为什么要针对您没有拥有大量客户端的情况进行优化; )
这样的系统中的瓶颈很少是执行迭代的CPU,而是I/O,所以我不会担心我在哪里。
Using selectors (as you seem to be doing) really pays when you're handling a really large number of clients (and why optimize for the case in which you don't have a large number of clients ;)
The bottleneck in such system is rarely the CPU which does the iteration, but the I/O anyway, so I wouldn't worry if I where you.