Use taskset to effectively control CPU resources

Source: Internet
Author: User

Reprint: http://hiadmin.com /? P = 1452
It is often felt that the system resources are insufficient, and no more than three important services can be run on a single machine. However, every day we need to perform backup compression and other operations on the machine, and the network will be transmitted for a long time, this affects the insufficient system resources;

At this time, we can limit some less important tasks, such as copy, backup, and synchronization, to a single CPU or a core of a multi-core CPU, although this is not necessarily the most effective method, it can maximize the use of valid resources to reduce the CPU resources occupied by less important processes;

View the CPU information in the system:

#cat /proc/cpuinfo

Taskset can help us complete this task, and the operation is very simple;

The tool is installed by default. The RPM package name is util-Linux.

#taskset --help
taskset (util-linux 2.13-pre7)
usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]]
set or get the affinity of a process

-P,-pid operate on existing given PID
-C,-CPU-list display and specify CPUs in List format
-H,-help display this help
-V,-version output version information

Example:
1. enable a new process with only 0 CPU cores (job. Sh is your work script)

#taskset -c 0 sh job.sh

2. Find the existing process ID and adjust the CPU core usage of the process (23328 process ID used in the example)

# Taskset-PC 0 23328
PID 23328's current affinity list: 0-3 #0-3 indicates that all 4 cores are used for processing.
PID 23328's New Affinity list: 0 # adjusted to apply only 0-tag Single-core processing

3. Check the load in top

Finally, you can add this command in your work script to reasonably use the existing CPU resources;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.