如何解决高并发Apache HTTP Server SSL问题
我有一个HTTP服务器应用程序,在正常的HTTP流量下(〜10k个请求/秒)可以正常工作,但是当流量变大时,它开始无响应(约30秒到1分钟),没有任何AV或任何其他提示问题的线索。在这段时间之后,它将恢复并开始正常工作,直到再次“睡眠”为止。从应用程序日志来看,问题似乎出在SSL流量上,在进行SSL握手后,当服务器响应时,需要花费几秒钟的时间将下一个软件包发送到HAProxy:
服务器无响应时超过30秒(在这种情况下为1分半钟):
我如何创建连接池:
//create the SSL Context for the connection factory
SSLContext sslContext = null;
try{
sslContext=SSLContext.getDefault();
}catch(NoSuchAlgorithmException e){
logger.error(e.getMessage(),e);
}
BasicNIOConnFactory connFactory=new BasicNIOConnFactory(sslContext,null,ConnectionConfig.DEFAULT);
clientConnectionPool=new BasicNIOConnPool(requestsReactor,connFactory,0);
clientConnectionPool.setDefaultMaxPerRoute(30000);
clientConnectionPool.setMaxTotal(30000);
和一个将请求转发到HAProxy的HttpAsyncRequester客户端:
private HttpAsyncRequester initializeHttpClientForCalls(final ConnectingIOReactor ioReactor)
throws IOReactorException {
// Create HTTP protocol processing chain
HttpProcessor httpproc = HttpProcessorBuilder.create()
// Use standard client-side protocol interceptors
.add(new RequestContent(true)).
add(new RequestTargetHost()).
add(new RequestConnControl())
.add(new RequestExpectContinue(true)).
build();
// Create HTTP requester
HttpAsyncRequester requester = new HttpAsyncRequester(httpproc);
// Create client-side HTTP protocol handler
HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
// Create client-side I/O event dispatch
final IOEventdispatch ioEventdispatch =
new DefaultHttpClientIOdispatch<>(protocolHandler,ConnectionConfig.DEFAULT);
// Run the I/O reactor in a separate thread
new Thread(new Runnable() {
@Override
public void run() {
try {
// Ready to go!
ioReactor.execute(ioEventdispatch);
} catch (InterruptedioException ex) {
logger.error("Interrupted",ex);
} catch (IOException e) {
logger.error("I/O error",e);
}
catch (Exception e){
logger.error("Exception encountered in Client ",e.getMessage(),e);
}
logger.info("Client calls shutdown");
}
},"Client for calls").start();
return requester;
}
通话:
clientRequester.execute(new BasicAsyncRequestProducer(httpHost,request),new BasicAsyncResponseConsumer(),clientConnectionPool,coreContext,// Handle HTTP response from a callback
new FutureCallback<HttpResponse>() {
IOReactor分配了16个线程。增加线程数并不能提高性能
IOReactorConfig requestsConfig = IOReactorConfig.
custom().
// setSoLinger(0).
setSoReuseAddress(true).
setIoThreadCount(16).
build();
// Create server-side I/O reactor
requestsIoReactor = new DefaultListeningIOReactor(requestsConfig);
在部署了应用程序的服务器上与Java VisualVM连接并针对该应用程序运行一批aprox 400 SSL请求表明,对请求的自定义处理不会浪费时间:
Java版本:
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13,mixed mode)
具有最新的org.apache.httpcomponents。
我知道这个问题Highly Concurrent Apache Async HTTP Client IOReactor issues,并且可能阅读了有关该主题的所有问题,但是它没有为我的问题提供解决方案。有没有办法提高SSL性能?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。