I’m trying to run jWebSocket server on CentOS 5.8 (1and1 VPS). Just after start of the server and few requests from client (reloading webpage) I get this error:
Exception in thread "jWebSocket TCP-Connector 01.33719.16" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943)
at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1555)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:333)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:546)
at java.util.concurrent.ScheduledThreadPoolExecutor.submit(ScheduledThreadPoolExecutor.java:646)
at org.jwebsocket.tcp.TimeoutOutputStreamNIOWriter.sendPacket(TimeoutOutputStreamNIOWriter.java:215)
at org.jwebsocket.tcp.TCPConnector.sendPacket(TCPConnector.java:279)
at org.jwebsocket.server.BaseServer.sendPacket(BaseServer.java:186)
at org.jwebsocket.server.TokenServer.sendPacketData(TokenServer.java:405)
at org.jwebsocket.server.TokenServer.sendTokenData(TokenServer.java:388)
at org.jwebsocket.server.TokenServer.sendToken(TokenServer.java:312)
at org.jwebsocket.plugins.TokenPlugIn.sendToken(TokenPlugIn.java:174)
at org.jwebsocket.plugins.system.SystemPlugIn.sendWelcome(SystemPlugIn.java:397)
at org.jwebsocket.plugins.system.SystemPlugIn.connectorStarted(SystemPlugIn.java:261)
at org.jwebsocket.plugins.BasePlugInChain.connectorStarted(BasePlugInChain.java:126)
at org.jwebsocket.server.TokenServer.connectorStarted(TokenServer.java:170)
at org.jwebsocket.engines.BaseEngine.connectorStarted(BaseEngine.java:93)
at org.jwebsocket.tcp.TCPEngine.connectorStarted(TCPEngine.java:320)
at org.jwebsocket.tcp.TCPConnector$ClientProcessor.run(TCPConnector.java:502)
at java.lang.Thread.run(Thread.java:722)
But when I run jWebSocket on my computer everything is working ok. I made my own virtual server using virtualbox and CentOS 5.8 fresh install and it is working there too.
I noticed that java on 1and1 VPS uses a lot of memory ~1GB (10 times more then on my computer or virtualbox). On 1and1 VPS I have 2GB of RAM (there is an error) and on Virtualbox jWebSocket is running just fine with only 512MB of RAM.
What may be the cause of this out of memory error? Please share if you have any suggestions. I don’t know what to do with this any more.
It is 1and1 (http://www.1and1.pl/) virtual hosting problem. They use Parallels Virtuozzo Containers with so called User Beancounters or UBC parameters. It is a set of limits witch was the cause of my problems. You can see this limits in /proc/user_beancounters. When one of the limits called “numproc” is reached my application can’t create new threads.
EDIT
At that time jWebSocket was designed in way that it was creating one thread for every incoming token and not destroying it when this thread was no more needed.
I’m not using jWebSocket any more, I replaced it with websocket serwer written in PHP.