2

I'm using Apache camel 2.16.0 and CXF 3.1.2

How can i configure connection pooling (in cxf.xml) for all the http calls so that it can reuse the existing http connection instead of create a new connection every time ?

I see too may TIME_WAIT, CLOSE_WAIT and FIN_WAIT2 for each request, How can i close idle connections ?

<bean id="http" class="org.apache.camel.component.http.HttpComponent">
        <property name="camelContext" ref="camel_context" />
        <property name="httpConnectionManager" ref="myHttpConnectionManager" />
    </bean>

    <bean id="myHttpConnectionManager"
        class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager">

        <property name="params" ref="myHttpConnectionManagerParams" />
    </bean>

    <bean id="myHttpConnectionManagerParams"
        class="org.apache.commons.httpclient.params.HttpConnectionManagerParams">
        <property name="connectionTimeout" value="20000" />
        <property name="soTimeout" value="20000" />
        <property name="defaultMaxConnectionsPerHost" value="5" />
        <property name="maxTotalConnections" value="10" />
    </bean>

seems like maxTotalConnections isn't working ! maxTotalConnections is 10 but when i do a load test i can see more than 230 ESTABLISHED connections.. not only this all the properties like connectionTimeout, soTimeout, defaultMaxConnectionsPerHost are all ignored !

any help is appreciated..

user7484208
  • 209
  • 2
  • 5
Nitesh Jain
  • 177
  • 2
  • 13
  • Not an expert in Camel / CXF integration, but as I recall, the CXF HTTP conduit is NOT an Apache HttpClient so configuring the camel Apache HttpClient and hoping to have any impact on CXF seems like a lost cause to me ! – GPI Sep 02 '16 at 09:28
  • please check the edited version, i'm using bean configuration for connection pooling and it isn't working as expected, am i missing anything here ? – Nitesh Jain Sep 06 '16 at 03:39
  • 1
    As I said : configuring any org.apache;commons.httpclient beans has ZERO chance of doing ANYTHING to CXF, as CXF does not use HTTPClient. It's simply unrelated. See http://stackoverflow.com/questions/29941681/http-connection-pooling-in-apache-cxf, http://stackoverflow.com/questions/9664384/cxf-increase-connection-pool-size-without-changing-http-maxconnections, and http://cxf.apache.org/docs/asynchronous-client-http-transport.html and http://cxf.547215.n5.nabble.com/HTTP-Connection-Pooling-td561783.html – GPI Sep 06 '16 at 07:29
  • Google "setting system properties from Spring" yields http://stackoverflow.com/questions/3339736/set-system-property-with-spring-configuration-file (but you should be carreful, System properties are JVM wide) – GPI Sep 06 '16 at 08:36
  • Thanks @GPI This post says http://cxf.547215.n5.nabble.com/HTTP-Connection-Pooling-td561783.html CXF relies on the out-of-the-box java.net URL and HttpURLConnection . The JVM offers connections pooling mechanisms called "HTTP Persistent Connections". Basically, you have to define the JVM property "http.maxConnections" (default 5) to a higher value. How do i configure this in my context xml ? – Nitesh Jain Sep 06 '16 at 08:38
  • @GPI , the result is the same :( , i can still see 100+ established connection even after adding 10 – Nitesh Jain Sep 06 '16 at 11:11
  • @Nitesh Jain, https://stackoverflow.com/questions/53720957/java-exact-meaning-http-maxconnections - This could be the reason that you see more than 10 HttpConnections even if you have configured 10 as the value for maxConnections. – Balaji Apr 22 '20 at 07:35

0 Answers0