我希望能够使用 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" />
我还需要在我的服务器上配置其他东西吗?