I want to be able to POST messages to an HTTPS server using Camel at a pretty fast rate ( > 1500/sec) using only one connection to the server.
I tried setting keepAlive to true, but I still cant see any improvement in speed.
Took the tcpdump while sending 5 messages, and I find 5 SYN/ACK packets on wireshark. Possibly the SSL certificate is also being sent on each POST. (102 packets captured by the tcpdump, but all I am sending are 5 "HelloWorld" strings)
Is there any way I can speed things up? This is the code I used:
CamelContext context = new DefaultCamelContext();
final HttpComponent http = (HttpComponent) context.getComponent("https4");
http.setConnectionsPerRoute(1);
http.setMaxTotalConnections(1);
HttpConfiguration httpConfiguration = new HttpConfiguration();
http.setHttpConfiguration(httpConfiguration);;
context.addComponent("fcpHttpComponent", http);
template = context.createProducerTemplate();
headers.put(Exchange.CONTENT_TYPE, "application/json");
headers.put(Exchange.HTTP_METHOD, HttpMethods.POST);
final String endpoint = "https://xxx.xxx.xxx.xxx:443";
try {
httpEndpoint = new HttpEndpoint(endpoint, http, new URI(endpoint));
httpEndpoint.configureProperties(headers);
PoolingHttpClientConnectionManager clientConnectionManager = new PoolingHttpClientConnectionManager();
SocketConfig socketConfig = SocketConfig.custom()
.setSoKeepAlive(true)
.setSoReuseAddress(true)
.setTcpNoDelay(true)
.setSndBufSize(10)
.build();
clientConnectionManager.setDefaultSocketConfig(socketConfig);
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setMaxConnPerRoute(1);
clientBuilder.setConnectionManager(clientConnectionManager);
clientBuilder.build();
ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy();
clientBuilder.setKeepAliveStrategy(keepAliveStrategy );
httpEndpoint.setClientBuilder(clientBuilder);
httpEndpoint.setClientConnectionManager(clientConnectionManager);
template.start();
context.start();
} catch (final Exception e) {
LOG.error("Exception while starting Camel context ", e);
}
//Call this method 5 times
template.asyncRequestBodyAndHeaders(httpEndpoint, message, headers);
The SSL certificate details are given as JVM arguments. I am able to POST data but the speed is something I need to improve.
[Update] I am using Apache Tomcat 8 as my server. Set the following in server.xml:
<Connector
protocol="org.apache.coyote.http11.Http11NioProtocol"
port="443" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile="/x/store.jks" keystorePass="y"
clientAuth="false" sslProtocol="TLS" maxKeepAliveRequests="-1" keepAliveTimeout="-1" />
Is there something else I need to configure on my server as well?