1

I am having trouble with Tomcat 9, openjdk 11.0.9.1 on ubuntu 18.04. I installed it using these instructions: https://linuxize.com/post/how-to-install-tomcat-9-on-ubuntu-18-04/

It worked fine for a while, but today when I try to go to any application or any of the Tomcat manager pages, my browser hangs. The service has not been restarted in the interim. I find nothing of interest in any of the Tomcat logs.

I tried "systemctl status tomcat", and I see Tasks is 35 with a limit of 37. It worries me that there appears to be almost no headroom.

So three questions:

  1. What are Tasks? Are they Threads? Processes? Something else?

  2. Where do the 35 and 37 come from? Is the 37 based on the size of my server (which is admittedly small right now)?

  3. Is it reasonable that my Tomcat hang might be related to this?

Sample systemctl status output (note that the uptime you see here reflects the fact that I have since tried restarting the service, with no improvement):

# systemctl status tomcat
● tomcat.service - Tomcat 9 servlet container
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-02-04 14:18:27 PST; 40min ago
  Process: 194 ExecStart=/opt/tomcat/latest/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 212 (java)
    Tasks: 35 (limit: 37)
   CGroup: /system.slice/tomcat.service
           └─212 /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/latest/conf/logging.pro

Feb 04 14:18:16 cloud.wolfeld.com shutdown.sh[20873]: /opt/tomcat/latest/bin/catalina.sh: 574: /opt/tomcat/latest/bin/catalina.sh: C
Feb 04 14:18:16 cloud.wolfeld.com systemd[1]: tomcat.service: Main process exited, code=exited, status=143/n/a
Feb 04 14:18:16 cloud.wolfeld.com systemd[1]: tomcat.service: Control process exited, code=exited status=2
Feb 04 14:18:16 cloud.wolfeld.com systemd[1]: tomcat.service: Failed with result 'exit-code'.
Feb 04 14:18:16 cloud.wolfeld.com systemd[1]: Stopped Tomcat 9 servlet container.
Feb 04 14:18:27 cloud.wolfeld.com systemd[1]: Starting Tomcat 9 servlet container...
Feb 04 14:18:27 cloud.wolfeld.com startup.sh[194]: Existing PID file found during start.
Feb 04 14:18:27 cloud.wolfeld.com startup.sh[194]: Removing/clearing stale PID file.
Feb 04 14:18:27 cloud.wolfeld.com startup.sh[194]: Tomcat started.
Feb 04 14:18:27 cloud.wolfeld.com systemd[1]: Started Tomcat 9 servlet container.
2
1

Thanks all for the help. I increased the size of my server, as well as the memory allocated to my JVM, but that did not help. I had expected the Tasks limit to increase automatically upon reboot or something, but it didn't.

Eventually I learned that the Tasks limit's default value of 37 was a linux compile time default, and not dependent on any heuristic examination of the runtime environment. Once I overrode it to 100 in /etc/systemd/system.conf, reloaded the systemd configuration and restarted the Tomcat service, the application worked again.

DefaultTasksAccounting=yes
DefaultTasksMax=100

I'll have to watch the JVM and system memory usage, but for now I'm good. Thanks again.

0

Looking in the tutorial you provided, tomcat's system logging takes place in the file /opt/tomcat/latest/logs/catalina.out. You should look there in order to find more information about the reason Tomcat stopped.

A common problem for a Tomcat application service is the memory limit. If JVM needs more memory than the allocated, then it might stop. I don't know how many virtual hosts or applications your Tomcat currently hosts, but I may suggest to use at least 500MB per application plus 500MB for the tomcat webapps (like hostmanager).

In order to reduce the amount of memory Tomcat consumes, you should edit the file /etc/systemd/system/tomcat.service.

For example, if you host 4 applications, you should use 2500MB (4x500 + 500 = 2500), thus replace the line,

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

with

Environment="CATALINA_OPTS=-Xms512M -Xmx2500M -server -XX:+UseParallelGC"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.