0

I have a tomcat 7 running on a low memory CentOS. Currently it has 2 connectors for ports 80 and 443. Important configuration options are:

<Connector port="80" protocol="HTTP/1.1" executor="tomcatThreadPool"
                connectionTimeout="10000"
                keepAliveTimeout="60000"

<Connector port="443" protocol="HTTP/1.1" executor="tomcatThreadPool"
                SSLEnabled="true" scheme="https" secure="true"
                connectionTimeout="10000"
                keepAliveTimeout="60000"

Both connectors is bound to an executor:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
                maxThreads="100" minSpareThreads="3"
                maxIdleTime="120000" />

When tomcat is first started, it starts about 50 threads. After about 15-20 users connecting to web application, it is increased to about 60. (I count tomcat threads with command ps -eLf | grep java |grep tomcat |wc -l)

I have about 4 connections per minute, it is not more than 5 due to the nature of my application. Therefore I want tomcat to start minimum possible threads. Since I have configured minimum of 3 spare threads and keepalive as 2 minutes, it should not go over 20 or something. But I am wrong.

How can I limit the number of Tomcat threads to a minimum value like 20 or 30?

030
  • 5,901
  • 13
  • 68
  • 110
jdiver
  • 135
  • 1
  • 4
  • 9

1 Answers1

1

According to this documentation the number of minimum threads can be configured using the following parameter:

Attribute Description
minSpareThreads(int) The minimum number of threads always kept alive, default is 25

According to this documentation it could be implemented as follows:

<Connector port="8080" address="localhost"     
     minSpareThreads="20" />

At server startup, the HTTP Connector will create a number of processing threads based on the value configured for the minSpareThreads attribute.

030
  • 5,901
  • 13
  • 68
  • 110
  • I used an executor and defined minSpareThreads but it does work. Should I use just connector and define minsparethreads? As answered here executor allows to share a thread pool by connectors http://stackoverflow.com/questions/9626211/tomcat-thread-pool-commented-out-in-tomcat-conf-should-i-use-it – jdiver Nov 14 '14 at 20:58
  • @jdiver did you restart Tomcat after changing the server.xml? – 030 Nov 14 '14 at 21:01
  • Of course; I keep restart tomcat once each 2 days because it consumes all memory. – jdiver Nov 14 '14 at 21:02
  • Ok that is interesting. Do you use a tool like JVisualVM to investigate the threads? Which tools are you using? I assume that you are using certain tools as you provide information regarding the amount of threads in the question. – 030 Nov 14 '14 at 21:03
  • I just restarted now and there are 52 threads. Actually I don't understand why it is starting about 50 threads each time. – jdiver Nov 14 '14 at 21:05
  • I just use ps command : ps -eLf | grep java |grep tomcat |wc -l and pstree – jdiver Nov 14 '14 at 21:06
  • @jdiver What is the number of maxThreads? Could you change it to 10 and the min to e.g. 5? – 030 Nov 14 '14 at 21:06
  • maxThreads value is 100 – jdiver Nov 14 '14 at 21:06
  • @jdiver it should be decreased if the number of maxThreads will be changed to e.g. 10. Could you verify this? – 030 Nov 14 '14 at 21:07
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/18665/discussion-between-jdiver-and-utrecht). – jdiver Nov 14 '14 at 21:08