在Docker容器中运行Nginx的性能问题 [英] Performance issues running nginx in a docker container

查看:430
本文介绍了在Docker容器中运行Nginx的性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using ApacheBench (ab) to measure the performance of two nginx on Linux. They have same config file. The Only difference is one of nginx is running in a docker container.

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

只是想知道为什么容器的性能这么差

Just wondering why the container one has such a poor performance

nginx.conf:

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运行测试,然后查看结果.

How are you running the container? Is it using the default Docker bridge network? If so, try running the tests with --net=host and see what the results look like.

这篇关于在Docker容器中运行Nginx的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