我使用来自https://hub.docker.com/r/polinux/stress-ng/dockerfile的压力-纳卡图像来强调我的系统。我想使用perf工具来监控指标。
perf stat -- stress-ng --cpu 2 --timeout 10运行压力-ng 10秒,并返回性能指标。我试着使用perf stat -- docker run -ti --rm polinux/stress-ng --cpu 2 --timeout 10对码头映像做同样的处理。这将返回度量,但不返回压力-ng的度量。
当我在压力-ng上使用'perf‘时得到的输出:
Performance counter stats for 'stress-ng --cpu 2 --timeout 10':
19975.863889 task-clock (msec) # 1.992 CPUs utilized
2,057 context-switches # 0.103 K/sec
7 cpu-migrations # 0.000 K/sec
8,783 page-faults # 0.440 K/sec
52,568,560,651 cycles # 2.632 GHz
89,424,109,426 instructions # 1.70 insn per cycle
17,496,929,762 branches # 875.904 M/sec
97,910,697 branch-misses # 0.56% of all branches
10.025825765 seconds time elapsed在docker映像上使用perf工具时得到的输出:
Performance counter stats for 'docker run -ti --rm polinux/stress-ng --cpu 2 --timeout 10':
154.613610 task-clock (msec) # 0.014 CPUs utilized
858 context-switches # 0.006 M/sec
113 cpu-migrations # 0.731 K/sec
4,989 page-faults # 0.032 M/sec
252,242,504 cycles # 1.631 GHz
375,927,959 instructions # 1.49 insn per cycle
84,847,109 branches # 548.769 M/sec
1,127,634 branch-misses # 1.33% of all branches
10.704752134 seconds time elapsed有人能帮我如何获得压力指标运行时使用码头吗?
发布于 2020-05-03 12:56:14
继续从@osgx的评论,
正如前面提到的这里,默认情况下,perf stat命令不仅监视要监视的进程的所有线程,而且监视它的子进程和线程。
这种情况下的问题是,通过运行perf stat和监视docker run stress-ng命令,您没有监视实际的stress-ng进程。需要注意的是,作为容器的一部分运行的进程实际上不是由docker客户机启动的,而是由docker-containerd-shim进程(它是dockerd进程的外孙进程)启动的。
如果您运行docker命令来在容器中运行stress-ng并观察进程树,那么就很明显了。
docker run -ti --name=stress-ng --rm polinux/stress-ng --cpu 2 --timeout 100
ps -elf | grep docker
0 S ubuntu 26379 114001 0 80 0 - 119787 futex_ 12:33 pts/3 00:00:00 docker run -ti --name=stress-ng --rm polinux/stress-ng --cpu 2 --timeout 10000
4 S root 26431 118477 0 80 0 - 2227 - 12:33 ? 00:00:00 docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/72a8c2787390669ff4eeae6f343ab4f9f60434f39aae66b1a778e78b7e5e45d8 -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
0 S ubuntu 26610 26592 0 80 0 - 3236 pipe_w 12:34 pts/6 00:00:00 grep --color=auto docker
4 S root 118453 1 3 80 0 - 283916 - May02 ? 01:01:57 /usr/bin/dockerd -H fd://
4 S root 118477 118453 4 80 0 - 457853 - May02 ? 01:14:36 docker-containerd --config /var/run/docker/containerd/containerd.toml
----------------------------------------------------------------------
ps -elf | grep stress-ng
0 S ubuntu 26379 114001 0 80 0 - 119787 futex_ 12:33 pts/3 00:00:00 docker run -ti --name=stress-ng --rm polinux/stress-ng --cpu 2 --timeout 10000
4 S root 26455 26431 0 80 0 - 16621 - 12:33 pts/0 00:00:00 /usr/bin/stress-ng --cpu 2 --timeout 10000
1 R root 26517 26455 99 80 0 - 16781 - 12:33 pts/0 00:01:08 /usr/bin/stress-ng --cpu 2 --timeout 10000
1 R root 26518 26455 99 80 0 - 16781 - 12:33 pts/0 00:01:08 /usr/bin/stress-ng --cpu 2 --timeout 10000
0 S ubuntu 26645 26592 0 80 0 - 3236 pipe_w 12:35 pts/6 00:00:00 grep --color=auto stress-ng第一个stress-ng进程的PPID为26431,这不是docker run命令,而是实际的docker-containerd-shim进程。监视docker run命令永远不会反映正确的值,因为docker客户端完全脱离了启动stress-ng命令的过程。
perf stat命令附加到由docker运行时启动的压力ng进程的PID中。与上述情况一样,一旦启动docker run命令,您就可以立即开始执行此操作-
perf stat -p 26455,26517,26518
Performance counter stats for process id '26455,26517,26518':
148171.516145 task-clock (msec) # 1.939 CPUs utilized
49 context-switches # 0.000 K/sec
0 cpu-migrations # 0.000 K/sec
67 page-faults # 0.000 K/sec 您可能会稍微增加一些--timeout,以便使命令运行得更长,因为您现在正在启动perf stat post --启动stress-ng。此外,你必须对最初测量时间损失的一小部分进行解释。
perf stat,类似于docker run perf stat ...,但为此您必须开始向容器提供privileges,因为默认情况下,perf_event_open系统调用是在docker中黑名单的。你可以读到这个答案这里。https://stackoverflow.com/questions/61456515
复制相似问题