繁体   English   中英

在docker容器中运行nginx的性能问题

[英]Performance issues running nginx in a docker container

我正在使用ApacheBench(ab)来测量Linux上两个nginx的性能。 他们有相同的配置文件。 唯一的区别是nginx在docker容器中运行。

主机系统上的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

Docker容器中的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桥接网络? 如果是这样,请尝试使用--net=host运行测试,看看结果如何。

我想补充@Andrian Mouat的答案,我刚刚在文档中找到了答案。

它是在Docker运行参考中编写的:

网络:主持人

与默认bridge模式相比, host模式提供了明显更好的网络性能,因为它使用主机的本机网络堆栈,而桥接器必须通过docker守护程序进行一级虚拟化

建议在网络性能至关重要时以此模式运行容器,例如生产负载均衡器或高性能Web服务器。


使用Flame Graph的一些测试如下:

当使用主机的本机网络堆栈与--net=host ,系统调用较少,这在下面的Flame --net=host中清楚地描述。 细节:

  • 系统范围捕获30秒: sudo perf record -F 99 -a -g -- sleep 30
  • 来自另一台物理机的ab测试: ab -n 50000 -c 1000 http://my-host-ip/ (捕获时发生)

有关Flame Graphs的更多信息,请访问Brendan Gregg的网站: www.brendangregg.com/

发布端口-p 80:80时的Flame Graph:

这里全貌

放大到nginx部分:

docker nginx flame graph发布端口缩放



使用--net=host时的Flame Graph:

这里全貌

放大到nginx部分:

docker nginx flame graph net host zoom

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM