abishkar bhattarai
abishkar bhattarai

Reputation: 7641

How to configure properly Tomcat no of threads and jmeter ramp up period

I am doing load testing using jmeter.The configuration paramter for jmeter as follows

no of threads =299 ramp up period=1 loop count=1

This is my configuration for threads in tomcat .I am using tomcat 7

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="2500" minSpareThreads="2400"/>

I have used 4 GB of ram

MYsql max connection :150

pooling configuration

<prop key="hibernate.c3p0.acquire_increment">90</prop>
                <prop key="hibernate.c3p0.idle_test_period">28690</prop>
                <prop key="hibernate.c3p0.max_size">147</prop>
                <prop key="hibernate.c3p0.max_statements">100</prop>
                <prop key="hibernate.c3p0.min_size">147</prop>
                <prop key="hibernate.c3p0.timeout">1800</prop>          
                <prop key="hibernate.c3p0.preferredTestQuery">select 1</prop> 

This is my tomcat configuration

-Xms1024m -Xmx1024m -XX:MaxPermSize=3g

When no of threads is equal to 298 there is no problem.But,when it is increase to 299 i am getting following error org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8080 refused

But,when i increased ramp up period to 10 then there is no error.

So,it seems like the problem is related to tomcat threads and ramp up period of jmeter .

If higher the ramp up period there is no exception .But,when rampup period is lower i get the exception.

In my case i have configured minSpareThreads =2400 then as far my understanding these minimum no of threads are always available.

If concurrent requests hit the tomcat in interval of 1 in my case why there is problem in accepting connection to tomcat?

As in my case no of threads=299 which is higher than max threads so still why tomcat is not accepting connection? Any help and suggestion please?

Upvotes: 1

Views: 1280

Answers (1)

newBee
newBee

Reputation: 1319

I know its quite late but I had a very smiliar issue:

In general Tomcat uses a so called HTTP-Connector which handles all requests. By default it uses a Blocking IO (BIO) Connector in Tomcat 7. In Tomcat 8 a non-blocking is used by default.

The BIO-Connector will use 1 Thread per Connection. Until the request has completed the thread will not be available for any other processes (->blocking). The Non Blocking on the other hand can handle many connections per thread and usually you only have as many threads as cpu cores. This will prevent you from running out of threads as it will not exhaust your thread pool (which is ridiculous high at the moment).

This beeing said: When you face a lot of requests per second, you use websockets or long polling you should better switch to the NIO-HTTP-Connector. Although it has a slightly slower throughput if you have a moderate amount of requests/s we found that it scales much much better. (in case of websockets or longpolling it is actually the only real solution!).

To change the connector go to your tomcat's server.xml and look for the Connector entries. There should be 2 - HTTP and HTTPs basically. The xml-entries have a protocol attribute, set to either HTTP/1.1 or something like org.apache.coyote.http11.Http11Protocol. Change both entries to org.apache.coyote.http11.Http11NioProtocol to enable the NIO-Connector. Restart Tomcat.

Upvotes: 0

Related Questions