Hi....
I am developing a server which needs to do some work for its
client. It may be some calculation that takes some half or one sec. How
should implements.. should i go for ServerSocket with threads or
NIOServers ?
Just giving the calculation time tells us nothing. We also need to know:
1) the required response time per request
2) how many clients will use the server simultaneously
3) what are the min/average/max request rates per server and in total.
4) is the server handling stateless, i.e. unrelated requests or
does it need to keep a session history for each client?
5) does the server use any shared resources such as a
method that requires locking or a database that it updates?
If you don't know these details which WILL drive the structure of a
heavily used server, then about all you can do is write an unoptimised
first cut version, instrument it to collect statistics for items 1-3 and
release it for production use, see how it performs and be prepared to
rewrite it as needed.
All the performance testing in the world is meaningless if the volumes
and arrival rates don't match what happens in real life.
The server should be designed for change from the outset, not just thrown
together. I'd start with a threaded design that creates a thread for each
incoming connection and kills it when the client disconnects. I'd also
design it with good isolation between the application-specific
calculations and the server management code. Make sure that the
calculation is modular and that each module is instrumented. This way
heavily used and/or resource-intensive modules can be spotted and
replicated more easily.