How to optimize performance for a docker container?

前端 未结 2 1261
半阙折子戏
半阙折子戏 2020-12-14 21:54

I tested redis container based on. https://index.docker.io/u/dockerfile/redis/

With same redis-benchmark, redis-server runs inside a container much slower, than run

2条回答
  •  孤城傲影
    2020-12-14 22:13

    The container appears to be slower because you are going through an extra network layer.

    In that case, instead of connecting directly to Redis, to connect to the Docker userland proxy, which itself connects back to the container (and instead of going over a local interface, this connection goes over a veth interface).

    This adds a little bit of latency (not measurable compared to, e.g, a 10ms webpage generation; but 50µs is still faster than 150µs, if you see what I mean).

    If you want to do a more "apples to apples" comparison, you could:

    • run redis-benchmark inside the container (to connect directly to Redis from within the container);
    • run redis-benchmark on another machine (but keep in mind that you will still have an extra network layer for the port translation mechanism);
    • run redis-benchmark on another machine and use a mechanism like pipework to give the container a macvlan interface with (almost) zero overhead.

提交回复
热议问题