以下に、Linux でリソース グループを構成して使用する手順を示します。
1. cgroup を使用するには、システムに「libcgroup」パッケージをインストールする必要があります。
# yum install libcgroup
2. cgroups の設定ファイルを作成します:
# vi /etc/cgconfig.conf mount { cpu = /cgroup/cpumem; cpuset = /cgroup/cpumem; memory = /cgroup/cpumem; } # High priority group group mysqldb { cpu { # Allocate the relative share of CPU resources equal to 75% cpu.shares="750"; } cpuset { # No alternate memory nodes if the system is not NUMA cpuset.mems="0"; # Allocate CPU cores 2 through 5 to tasks in the cgroup cpuset.cpus="2-5"; } memory { # Allocate at most 8 GB of memory to tasks memory.limit_in_bytes="8G"; # Allocate at most 16 GB of memory+swap to tasks memory.memsw.limit_in_bytes="16G"; # Apply a soft limit of 4 GB to tasks memory.soft_limit_in_bytes="4G"; } }
3. cgroup ルール定義ファイルを作成します:
# vi /etc/cgrules.conf # Assign tasks run by the mysql user to mysqldb mysql cpu,cpuset,memory mysqldb
4. cgconfig サービスを開始し、システムの起動時に開始するように構成します。
$ service cgconfig start $ chkconfig cgconfig on
5. この時点で、mysql のリソース グループの準備が整っています。 mysqld を再起動すると、上記の構成とルールに従ってリソースが許可されます。
6. 実行時にリソース グループの制限を見つけて変更することもできます。
– リソースの制限を見つけるには:
$ cgget -r memory.stat mysqldb
– リソース制限を設定するには:
$ cgset -r blkio.throttle.read_bps_device="8:1 0" iocap1
– 将来の使用のために現在変更されている構成を保存するには:
$ cgsnapshot -s > current_cgconfig.conf