简体   繁体   中英

Java NIO in both server and client?

I am new to Java NIO.I have a small doubt. If I use the NIO instead of a socket client, should the server also be using NIO or does it not matter?

I am concerned about application scalability. I am looking at around 500-1000 client requests per seconds per server. Since I would send my data to atleast three different servers, I am ideally looking at around 1500 client requests per second. For this, I already have a socket pool implementation in place which does a fairly decent job.

What I have is a pool of socket connections for each server.Each thread picks up an available socket connection from the pool and sends it to the server

I am trying to find out if NIO can help or is better in any way than a socket client. How about blocking ? Normal client would either block or timeout.

It doesn't matter. The TCP stream will be unaffected by your choice of NIO.

imho you won't get any more performance out of your client by using NIO. The bottleneck will be either the server or the network. Also, NIO is more complex and it's likely that you'll get something wrong that will hurt performance.

I would start by doing a socket implementation to get it up and running more quickly. If you follow some common patterns/principles like Single Responsibility Principle it would be easy to switch implementation later on (if you or your users have proved that your applications performance is the bottleneck which I find highly unlikely).

Update

What NIO or any other asynchronous framework does it to let multiple operations share the same threads. Having one thread per connection when dealing with a lot of connections is a waste of resources since all threads will not be active all the time.

Using NIO for a client will not give you any benefits if you have just a few connections. Having a thread+socket per connection doesn't consume that much resources and it will be easier to handle the connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM