• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to configure Linux Resource Groups (cgroups) for MySQL

by admin

The following provides the procedure for configuring and using resource groups under Linux:

1. To use cgroups, you must install the “libcgroup” package on your system.

# yum install libcgroup

2. Create a config file for cgroups (/etc/cgconfig.conf) and add below configuration.

# 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. Create a cgroup rules definition file – /etc/cgrules.conf with below configuration:

# vi /etc/cgrules.conf

# Assign tasks run by the mysql user to mysqldb
mysql cpu,cpuset,memory mysqldb

4. Start the cgconfig service and configure it to start when the system is booted.

$ service cgconfig start
$ chkconfig cgconfig on

5. At this point the resource group for mysql is ready and in place. Restart mysqld and it will be allowed resources according to the config and rules provided above.

6. You can find and change the resource group limits during runtime as well:

a. To find resource limits:

$ cgget -r memory.stat mysqldb

b. To set resource limits:

$ cgset -r blkio.throttle.read_bps_device="8:1 0" iocap1

c. To save the current modified config for future use:

$ cgsnapshot -s > current_cgconfig.conf

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. etckeeper: command not found
  2. hdparm Command Examples in Linux
  3. parted Command Examples in Linux
  4. What happens in the Background when you execute the “useradd” command under Linux
  5. How to display a Custom Kernel Name in GRUB Menu CentOS/RHEL 6
  6. sa Command Examples in Linux
  7. lsof : Most commonly used examples
  8. What’s the difference between locate and find command in Linux
  9. CentOS / RHEL 6,7 : How to disable or delete virbr0 interface
  10. mkfs.ntfs: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright