docker客户端拉包逻辑及优化思路

docker客户端拉包逻辑及优化思路

docker pull xxxxxx

Concurrent downloads

By default the Docker daemon will pull three layers of an image at a time. If you are on a low bandwidth connection this may cause timeout issues and you may want to >>lower this via the --max-concurrent-downloads daemon option. See the daemon documentation for more details.

docker pull每次一个镜像默认并发拉3层,如果你的带宽比较小,导致了超时问题,你可以通过调整–max-concurrent-downloads来减少并发数。

local disk store

Docker uses a content-addressable image store, and the image ID is a SHA256 digest covering the image’s configuration and layers. In the example above, debian:jessie and debian:latest have the same image ID because they are actually the same image tagged with different names. Because they are the same image, their layers are stored only once and do not consume extra disk space.

docker镜像是由元数据加层(layer)构成,每一层都有一个sha256,机器上同sha256只会保存一份,也就是说的当两个镜像有一层是相同的,相同的这一层只会请求一次网络下载。

docker pull的运行原理

执行docker pull从远程仓库拉镜像的docker client的步骤是:
1.从远程仓库获取到manifests各个层的disgest(sha256)
2.在本地机器搜索是否sha256已经存在
3.如sha256在本地机器不存在,则从远程仓库拉取sha256
4.同一个镜像并发拉的层数受–max-concurrent-downloads这个参数控制(默认一个镜像并发拉3层)
5.下载完成后,进行extracting解压合并所有层生成镜像

从上面我们可以看到,拉取镜像的速度受一下因素影响:
1.本地机器已有的镜像数(镜像数、层数),如果太多,搜索的时候就会耗费很多时间
2.本地机器、远程仓库的带宽
3.本地机器的磁盘IO吞吐量
3.设置的并发数,决定带宽是否充分利用
4.当前机器同时进行pull的镜像数量
5.机器负载,下载成功后解压合并需要耗费CPU负载

优化思路

从上面的原理我们可以看到,镜像下载快慢,受综合因素影响:机器当前存在的镜像数、带宽、CPU、磁盘IO、机器同时docker pull的数量。

docker pull的总数量我们不控制,但是我们可以调整同时拉的数量、带宽极限1000M、磁盘IO也有极限,CPU同样如此。

在我们调整了硬件:
1.带宽1000M
2.CPU、磁盘使用能调动的最大

我们能控制的就是:
1.定时清理本地的镜像(或用完就删除)
2.部署机同时放进的任务数
3.调大–max-concurrent-downloads这个参数,加快单个镜像的拉取速度。
4.增加处理dokcer pull的机器

总结:在资源调动允许范围内磁盘IO、带宽、CPU使用最好的;减少并发拉取镜像的数量,调大单个镜像并发拉取的层数,加快单个任务的吞吐,不是系统雪崩,从而加快所有任务的速度。

调整–max-concurrent-downloads参数

cd /ect/docker
cat daemon.json
{
    "max-concurrent-downloads": 20,
    "max-concurrent-uploads": 20
}

一些分析、跟踪问题使用的命令

//修改daemon.json重启docker服务
**sudo systemctl restart docker**

//查看docker Pull的网络连接  端口:请求远程仓库的端口
netstat -apn | grep 端口

//example
netstat -apn | grep 8443

//查看端口的网络连接数
netstat -apn | grep 端口 | wc -l
//example
netstat -apn | grep 8443 | wc -l

//查看docker pull的进程
ps -ef|grep 'docker pull'


//删除本地带有 8443的镜像
docker rmi --force `docker images | grep 8443 | awk '{print $3}'`

//查看docker client的日志
tail -f /var/log/messages |grep dockerd

测试技术指标

机器:8C4核, 1000M带宽

max-concurrent-downloads=50

“max-concurrent-downloads”: 50,
“max-concurrent-uploads”: 50,

调到50, 带宽每秒可以到30M左右,峰值50M,连接数峰值78,机器负载13,磁盘Iod峰值50M,平均30M左右 可同时拉11个镜像,但是extracting会很慢

max-concurrent-downloads=30

“max-concurrent-downloads”: 30,
“max-concurrent-uploads”: 30,

调到30, 带宽每秒可以到30M左右,峰值50M,连接数峰值46,连接数稳定值30,机器负载5分钟高峰12,平均10分钟负载9,磁盘Iod峰值60M,平均30M左右 可同时拉11个镜像,但是extracting会很慢
会存在docker client timeout

max-concurrent-downloads=20

“max-concurrent-downloads”: 20,
“max-concurrent-uploads”: 20

并行7个任务 + 1个手拉

调到20, 带宽每秒可以到20M左右,峰值26M;连接数峰值30,连接数稳定值20;机器负载5分钟高峰15,平均10分钟负载8,磁盘Iod峰值50M,平均30M左右 可同时拉8个镜像,但是extracting会很慢

extracting:占用大量负载,因为是解压合并文件

建议并行6~7个任务,docker pull 是一个占用网络IO、磁盘IO、cpu负载的综合型操作

其他一些参数

--max-concurrent-downloads int          Set the max concurrent downloads for each pull (default 3)
--max-concurrent-uploads int            Set the max concurrent uploads for each push (default 5)
--max-download-attempts int             Set the max download attempts for each pull (default 5)

相关参考

https://docs.docker.com/engine/reference/commandline/dockerd/
https://www.educba.com/docker-pull/

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker 客户端是通过命令行或其他工具使用 Docker SDK 与 Docker 的守护进程通信的工具。 客户端发送命令给守护进程,然后守护进程负责实现 Docker 的各种功能。 Docker 客户端和守护进程之间通过远程 API 进行通信。 Docker 的架构图中显示了客户端与守护进程之间的通信关系,客户端通过 API 来管理和创建 Docker 容器,而守护进程负责执行这些命令。 Docker 的架构图: Docker使用客户端-服务器C/S架构模式,使用远程API来管理和创建Docker容器。Docker 客户端(Client): Docker客户端通过命令行或者其他工具使用 Docker SDK与Docker的守护进程通信。 在Docker Client中来运行Docker的各种命令,而这些命令会传送给在Docker的宿主机上运行的Docker的守护进程。而Docker的守护进程是负责来实现Docker的各种功能。 目录 一、Docker -Docker的CS模式1、下图为Docker官方提供的Docker的CS运行模式的介绍:2、Docker客户端与守护进程的描述3、Remote API4、Docker客户端与守护进程的通信方式5、连接演示1)、检验docker是否启动2)、查看docker版本3)、通过unix:///var/run/docker.sock访问<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Docker 详解及安装](https://blog.csdn.net/zhengzhaoyang122/article/details/127322666)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [五、Docker客户端和守护进程](https://blog.csdn.net/q908544703/article/details/126114056)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值