I am porting fat Java client code to a server architecture with a lean client.
The server needs to run one instance of the code for each client. The code is multithreaded and runs for long times (weeks) but has only occasional interaction with the client. The number of clients will be in the thousands. Each client needs ~20MB of heap.
I have now two options,
I can see pros and cons for each. For multiple JVMs:
Pros:
Cons:
Are there any best practices which you recommend?
Do you know of any good reference book / article on the subject?
Is there a framework which uses only one JVM but runs several copies of code as if it was separate process space (with limited resources etc)?
It is sadly not possible to limit resources on a Thread basis in a single JVM. However, I would nontheless try to port your app into a single JVM, because of the following reasons:
Go with the single app approach, unless you really do not have any control over which tasks can be started by your users.
You could create a web service/proxy service which starts a JVM for each client, shuts them down. This would give you the ability to kill off requests/JVM from long running clients.
The proxy server can give the clients one port they need to talk to as the server forwards requests to the running JVM for that client.
BTW: If you have many clients running CPU intensive jobs, you only have so many cores to go around. You may find the JVMs need to run across multiple machines to support all the clients.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With