1. 程式人生 > >Docker 資源限制之 IO

Docker 資源限制之 IO

一、壓測工具

通過 Linux dd 命令測試

二、IO 測試

  • 關於 IO 的限制

    • --blkio-weight=0
      • Block IO weight (relative weight) accepts a weight value between 10 and 1000.
    • --blkio-weight-device=""
      • Block IO weight (relative device weight, format: DEVICE_NAME:WEIGHT)
      • 針對特定裝置的權重比
    • --device-read-bps=""
      • Limit read rate from a device (format: <device-path>:<number>[<unit>]
        ). Number is a positive integer. Unit can be one of kbmb, or gb.
      • 按每秒讀取塊裝置的資料量設定上限
    • --device-write-bps=""
      • Limit write rate from a device (format: <device-path>:<number>[<unit>]). Number is a positive integer. Unit can be one of kbmb, or gb.
      • 按每秒寫入塊裝置的資料量設定上限
    • --device-read-iops=""
      • Limit read rate (IO per second) from a device (format: <device-path>:<number>
        ). Number is a positive integer.
      • 按照每秒讀操作次數設定上限
    • --device-write-iops=""
      • Limit write rate (IO per second) from a device (format: <device-path>:<number>). Number is a positive integer.
      • 按照每秒寫操作次數設定上限
➜  ~ docker help run | grep -E 'bps|IO'
Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
  --blkio-weight                  Block IO (relative weight), between 10 and 1000
--blkio-weight-device=[] Block IO weight (relative device weight) --device-read-bps=[] Limit read rate (bytes per second) from a device --device-read-iops=[] Limit read rate (IO per second) from a device --device-write-bps=[] Limit write rate (bytes per second) to a device --device-write-iops=[] Limit write rate (IO per second) to a device ➜ ~

2.1 --blkio-weight--blkio-weight-device

  • --blkio-weight

預設,所有的容器對於 IO 操作「block IO bandwidth – blkio」都擁有相同優先順序。可以通過 --blkio-weight 修改容器 blkio 權重。--blkio-weight 權重值在 10 ~ 1000 之間。

Note: The blkio weight setting is only available for direct IO. Buffered IO is not currently supported.

使用 blkio weight 還需要注意 IO 的排程必須為 CFQ:

➜  ~ cat /sys/block/sda/queue/scheduler
noop [deadline] cfq
➜  ~ sudo sh -c "echo cfq > /sys/block/sda/queue/scheduler"
➜  ~ cat /sys/block/sda/queue/scheduler
noop deadline [cfq]

按照 Docker 官方文件的介紹測試:

➜  ~ docker run -it --rm --blkio-weight 100 ubuntu-stress:latest /bin/bash
[email protected]0b6770ee80e0:/#
➜  ~ docker run -it --rm --blkio-weight 1000 ubuntu-stress:latest /bin/bash
[email protected]6778b6b39686:/#

在執行的容器上同時執行如下命令,統計測試時間:

[email protected]0b6770ee80e0:/# time dd if=/dev/zero of=test.out bs=1M count=1024 oflag=direct
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 122.442 s, 8.8 MB/s

real    2m2.524s
user    0m0.008s
sys     0m0.492s
[email protected]6778b6b39686:/# time dd if=/dev/zero of=test.out bs=1M count=1024 oflag=direct
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 122.493 s, 8.8 MB/s

real    2m2.574s
user    0m0.020s
sys     0m0.480s
[email protected]6778b6b39686:/#

官方的測試說明是:

You’ll find that the proportion of time is the same as the proportion of blkio weights of the two containers.

  • --blkio-weight-device="DEVICE_NAME:WEIGHT"

--blkio-weight-device 可以指定某個裝置的權重大小,如果同時指定 --blkio-weight 則以 --blkio-weight 為全域性預設配置,針對指定裝置以 --blkio-weight-device 指定裝置值為主。

➜  ~ docker run -it --rm --blkio-weight-device "/dev/sda:100" ubuntu-stress:latest /bin/bash

2.2 --device-read-bps--device-write-bps

限制容器的寫入速度是 1mb「<device-path>:<limit>[unit],單位可以是 kb、mb、gb 正整數」:

