Estimating threads and connection of a server

Hey,
I’m on a project which is about a board game. How can I approximately calculate max threads and max connections that the server can handle? Is there any way except waiting the server to throw any exception?
Sincerely

PS: The server sends all the clients a message about who joined a table or who quit one, and messages about the moves of the clients to a table (there are 4 players playing on a table)

Stress test the server by creating lots of dummy clients which send data to the server (about the same way as normal players would), and see how many clients the server can handle. Measure memory usage, CPU usage and response times during the test. Then you’ll have an estimation.

If you find that you need more speed, use a Java profiler for finding the bottlenecks in your code.

Since you talked about “calculating max threads that the server can handle”, I got to wondering that what kind of a threading architecture do you use? If you have one thread for each game or client, it will greatly lower the performance of the server, because of the time required by thread context changes. It is faster to have only a few threads (ideally one per CPU core) which handle lots of clients.

I planned to use a thread per client. The server is a dual core machine. Wouldn’t it be a problem if thousands of clients send messages to one thread?

If you use the java.nio package for networking, you don’t need to use any threads at all.

Well, that is not entirely correct. If there are a lot of users connected, threading will be necessary in order to even the response times…

What can 2 thread what 1 thread can’t?

IO never blocks, so the CPU can run at 100% handling incoming and outgoing
packets. With non-blocking IO in 1 thread, your response-times will be exactly
the same, if not better, as you don’t have to synchronize.

I don’t know if I miss something, but I think this statement is only true for similar requests or requests of the same duration. If you have different “commands” and some of them take a large amount of time, using just one thread will block the processing of the shorter commands while the time consuming ones are executed.