$ ab -n 100000 -c 20000 http://localhost:8080/mrs/ping
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
apr_socket_recv: Connection reset by peer (104) <<< HOW to overcome??
public class UndertowPingServer {
private static Logger log = Logger.getLogger(UndertowPingServer.class);
public static void main(String[] args) throws ServletException {
PathHandler path = Handlers.path()
.addPrefixPath("/mrs/ping", new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(
Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Server Time:" + new Date().toString() + "\n\n");
}
});
Undertow.Builder builder = Undertow.builder()
.setHandler(path)
.addHttpListener(8080, "0.0.0.0")
.setBufferSize(1024 * 16)
//this seems slightly faster in some configurations
.setIoThreads(Runtime.getRuntime().availableProcessors() * 2)
.setSocketOption(Options.BACKLOG, 500000)
.setWorkerThreads(2000)
//don't send a keep-alive header for HTTP/1.1 requests, as it is not required
.setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, false);
Undertow server = builder.build();
server.start();
log.info("micro-service running!");
}
}
通过sysctl完成所有需要的Linux内核套接字和线程设置。这就是为什么它可以毫无问题地为20k用户提供第一个90K请求。
答案 0 :(得分:1)
您可以将-r
参数添加到ab中以防止其退出。
来自https://httpd.apache.org/docs/2.4/programs/ab.html
-r
Don't exit on socket receive errors.
连接将开始超时,并且可以将测试时间延长一个超时时间。
答案 1 :(得分:0)
我刚刚解决了类似问题: blog.scene.ro/posts/apache-benchmark-apr_socket_recv
sudo sysctl -w net.ipv4.tcp_syncookies=0
这完成了这项工作。没有更多由对等方重置连接(104)。 猜猜这可能不是一个问题或xnio-api问题。
答案 2 :(得分:0)
另一个观察结果:
Undertow.Builder builder = Undertow.builder()
.setSocketOption(Options.BACKLOG, 100000) // << Does impact the REST
也可能与:
相关$ sysctl -a | grep -i sync
...
net.ipv4.tcp_max_syn_backlog = 100000