0

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?

7
  • interested to know what would be the best solution in this situation
    – Kaipa M Sarma
    Oct 13, 2012 at 11:56
  • 2
    How will it respond to a request if its asleep? Tomcat should not be consuming noticeable amounts of CPU when not processing a request. Time to look at your app to see what's wrong with it. Oct 13, 2012 at 11:58
  • @PaulTomblin; "How will it respond to a request if its asleep?" That is my question. Can we use some kind of loadbalancer (like nginx) or something maybe to wake it up? "Tomcat should not be consuming noticeable amounts of CPU when not processing a request" I guessed so but there is nothing wrong with a single page JSP and 1 connection to MongoDB on this single page. Oct 13, 2012 at 12:01
  • 1
    How did you confirmed that tomcat is causing high cpu load
    – Kaipa M Sarma
    Oct 13, 2012 at 12:17
  • 2
    I bet if you run strace on your tomcat instance, you'll find out something in your app is doing something stupid, like busy waiting or polling a resource. Oct 13, 2012 at 18:03

3 Answers 3

4

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

$ free
            total       used       free     shared    buffers     cached
Mem:       7858068    7391512     466556          0     114304    2853220
-/+ buffers/cache:    4423988    3434080
Swap:      2101244     219372    1881872

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.

1

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

0

You should stop the service if you don't need it.

1
  • OP wants the server still be processing when there is a request. Stopping the service wont help
    – Kaipa M Sarma
    Oct 13, 2012 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .