Performance issues running nginx in a docker container

前端 未结 2 728
一向
一向 2020-12-08 22:34

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 containe

相关标签:
2条回答
  • 2020-12-08 22:59

    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.

    0 讨论(0)
  • 2020-12-08 23:20

    I'd like to add to @Andrian Mouat's answer, something I've just found in the docs.

    It is written in the Docker run reference:

    NETWORK: HOST

    Compared to the default bridge mode, the host mode gives significantly better networking performance since it uses the host’s native networking stack whereas the bridge has to go through one level of virtualization through the docker daemon.

    It is recommended to run containers in this mode when their networking performance is critical, for example, a production Load Balancer or a High Performance Web Server.


    Some tests with Flame Graphs follow:

    When using the host’s native networking stack with --net=host, there are fewer system calls and this is clearly depicted in the following Flame Graphs. Details:

    • system wide captures for 30sec: sudo perf record -F 99 -a -g -- sleep 30
    • ab test from another physical machine: ab -n 50000 -c 1000 http://my-host-ip/ (takes place while capturing)

    For more info on Flame Graphs, check Brendan Gregg's website: www.brendangregg.com/

    Flame Graph when publishing port -p 80:80:

    Full picture here

    Zoomed to nginx part:

    docker nginx flame graph publish port zoomed



    Flame Graph when using --net=host:

    Full picture here

    Zoomed to nginx part:

    docker nginx flame graph net host zoomed

    0 讨论(0)
提交回复
热议问题