进程在 ubuntu 18 机器上的 docker 容器中运行时需要时间。但是具有相同 docker 版本的相同进程在 ubuntu 16 机器上运行良好。
我有一个节点应用程序正在监听某个端口。接受路径“/”和“/docker”上的get请求,它们分别在主机和docker容器中运行一个命令“whoami”并返回结果。具有相同 docker 容器的相同节点应用程序在两台机器(ubuntu16 和 ubuntu18)上运行。
现在,首先我尝试向两台机器发送带有路径“/”的 20 个并发获取请求。并且两台机器都在平均执行命令
35-40 毫秒。
现在,第二个我尝试向两台机器发送 20 个带有路径“/docker”的并发获取请求。在这里,ubuntu16 机器花费了 Max 4.3 秒和 Avg 3 秒。但是 ubuntu18 机器最多需要 10 秒,平均需要 9 秒。
我多次尝试上述测试。并得出结论,当在 docker 中运行进程时,与 ubuntu16 相比,在 ubuntu18 机器中执行所需的时间几乎翻了一番。
我检查了以下内容:
top
进行监控和 htop
同时达到 20 个请求。但一切似乎都一样。 perf
进行监控命令。但无法发现他们有什么异常。但是我不是很习惯 perf 命令,所以无法理解清楚。 strace
手动运行相同的 docker 命令.并发现随机结果,即有时在 clock_gettime
中花费的时间或 futex (FUTEX_WAIT)
或有时在 +++ exited with 0 +++
ubuntu18 上的消息。但在 ubuntu16 上花费的时间更少。 以下是我正在使用和运行的不同配置和代码片段。
Machine1: Giving better performance. node v10.16.0 npm 6.9.0 docker 18.09.8 ubuntu 16.04.3 LTS, xenial Machine2: Giving poor performance. node v10.16.0 npm 6.9.0 docker 18.09.8 ubuntu 18.04.2 LTS, bionic
Node application code snippet:
// for path "/docker"
var excuteInDocker = function() {
var cmd = "docker";
var args = ["exec", "ubuntu", "whoami"];
return executeCmd(cmd, args);
}
// for path "/"
var execute = function(){
var cmd = 'whoami';
var args = [];
return executeCmd(cmd, args);
}
docker info
的输出ubuntu 16 和 18 通用:Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 2
Server Version: 18.09.8
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.296GiB
Name: myhostname
ID: LLLO:OMTS:PNNM:T3MP:AD2F:UMDG:IIZK:OGBO:3ZLL:YDBX:ONAO:AY5G
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 27
Goroutines: 42
System Time: 2019-07-25T15:25:54.991694211+05:30
EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
WARNING: No swap limit support
docker info
特定于 ubuntu 16 Kernel Version: 4.4.0-112-generic
Operating System: Ubuntu 16.04.3 LTS
Total Memory: 7.303GiB
ID: FOFI:RW7N:RZSP:HHKH:BKS3:LMWL:TC2J:W7V2:222Y:Q2AU:XMU3:KLU7
docker info
特定于 ubuntu 18 Kernel Version: 4.15.0-1040-aws
Operating System: Ubuntu 18.04.2 LTS
Total Memory: 7.296GiB
ID: LLLO:OMTS:PNNM:T3MP:AD2F:UMDG:IIZK:OGBO:3ZLL:YDBX:ONAO:AY5G
ubuntu16 机器数据:
1、执行时间数据
2019-07-25 14:06:42.851 INFO uid: 540ae880-aeb7-11e9-919d-dd32b3cf84d5 time: 475 result: {"success":true,"data":"root"}
2019-07-25 14:06:43.183 INFO uid: 54145e60-aeb7-11e9-919d-dd32b3cf84d5 time: 745 result: {"success":true,"data":"root"}
2019-07-25 14:06:45.711 INFO uid: 540c4810-aeb7-11e9-919d-dd32b3cf84d5 time: 3326 result: {"success":true,"data":"root"}
.
.
.
2019-07-25 14:06:46.835 INFO uid: 541d5f10-aeb7-11e9-919d-dd32b3cf84d5 time: 4338 result: {"success":true,"data":"root"}
strace -t docker exec ubuntu whoami
enter image description here perf top --sort comm,dso
的结果enter image description here
ubuntu18 机器数据:
1、执行时间数据
2019-07-25 14:07:32.559 INFO uid: 715a6af0-aeb7-11e9-a5a9-2fffd4e800d1 time: 1008 result: {"success":true,"data":"root"}
2019-07-25 14:07:32.941 INFO uid: 7178c860-aeb7-11e9-a5a9-2fffd4e800d1 time: 1191 result: {"success":true,"data":"root"}
2019-07-25 14:07:40.363 INFO uid: 71767e70-aeb7-11e9-a5a9-2fffd4e800d1 time: 8628 result: {"success":true,"data":"root"}
.
.
.
2019-07-25 14:07:41.970 INFO uid: 718af0d0-aeb7-11e9-a5a9-2fffd4e800d1 time: 10101 result: {"success":true,"data":"root"}
strace -t docker exec ubuntu whoami
enter image description here perf top --sort comm,dso
的结果enter image description here
所以,我需要帮助来调试 ubuntu18 机器上的 docker 出了什么问题。或者,如果 ubuntu18 上的 docker 有任何限制,或者某些机器或 docker 配置问题。
最佳答案
我在台式机上没有遇到过这样的问题,但是 mysql 容器以一种我在 ubuntu 笔记本电脑上无法理解的方式运行得很慢。 This solution解决了我的问题。
关于performance - 进程在 ubuntu 18.04 上的 docker 容器中运行缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57199473/