Tomcat 用KeepAlive优化Camel-HTTP4

Tomcat 用KeepAlive优化Camel-HTTP4,tomcat,https,apache-camel,keep-alive,camel-http,Tomcat,Https,Apache Camel,Keep Alive,Camel Http,我希望能够使用Camel以相当快的速率(>1500/秒)将消息发布到HTTPS服务器,只需使用一个到服务器的连接 我试着将keepAlive设置为true,但我仍然看不到速度有任何提高 在发送5条消息时使用了tcpdump,我在wireshark上发现了5个SYN/ACK数据包。 可能每个POST上都会发送SSL证书。(tcpdump捕获了102个数据包,但我发送的所有数据包都是5个“HelloWorld”字符串) 我有什么办法可以加快速度吗?这是我使用的代码: CamelContext

我希望能够使用Camel以相当快的速率(>1500/秒)将消息发布到HTTPS服务器,只需使用一个到服务器的连接

我试着将keepAlive设置为true,但我仍然看不到速度有任何提高

在发送5条消息时使用了tcpdump,我在wireshark上发现了5个SYN/ACK数据包。 可能每个POST上都会发送SSL证书。(tcpdump捕获了102个数据包,但我发送的所有数据包都是5个“HelloWorld”字符串)

我有什么办法可以加快速度吗?这是我使用的代码:

    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);
SSL证书详细信息作为JVM参数提供。我可以发布数据,但速度有待提高

[更新]我正在使用Apache Tomcat 8作为服务器。 在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" />


我还需要在服务器上配置其他东西吗

让它与netty4Http组件一起工作。 以下是一些示例代码:

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);
}
}
专用数据编写器(){
this.context=新的DefaultCamelContext();
试一试{
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(“内容类型”、“应用程序/json”);
this.headers.put(“CamelHttpMethod”、“POST”);
String trustCertificate=“&ssl=true&passphrase=“+”123456“+”&keystrefile=”
+“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”
+信任证书;
这个.template.start();
this.context.start();
}捕获(最终异常e){
LOG.error(“启动骆驼上下文时异常”,e);
}
}
公共void sendData(最终字符串消息){
试一试{
CompletableFuture=this.template.asyncRequestBodyAndHeaders(this.endpoint,message,this.headers);
System.err.println(“发送数据”+消息);
}捕获(最终执行例外){
LOG.error(“发送数据时出错”,e);
}
}