➜  ~ docker run -it --rm --device-write-bps /dev/sda:1mb ubuntu-stress:latest /bin/bash
[email protected]:/# dd if=/dev/zero of=test.out bs=1M count=100 oflag=direct
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 100.064 s, 1.0 MB/s    # 可以得知寫入的平均速度是 1.0 MB/s

通過 iotop 獲取測試過程中的 bps 也是 1.0 MB 為上限:

io write bps

讀 bps 限制使用方式同寫 bps 限制:

➜  ~ docker run -it --rm --device-read-bps /dev/sda:1mb ubuntu-stress:latest /bin/bash

2.3 --device-read-iops--device-write-iops

限制容器 write iops 為 5「<device-path>:<limit>,必須為正整數」:

➜  ~ docker run -it --rm --device-write-iops /dev/sda:5 ubuntu-stress:latest /bin/bash
[email protected]:/# dd if=/dev/zero of=test.out bs=1M count=100 oflag=direct
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 42.6987 s, 2.5 MB/s

通過 iostat 監控 tps「此處即為 iops」 基本上持續在 10 左右「會有些偏差」:

➜  ~ iostat 1
... ...
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.13    0.00    0.13   23.46    0.00   75.28

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              10.00         0.00      2610.00          0       5220
... ...

讀 iops 限制使用方式同寫 iops 限制:

➜  ~ docker run -it --rm --device-read-iops /dev/sda:5 ubuntu-stress:latest /bin/bash

注: 在容器中通過 dd 測試讀速度並沒有看到很好的效果,經查沒有找到磁碟讀操作的好工具,所以文中沒有介紹讀測試。

三、原始碼解析

libcontainer 主要操作是對 cgroup 下相關檔案根據選項寫操作,具體更進一步的資源限制操作可以看 cgroup 的實現方式。

本文轉自:http://blog.opskumu.com/docker-io-limit.html

相關推薦

Docker 資源限制 IO

一、壓測工具 通過 Linux dd 命令測試 二、IO 測試 關於 IO 的限制 --blkio-weight=0 Block IO weight (relative weight) accepts a weight value between 10 and 10

Docker 資源限制記憶體

一、壓測工具 通過如下 Dockerfile 構建簡單的測試映象 ➜ cat Dockerfile FROM ubuntu:latest RUN apt-get update && \ apt-get install stress ➜

容器技術Docker資源限制

  上一篇我們聊到了docker容器的單機編排工具docker-compose的簡單使用,回顧請參考https://www.cnblogs.com/qiuhom-1874/p/13121678.html;今天我們主要來聊一聊docker容器的資源限制;通常情況下我們啟動一個docker容器,其記憶體和CPU都

Docker資源限制

一、基礎知識 blkio: 這個subsystem可以為塊裝置設定輸入/輸出限制,比如物理驅動裝置(包括磁碟、固態硬碟、USB等)。 cpu: 這個subsystem使用排程程式控制task對CPU的使用。 cpuacct: 這個subsystem自動生成cgroup中task對CP

Oracle 12c系列(四)|資源隔離IO、記憶體、CPU

伺服器主機提供IO、記憶體、CPU、儲存空間等資源為資料庫使用,Oracle使用Flex Diskgroup為資料庫提供儲存空間並做了相應的資源隔離。下面我們來看下Oracle是如何為不同的PDB做IO、記憶體、CPU限制的。 一、IO 資源隔離 12c

centos7下安裝docker(9.3容器對資源的使用限制-Block IO))

緩存 centos 文件 機制 font nbsp 有效 之間 找到 Block IO:指的是磁盤的讀寫,docker 可以通過設置權重,限制bps和iops的方式控制容器讀寫磁盤的帶寬 註:目前block IO限額只對direct IO(不使用文件緩存)有效。 1.Blo

docker容器技術系統資源限制及驗正(八)

前一篇文章:docker容器技術之私有registry(七) 測試: 限制記憶體: 限制cpu:      

Docker Private Registry && 資源限制

創建用戶 top 角色 第三方 log inux mas ... 圖片 Docker Private Registry Docker Registry 分類 Registry用於保存docker鏡像,包括鏡像的層次結構和元數據 用戶可自建R

