2017-04-07 1 views
0

Camel을 사용하여 HTTPS 서버에 아주 빠른 속도 (> 1500/초)로 메시지를 POST 할 수 있기를 원합니다.KeepAlive로 Camel HTTP4 최적화하기

keepAlive를 true로 설정하려고했지만 속도가 향상되지 않습니다.

5 개의 메시지를 보내는 동안 tcpdump를 실행했고 wireshark에서 5 개의 SYN/ACK 패킷을 찾았습니다. 각 POST에서 SSL 인증서가 전송되었을 수도 있습니다. (tcpdump에 의해 캡쳐 된 102 패킷,하지만 보내고있는 것은 모두 "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 인수로 제공됩니다. POST 데이터를 사용할 수 있지만 속도가 향상되어야합니다.

[업데이트] 서버로 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" /> 

은 나뿐만 아니라 내 서버에 구성해야 뭔가가 있나요?

답변

0

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); 
} 
} 
관련 문제