0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

 tcconfigを使ってネットワーク帯域制限や遅延をソフト的に再現する方法。デバッグなどに役立つ。tcやtrickleを使う方法もあるが、tcconfigが簡単で扱いやすいためおすすめ。

動作確認環境

  • Ubuntu 22.04

インストール方法

 pipをインストールしていない場合は先にインストールしておく。 下記コマンドでtcconfigをインストールする。

pip install tcconfig

使い方

 各種コマンドの後に、NICデバイス名とオプションを指定する。

設定 (tcset)

 tcsetコマンドを使う。

tcset {nic_device}

帯域制限 (--rate)

例:eth0 帯域1Mbps (アップロードのみ)

tcset eth0 --rate 1Mbps

例:eth0 帯域1Mbps (アップロード+ダウンロード)

tcset eth0 --rate 1Mbps --direction incoming

Dockerコンテナ内で、ダウンロード制限するにはコンテナ起動時に以下の設定が必要。

sudo docker run --rm -it --cap-add NET_ADMIN --net=host -v /lib/modules:/lib/modules:ro tc 

詳細は、こちらの記事を参照。

デフォルト状態でコンテナを起動した場合、以下のエラーでダウンロードの帯域制限ができない。

[ERROR] modprobe: FATAL: Module ifb not found in directory /lib/modules/x.x.x-xx-generic

遅延 (--delay)

例:eth0 遅延500ms ジッター100ms(正規分布)

tcset eth0 --delay 500ms --delay-distro 100 --delay-distribution normal
  • --delay-distro
    • 遅延の揺らぎ(ジッター)
  • --delay-distribution
    • 遅延の分布
      • normal: 正規分布

パケットロス (--loss)

例:eth0 パケットロス10%

tcset eth0 --loss 10

パケット順番入れ替え (--reordering)

例:eth0 パケット順序入れ替え10%

tcset eth0 --reordering 10

設定例

  • NIC: eth0
  • 帯域:500Kbps (アップロードのみ)
  • 遅延:800ms
  • 正規分布:50ms
  • パケットロス:10%
  • パケット順序入れ替え:10%
tcset eth0 --rate 500Kbps --delay 800ms --delay-distro 50 --delay-distribution normal --loss 10 --reordering 10

設定内容の確認 (tcshow)

tcshow {nic_device}

例:eth0

tcshow eth0

結果は、json形式で出力される。

{
    "eth0": {
        "outgoing": {
            "protocol=ip": {
                "filter_id": "800::800",
                "delay": "800.0ms",
                "loss": "10%",
                "reorder": "10%",
                "rate": "500Kbps"
            }
        },
        "incoming": {}
    }
}

解除 (tcdel)

tcdel {nic_device}

全て解除 (--all)

例:eth0 全て解除

tcdel eth0 --all

まとめ

 tcconfigコマンドで、ネットワーク評価のために、帯域制御、遅延などを再現することができた。ネットワーク負荷の評価を疑似的に再現できるのでデバッグ時などに使える。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?