在泊坞窗容器中运行nginx的性能问题

问题描述 投票:6回答:2

我使用ApacheBench(AB)来测量两个nginx的Linux上的性能。他们有相同的配置文件。唯一不同的是Nginx的一个是在泊坞窗容器中运行。

Nginx的主机系统:

Running: ab -n 50000 -c 1000 http://172.17.0.2:7082/

Concurrency Level:      1000
Time taken for tests:   9.376 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      8050000 bytes
HTML transferred:       250000 bytes
Requests per second:    5332.94 [#/sec] (mean)
Time per request:       187.514 [ms] (mean)
Time per request:       0.188 [ms] (mean, across all concurrent requests)
Transfer rate:          838.48 [Kbytes/sec] received

Nginx的在泊坞窗容器:

Running: ab -n 50000 -c 1000 http://172.17.0.2:6066/

Concurrency Level:      1000
Time taken for tests:   31.274 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      8050000 bytes
HTML transferred:       250000 bytes
Requests per second:    1598.76 [#/sec] (mean)
Time per request:       625.484 [ms] (mean)
Time per request:       0.625 [ms] (mean, across all concurrent requests)
Transfer rate:          251.37 [Kbytes/sec] received

只是想知道为什么容器一个有这样的表现不佳

nginx.conf:

worker_processes  auto;
worker_rlimit_nofile 10240;

events {
    use epoll;
    multi_accept on;
    worker_connections  4096;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  10;

    client_header_timeout 10;
    client_body_timeout 10;

    send_timeout 10;

    tcp_nopush on;
    tcp_nodelay on;

    server {
        listen       80;
        server_name  localhost;
        location / {
            return 200 'hello';
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
docker nginx
2个回答
5
投票

你是如何运行的容器?难道使用默认泊坞桥网络?如果是这样,请尝试使用--net=host运行测试,看看结果是什么样子。


2
投票

我想补充到@Andrian Mouat's的答案,这是我刚刚在文档中找到。

这是写在Docker run reference

NETWORK: HOST

相较于默认bridge模式下,host模式使显著更好的网络性能,因为它使用主机的本地网络协议栈,而桥要经过通过泊坞窗守护程序虚拟化的一个水平。

建议当他们的网络性能是至关重要的运行在此模式下的容器,例如,生产负载平衡器或高性能Web服务器。


与火焰图形一些测试如下:

当使用--net=host主机的本地网络协议栈,有更少的系统调用,这在下面的火焰图形清晰显示。细节:

  • sudo perf record -F 99 -a -g -- sleep 30:30秒全系统捕获
  • 从另一个物理机AB试验:ab -n 50000 -c 1000 http://my-host-ip/(发生在捕捉)

有关火焰图形的详细信息,请布伦丹·格雷格的网站:www.brendangregg.com/

Flame Graph when publishing port -p 80:80:

全画面here

放大到nginx部分:

Flame Graph when using --net=host:

全画面here

放大到nginx部分:

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