I have been using Tomcat 7 on Ubuntu Server for a little website. But there are other processes working on the server and I think Tomcat has some high load on both CPU and memory. For that reason I am curious if I can put Tomcat server sleep mode while there is no response. Is there a way to do that on server automatically or there are other servlet containers which we are able to do that?
migrated from stackoverflow.com Oct 15 '12 at 9:57
I'm sorry for this anwser that might be what you expected, but :
When Tomcat receives no request, then it has nothing to do, and then consumes no CPU cycles. If you observe high CPU usage related to Tomcat when it received no request, there's something really wrong.
And, when Tomcat hasn't served requests for a long time, if your Ubuntu system needs memory, it will automatically put the memory used by Tomcat on disk : this mecanism is called swapping. Chech how much swap space you have on your Ubuntu box using the following command
If you don't have a swap partition, I strongly recommend you create one. Because this sytem behavior of putting sleeping application's memory to disk when the system needs memory is by default, and will work for any application that doesn't do anything for a 'long' time.
I'm afraid its not a tomcat but the war that loads CPU and memory :)
Tomcat by itself is a tiny program, very fast and lightweight. You can download the tomcat and examine its impact if you want to see exact numbers. On the other hand (I have to mention, although you might know that) war file(s) with the applications are handled by tomcat so that they don't spawn additional processes, in other words all the wars and tomcat itself are running in the same JVM.
So the correct solution would be to understand why does your war loads the server exactly. Technically if tomcat doesn't handle requests it should be only some kind of background job that was defined in this war of maybe some asynchronous tasks, and so forth, I guess you've got an idea. Then re-factor the war file.
What you propose is not a common practice and technically not the way to go.
Hope this helps