1

使用 apache 基准测试 100K 请求 20K 并发用户:

   $ 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??

下面是 Undertow(版本 1.2.6 + xnio-api 3.3.1)PingServer:

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!");
        }
    }

所有需要的 linux 内核套接字和通过 sysctl 进行的线程设置都已经完成。这就是为什么它可以毫无问题地对 20k 用户执行第一个 90K 请求的原因。

4

3 回答 3

1

您可以将-r参数添加到 ab 以防止它退出。

来自https://httpd.apache.org/docs/2.4/programs/ab.html

-r

Don't exit on socket receive errors.

连接将开始超时,并且可以通过超时时间延长测试时间。

于 2018-08-27T17:09:53.640 回答
0

我刚刚发现了类似的问题: blog.scene.ro/posts/apache-benchmark-apr_socket_recv

sudo sysctl -w net.ipv4.tcp_syncookies=0 

这完成了工作。没有更多的连接被对等点 (104) 重置。猜猜这可能不是 undertow 或 xnio-api 问题。

于 2015-05-28T03:51:33.377 回答
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
于 2015-05-28T06:27:56.537 回答