运行“空”Undertow 时每秒 HTTP 请求的限制因素是多少?

问题描述 投票:0回答:1

我正在运行一个非常简单的 Undertow 配置。包含完整代码:

public class HelloWorldUndertow {
    public static void main(String[] args) {
        Undertow undertow = Undertow.builder()
                .addHttpListener(9090, "0.0.0.0")
                .setHandler(new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        exchange.setResponseCode(200);
                        exchange.getResponseSender().send("hello!");
                    }
                }).build();
        undertow.start();
    }
}

我尝试测试它每秒可以处理多少个请求。我正在使用 apache

ab
工具进行测量:

ab -n 100000 -c 10 http://localhost:9090/test

我设法获得的最大数字约为 10000 3/秒:

Concurrency Level:      10
    Time taken for tests:   10.664 seconds
    Complete requests:      100000
    Failed requests:        0
    Total transferred:      10000000 bytes
    HTML transferred:       600000 bytes
    Requests per second:    9377.69 [#/sec] (mean)
    Time per request:       1.066 [ms] (mean)
    Time per request:       0.107 [ms] (mean, across all concurrent requests)
    Transfer rate:          915.79 [Kbytes/sec] received

    Connection Times (ms)
    min  mean[+/-sd] median   max
    Connect:        0    0   0.2      0       1
    Processing:     0    1   0.5      1      11
    Waiting:        0    1   0.5      1      11
    Total:          0    1   0.5      1      11

    Percentage of the requests served within a certain time (ms)
    50%      1
    66%      1
    75%      1
    80%      1
    90%      2
    95%      2
    98%      2
    99%      2
    100%     11 (longest request)

我知道它很大,但我很好奇这种情况下的限制因素是什么。它不是处理器(使用 Java Mission Control 采样时应用程序的运行速度低于 20%),也不是内存。我在 Windows 上运行它 - 也许这就是原因?

java windows http tcp undertow
1个回答
1
投票

我无法告诉您如何让它在 Windows 中运行时表现更好,但如果您在 Linux 中运行它,您可以在此处进行 Jetty 建议的调整:https://eclipse.dev/jetty/documentation/jetty- 9/index.html#高负载

总结:

sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216"
sysctl -w net.ipv4.tcp_wmem="4096 16384 16777216"
sysctl -w net.core.somaxconn=4096
sysctl -w net.core.netdev_max_backlog=16384
sysctl -w net.ipv4.tcp_max_syn_backlog=8192
sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_tw_recycle=1
sysctl -w net.ipv4.tcp_congestion_control=cubic

运行代码时包含

-server
JVM 参数。

然后尝试:

ab -n 100000 -c 100 http://localhost:9090/test

(使用 100 个连接发出 100,000 个请求)

当我在 Windows 7 笔记本电脑(3 年前)上的 VMware Player 中运行的 Linux 虚拟机中尝试该操作时,我每秒收到超过 100,000 个请求。

© www.soinside.com 2019 - 2024. All rights reserved.