有没有一种方法可以加快docker exec? [英] Is there a way to speed up docker exec?

查看:99
本文介绍了有没有一种方法可以加快docker exec?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有消除docker exec开销的方法?例如,当我在已经运行的容器上调用 docker exec ls 时,返回结果需要0.15s.

Is there a way to eliminate the overhead of docker exec? For example, when I call docker exec ls on an already-running container, it takes 0.15s to return the result.

root@min:/# time docker exec 6f ls
bin
boot
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

real    0m0.159s
user    0m0.028s
sys 0m0.028s

但是,如果我启动连接的容器,并从容器的命令行开始 ls ,则只需花费几毫秒.

However if I start the container attached, and ls from the container's command line, it only takes a couple ms.

root@min:/# docker start -ai 6f
[root@6f384443d3a6 /]# time ls
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

real    0m0.004s
user    0m0.003s
sys 0m0.000s

容器的创建过程如下:

$ docker create -t -i fedora bash
6f8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752
$ docker start 6f

docker exec 中的开销是多少,有没有办法减少它?(我正在尝试提供一个服务,以承载正在运行的容器并在其上调用可执行文件并返回结果.但是,如果每次调用要花费150ms,那么这是不好的.)

What is the overhead in docker exec, and is there a way to reduce it? (I'm trying to make a service that hosts running containers and calls executables on them and returns the results. But if it's going to take 150ms per call, then that's no good).

推荐答案

Docker被实现为基于HTTP的服务,通常通过Unix套接字调用.例如,您可以看到创建exec实例" 请求.运行 docker exec 命令至少需要两次往返,再加上启动主机端 docker 进程的开销.在本地Linux上,HTTP调用将通过Unix套接字进行;在其他平台上,根据您的设置,可能需要跨越VM边界,甚至需要通过TCP.

Docker is implemented as an HTTP-based service, which is usually called over a Unix socket. For example, you can see the "create an exec instance" request in the Docker API documentation. It takes at least two round-trips to run a docker exec command, plus the overhead of starting the host-side docker process. On native Linux the HTTP calls will be over a Unix socket; on other platforms, depending on your setup, it may need to cross a VM boundary or even go over TCP.

150 ms直觉对我来说有点慢,但并非超出合理范围.由于所有这些机制都在 docker 客户端工具和服务器守护程序内部,因此您无法做很多事情来加快它的速度.

150 ms for a single docker exec call intuitively feels a little slow to me, but not out of the realm of the reasonable. There's not much you can do to speed it up, since all of these mechanics are inside the docker client tool and server daemon.

典型的Docker设置将使容器运行长时间运行的服务器进程(不是裸露的 fedora 容器,而不是 bash shell作为主要容器进程).您应该能够向容器发出网络请求,这可能比 docker exec 更快(并且不需要管理员特权).

A typical Docker setup will have containers running long-running server processes (not a bare fedora container, and not a bash shell as the main container process). You should be able to make a network request to the container, and this will likely be faster than docker exec (and not require administrator privileges).

这篇关于有没有一种方法可以加快docker exec?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