Resource Management in Centos/RHEL7 Using Cgroups




1)  What is Resource Management ?
     Resource management is the efficient and effective deployment and allocation of system resources when and where they are        needed. 

2)  What are Control Groups (Cgroups) ?
     Cgroups are Linux kernel feature that allows you to allocate resources — such as CPU time, system memory, network                    bandwidth, or combinations of these resources — among hierarchically ordered groups of processes running on a system. 

3) How to limit resources in Centos 7 using Cgroups ?

    Systemd organizes processes in control groups. For example, all the processes started by an apache webserver will be in the        same control group. Systemd Unit Tree is  made up of a parts.

    To get full hierarchy of Cgroups Run bellow command.

     #systemd-cgls


                                        Inline image 1

 In the above output of the command user.slice hierarchy. 
 It contains details of the user session. user-0.slice is the root user session hierarchy. 
 Similarly, for uid  1001 user session hierarchy will display as user-1001.slice.

 

I) To limit CPU resource for any user select user session and use bellow command.

  #systemctl set-priority user-0.slice CPUQuota=10%

When we hit above command Root user will only able to access 10% of the CPU Quota from available CPU Quota. This way we can restrict user from using available CPU resources on the server.




II) Restricting  Limit on CPUshare base on service.

  # systemctl set-property httpd CPUShares=500
  
  # systemctl daemon-reload
  
    This will restrict CPU shares of httpd service to 500.By default each process owns 1024 CPU shares.
    we can give value smaller or larger as per our requirement on  server.
 
    To view CPU shares on the particular service 

   #systemctl show -p CPUShares httpd

    If you haven't given any CPUShares it will give some garbage value in the output.
 
    This way we can restrict resources on the server and prevent any user or process from utilizing extra resources on the server     which leads in performance downgrade.

   
    There are serveral other features available in resource management refer bellow official link  of RHEL:
  




Comments