对于只有多个客户端的服务器,我应该使用套接字还是 nio?
我有一个程序,它从外部源读取实时套接字数据,并尽快将它们广播到多个客户端。源端数据带宽200K,客户端少于10个。
服务器和客户端在内网,千兆网卡。
目前,我使用的是 mina 1.x,它是 nio 框架。但我发现表现并没有我想象的那么好。
我在想,这个应用程序使用 nio 是否正确? (我听说nio对数千个客户端有好处)
在这种情况下传统套接字比nio有更好的性能吗?
I have a program, which read real-time socket data from a external source, and broadcast them to several clients as fast as it can. The data bandwidth from source is 200K, and the clients is less than 10.
The server and clients are in an intranet, and gigabit ethernet card.
Currently, I'm using mina 1.x, which is nio framework. But I found the performance is not as good as I expected.
I'm thinking, is it correct to use nio for this application? (I heard nio is good for thousand s of clients)
Does traditional socket have better performance than nio in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的经验,阻止 NIO 对于少量(大约 10 个)连接效果最好。然而,您使用的任何方法通常都足够快,足以使 10 Gig-E 网络饱和。 (只有在环回时才重要,或者如果您的带宽远远超过 10 Gig-E)
您使用的是什么网络?你得到什么数字?
这是我做的一个旧测试。 http://vanillajava.blogspot .com/2010/07/java-nio-is-faster-than-java-io-for.html 即使一个客户端使用任一方法都会使 1 Gb 连接饱和。顺便说一句,这是在一台旧电脑上运行的。
In my experience blocking NIO performs best for a small number (around 10) connections. However, any approach you uses is usually fast enough to saturate a 10 Gig-E network. (It only matters over loopback, or if you have much more than 10 Gig-E bandwidth)
What network are you using? What numbers are you getting?
Here is an old test I did. http://vanillajava.blogspot.com/2010/07/java-nio-is-faster-than-java-io-for.html Even one client saturates a 1 Gb connection using either approach. This was run on an old PC BTW.