tomcat - Optimizing Camel HTTP4 with KeepAlive -
i want able post messages https server using camel @ pretty fast rate ( > 1500/sec) using 1 connection server.
i tried setting keepalive true, still cant see improvement in speed.
took tcpdump while sending 5 messages, , find 5 syn/ack packets on wireshark. possibly ssl certificate being sent on each post. (102 packets captured tcpdump, sending 5 "helloworld" strings)
is there way can speed things up? code 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 method 5 times template.asyncrequestbodyandheaders(httpendpoint, message, headers);
the ssl certificate details given jvm arguments. able post data speed need improve.
[update] using apache tomcat 8 server. set 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 else need configure on server well?
got working netty4http component. here sample code:
private datawriter() { this.context = new defaultcamelcontext(); try { final nettyhttpcomponent nettyhttpcomponent = this.context.getcomponent("netty4-http", org.apache.camel.component.netty4.http.nettyhttpcomponent.class); this.context.addcomponent("nettyhttpcomponent", nettyhttpcomponent); this.template = this.context.createproducertemplate(); this.headers.put("content-type", "application/json"); this.headers.put("camelhttpmethod", "post"); string trustcertificate = "&ssl=true&passphrase=" + "123456" + "&keystorefile=" + "c:/users/jpisaac/certs/publickey.store" + "&truststorefile=c:/users/jpisaac/certs/publickey.store" ; this.endpoint = "netty4-http:"+ "https://xx.xx.xx.xx:8443/server" + "?usebytebuf=true&disablestreamcache=true&connecttimeout=30000&requesttimeout=30000&reusechannel=true" + "&keepalive=true&tcpnodelay=true&sync=false&reuseaddress=true&sendbuffersize=1000" + trustcertificate; this.template.start(); this.context.start(); } catch (final exception e) { log.error("exception while starting camel context ", e); } } public void senddata(final string message) { try { completablefuture<object> future=this.template.asyncrequestbodyandheaders(this.endpoint, message, this.headers); system.err.println("sent data "+message); } catch (final camelexecutionexception e) { log.error("error while sending data", e); } }
Comments
Post a Comment