Search code examples
javasocketsnio

Should I use socket or nio for a server with only several clients?


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?


Solution

  • 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.