单个docker容器在cpu性能方面稍微优于其主机:为什么?

Pra*_*tal 10 docker

我运行了一个实验,将docker容器的CPU性能与运行它的主机的CPU性能进行比较.

案例

:在主机上运行的基准程序(Intel i5,2.6 GHz,2个处理器,2个内核)
B:在同一台主机上运行的Docker容器上运行基准程序.(对于B中的容器没有资源限制.即容器本身拥有所有1024个cpu共享.没有其他容器正在运行)

基准计划:数值整合

数值积分:是大规模并行程序的标准示例.使用OpenMP lib以C++编写的标准数字集成示例程序(已经过测试,以确保其正确性).程序从1-11开始,通过程序中不同数量的可用线程运行11次.对于每个案例A和B,完成了这11次运行.因此,对于主机和11对于容器,总共执行22次运行.

X轴:程序中可用的线程数

Y轴:表示与时间相反的性能(通过将运行程序的时间倒数乘以常数计算得出).

结果 在此输入图像描述

意见

在主机上运行的docker容器略微优于主机.该实验在2个不同的宿主上重复4-5次,每次容器性能曲线略高于宿主性能曲线.

当docker容器在主机上运行时,容器性能如何高于主机?

可能的原因:docker cgroup进程的优先级较高?

我假设容器的cgroup中的进程可能获得更高的进程优先级,从而导致程序在容器内运行的性能更高,而程序直接在主机上运行时.这听起来像是一个可能的解释吗?

Pra*_*tal 3

Thanks to the comments of @miraculixx and @Zboson, which helped me understand that the container is not really outperforming the host. The strange results (plot in question) were caused because of the different compiler versions being used on host and container while performing the experiment. When Case A & B are run again after updating to the same version of compiler in both container and host, these are the results:

Without optimization flag

在此输入图像描述

With optimization flag -O3

在此输入图像描述

Observation

It can be observed that container has same or slightly less performance than host; which makes sense intuitively. (Without optimization there are a couple of discrepancies)

P.S Apologies for the misleading question title. I wasn't aware that the performance discrepancy could be because of the different compiler versions until the comments were posted.

  • 我认为这里重要的教训是仅讨论启用优化的性能。请注意,单线程优化代码几乎与具有四个线程的未优化代码一样快!四个优化线程的速度几乎是四个未优化线程的三倍!我怀疑,如果您对原始绘图使用了优化,那么您不会看到意外的差异,因为主机使用的 GCC 版本比容器更新。最后,我将使用科学记数法绘制图表,因为计算所有这些零很烦人。 (2认同)