Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JMeter pool HTTP connections?

Tags:

java

jmeter

I know when using the built-in Java HTTP client in a JMeter HTTP Request sampler connections may or may not be pooled, depending on the JVM implementation and configuration.

However, does JMeter pool connections when using HttpClient3.1 or HttpClient4?

There are some hints in the JMeter documentation that it may, but nothing in the documentation definitively states it.

If it does, is there a way to control the connection pool? For example, can you set the size of the pool?

like image 238
Jim Hurne Avatar asked Mar 07 '16 12:03

Jim Hurne


People also ask

What is HTTP connection pooling?

When you set up connection pooling, instead of closing the client HTTP connection after use, CICS keeps the connection open and stores it in a pool in a dormant state. The dormant connection can be reused by the same application or by another application that connects to the same host and port.

How do I monitor HTTP connection pool?

Go to Monitoring and Tuning > Performance Viewer > Current activity , select server, then in PMI viewer select Settings > Log to define logging period and format. And in Modules > Thread pools > WebContainer you can view current counter values. This is rather for short term monitoring, than for constant logging.

How does connection pooling works?

Connection pooling means that connections are reused rather than created each time a connection is requested. To facilitate connection reuse, a memory cache of database connections, called a connection pool, is maintained by a connection pooling module as a layer on top of any standard JDBC driver product.

Which class gives connection from connection pool?

In a nutshell, the class initializes a connection pool based on an ArrayList that stores 10 connections, which can be easily reused. It's also possible to create JDBC connections with the DriverManager class and Datasource implementations.


2 Answers

JMeter does some pooling of HTTP connections when using HttpClient3.1 or HttpClient4.

In both cases, connections are pooled per-thread. Connections are NOT shared across threads.

When using HttpClient3.1, JMeter uses an instance of SimpleHttpConnectionManager on each thread.

When using HttpClient4, JMeter uses an instance of a subclass of PoolingClientConnectionManager on each thread, and it uses PoolingClientConnectonManager's default settings (2 connections per route, and 20 maximum connections).

JMeter does not provide a mechanism for controlling the parameters of the connection pools.

I had to go to JMeter's source code to find this answer. See the following links for reference (the 2.13 tagged code):

  • HTTPHC3Impl.java
  • HTTPHC4Impl.java
  • MeasuringConnectionManager.java

Note: this answer is accurate for JMeter 2.13. The answer may be different for other versions of JMeter.

like image 104
Jim Hurne Avatar answered Oct 04 '22 23:10

Jim Hurne


Update for JMeter 3: in your HTTPSampler configuration you can use the entries

 <boolProp name="HTTPSampler.concurrentDwn">true</boolProp>
 <stringProp name="HTTPSampler.concurrentPool">10</stringProp>

to specify connection pool size according to this Code-Snippet (from http://svn.apache.org/viewvc/jmeter/tags/v3_0/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?view=markup line 785ff)

      if(this.testElement.isConcurrentDwn()) {
            try {
                int maxConcurrentDownloads = Integer.parseInt(this.testElement.getConcurrentPool());
                    connManager.setDefaultMaxPerRoute(Math.max(maxConcurrentDownloads, connManager.getDefaultMaxPerRoute()));                
                } catch (NumberFormatException nfe) {
                   // no need to log -> will be done by the sampler
                }
            }
       }

The configuration via JMeter UI is a bit quirky:

switch the HTTP Sampler Configuration View to "Advanced", tick "Retrieve all embedded resources", then "Parallel Downloads" and enter a number. You may untick "Retrieve all embedded resources" after that if you don't want JMeter to parse your responses for images

like image 20
Erich Eichinger Avatar answered Oct 05 '22 00:10

Erich Eichinger