Reputation: 11486
I am implementing websockets in Tomcat for an intranet app that has 100 - 200 users on a regular basis.
It is being done to replace a long poll servlet that pushes the same bunch of JSON data I am going to send in on the websocket.
While doing some testing I noticed that every single websocket connection ties up a thread, when I had 50 instances of the app running there were minimally 50 busy threads.
With the long poll servlet I averaged 5 threads with all 50 instances running because the 3.0 servlet spec frees up the thread for long poll servlets.
I know that I can increase the maxThread
parameter as needed but I am concerned that if I have a few more apps with the same user base (something that is likely) I am going to require 1000 threads for tomcat that will be busy at all times.
Specifically, my questions about this are:
1) Is this normal? Is there a way of freeing up the websocket thread?
2) Is it actually a problem if I have 1000 threads devoted to keeping websockets open?
3) Should I just stick with long polling until websockets evolve some more?
Tomcat 7.0.50
Java 1.7.0_21
webserver is Windows Server 2008 R2 with 32 GB of RAM - but it is also the database server so that uses up a lot of the memory.
Upvotes: 0
Views: 848
Reputation: 262474
To make proper use of websockets, you should also use a non-blocking HTTP connector, otherwise you'll end up with a dedicated thread for each HTTP connection (and that does not scale too well). Check the Tomcat documentation on how to configure that.
Upvotes: 2