詳解Docker架構、鏡像、容器及資源限制

開啟 獲取 roc 隔離 圖片 詳解 inf cobbler ghost Docker概述 Docker 是一個開源的應用容器引擎,讓開發者可以打包他們的應用以及依賴包到一個可移植的容器中,然後發布到任何流行的Linux機器上,也可以實現虛擬化,容器是完全使用沙箱機制,相互

DOCKER-1-9-資源限制與驗證

1.先從 docker映象倉庫中獲取一個壓力測試的映象,pull到本地。 2.檢視映象的幫助資訊。 3.傳入引數-m和--vm,把容器跑起來。 4.通過top檢視容器中各項程序的資源佔用情況。 5.通過docker stats檢視cpu的佔用情況。

docker 實踐(六)docker 資源隔離及限制

一、docker 底層實現 docker 通過namespace實現資源隔離;通過cgroup實現資源限額 二、namespace說明 2.1.概述 namespace使得容器像一臺獨立的計算機,namespace實現容器間資源隔離。linux六中namespace mnt namespac

Docker對CPU及記憶體的資源限制

Dockerfile檔案中CMD和EMTRYPOINT的區別 第一種:陣列格式 執行一個可執行的檔案並提供引數 [root@foundation40 docker]# mkdir test [root@foundation40 docker]# cd test/ [root@foun

docker的memory和cpu資源限制

這裡僅針對docker本身,不涉及任何編排工具compose或者k8s等。 按照慣例,官文擼起來。 重要的部分是一些選項,用來限制資源大小。 Memory Most of these options take a positive integer, followed by a suffix of b,

docker的系統資源限制及驗證

限制容器的資源 預設情況下,容器沒有資源限制,可以使用主機核心排程程式允許的儘可能多的給定資源。 Memory 記憶體風險 不允許容器消耗宿主機太多的記憶體是非常重要的。在 Linux 主機上,如果核心檢測到沒有足夠的記憶體來執行重要的系統功能,它會丟擲  OOME&n

Docker系列09—Docker的系統資源限制及驗證

stat 意義 class 內存交換 詳細信息 test 禁用 優先級 單獨 1、限制容器的資源   默認情況下,容器沒有資源限制,可以使用主機內核調度程序允許的盡可能多的給定資源。Docker提供了控制容器可以使用多少內存或CPU的方法,設置docker run命令的運

Docker容器資源限制

原文地址:https://docs.docker.com/engine/admin/resource_constraints/#configure-the-realtime-scheduler摘要     在Docker中預設情況下容器的資源只受到host端核心資源排程的限

如何使用docker 對容器資源限制

在使用 docker 執行容器時,一臺主機上可能會執行幾百個容器,這些容器雖然互相隔離,但是底層卻使用著相同的 CPU、記憶體和磁碟資源。如果不對容器使用的資源進行限制,那麼容器之間會互相影響,小的來說會導致容器資源使用不公平;大的來說,可能會導致主機和叢集資源

效能指標資源指標-網路IO-關注指標

有時系統性能的低下是由於網路頻寬不足、網路抖動或者伺服器端的相關引數配置導致的。本節介紹網路IO的相關指標。 一、 配置 1.1 最大頻寬 LPAR能夠佔用的最大頻寬是有網路管理員/運營商配置決定的。如果需要了解某個LPAR的最大頻寬或者某N個LPAR共同佔用的最

容器編排系統Pod生命週期、健康/就緒狀態探測以及資源限制

  前文我們瞭解了在k8s上的資源標籤、標籤選擇器以及資源註解相關話題,回顧請參考https://www.cnblogs.com/qiuhom-1874/p/14141080.html;今天我們來聊下k8s上的核心資源pod生命週期、健康/就緒狀態探測以及pod資源限制相關話題;   1、Pod生命週期   

【翻譯自mos文章】即使resource_limit = false, password的 資源限制也會生效

作用 pro use def alt doc 資源限制 lock bsp 即使resource_limit = false, password的 資源限制也會生效 參考原文: Resource limits for passwords work even with re