Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the load balancing managed by the Linux process

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the load balancing of Linux process management". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

After the previous study, we know that a task has the following states, but when using top, it is often shown in the form of an acronym, which we summarize here.

R (TASK_RUNNING), operable state. Both Ready and Running in Linux correspond to TASK_RUNNING flag bits. Ready indicates that the process is in queue and has not been scheduled, while running indicates that the process is running on CPU.

D (TASK_UNINTERRUPTIBLE), uninterruptible sleep state. Are processes that are in the critical process of kernel state, and these processes are uninterruptible, for example, the most common is to wait for the hardware device to respond. Processes in the TASK_UNINTERRUPTIBLE state cannot be awakened by signals, only by wakeup. Since TASK_UNINTERRUPTIBLE cannot be awakened by the signal, it naturally does not respond to kill commands, even if it is necessary to kill kill-9.

S (TASK_INTERRUPTIBLE), interruptible sleep state.

T (TASK_STOPPED or TASK_TRACED), paused status or tracking status.

Z (TASK_DEAD-EXIT_ZOMBIE), exit state, the process becomes a zombie process.

What is the average load?

Get to know:

Cat / proc/loadavg 0.18 0.94 0.72 1/486 3569

Looking at the average load of the current system, the first three are the average number of processes in 1 minute, 5 minutes, and 15 minutes, respectively. The fourth numerator is the number of running processes, and the denominator is the total number of processes; the last recently running process is the ID number.

You can also:

Uptime 22:32:31 up 9 min, 1 user, load average: 0.18, 0.94, 0.72

22:32:31 up 9 min, 1 user, load average: 0.18, 0.94, 0.72

Load average: 0.18,0.94,0.72 / / is the average number of processes in 1 minute, 5 minutes and 15 minutes, respectively.

My PC here is 2 cpu, so the load here is relatively low. (if the average load is higher than 2.0, it means overload, and it is normal for the average load to be less than 2.0.)

The average load refers to the average number of processes in the runnable state and uninterruptible state of the system per unit time (that is, the average number of processes in the two states of R & D above, and it is easy to ignore the processes in D state), that is, the average number of active processes, which is not directly related to the utilization rate of CPU. The actual calculation is more complex, interested students can check the source code https://github.com/torvalds/linux/blob/master/kernel/sched/loadavg.c.

Average load is not equal to CPU utilization

Through the above introduction, we know:

The average load includes not only processes that are using CPU, but also processes waiting for CPU and waiting for CPU O.

CPU utilization, which is the statistics of CPU busy per unit time, does not necessarily correspond to the average load.

For example:

For CPU-intensive processes, the use of a large amount of CPU will lead to an increase in average load, which is consistent; for I-CPU-intensive processes, waiting for I-CPU will also lead to an increase in average load, but the CPU utilization is not necessarily very high; a large number of process scheduling waiting for CPU will also lead to an increase in average load, and the CPU utilization will also be high.

So this is why it is sometimes found that cpu usage is not very high through top, but the load is heavy when cat / proc/loadavg.

Common command

Top

You can view the status of the system CPU and display it as a percentage.

Tasks: 251 total, 1 running, 243 sleeping, 0 stopped, 1 zombie Mem: 2007724k total, 862108k used, 1145616k free, 18560k buffers Swap: 1505788k total, 0k used, 1505788k free 415260k cached 400%cpu 16%user 0%nice 6%sys 377%idle 0%iow 0%irq 0%sirq 0%host PID USER PR NI VIRT RES SHR S [% CPU]% MEM TIME+ ARGS 5628 root 20 0 5.9M 3.1M 2.7M R 19.3 0.10 MEM TIME+ ARGS 00.07 top 5614 root 0-20 000 S 0.0 0:00 .00 [kworker/u9:0] 5609 root 20 00 00 S 0.0 0.00: 00.00 [kworker/3:2] 5607 root 20 00 00 S 0.0 0.00: 00.00 [kworker/u8:2] 5590 root 0-20 000 S 0.0 0.00: 00.00 [kworker/u9:4] 5585 root 20 00 S 0.0 0.00: 00.00 [kworker/u8:3] 5577 root 0-20 000 S 0.0 0.00: 00.00 [kworker/u9:2] 5571 root 20 00 S 0.0 0.00 [kworker/3:0] 5537 root 20 00 00 S 0.0 0.0 0:00.05 [kworker/u8:1] 5448 root 20 00 00 S 0.0 0.0 0:00.67 [kworker/3:1]

Us (user cpu time): the ratio of cpu time used in user mode. When this value is high, it means that the user process consumes more CPU time. For example, if the value exceeds 50% for a long time, you need to optimize the program algorithm or code.

Sy (system cpu time): the cpu time ratio used in the system state.

Ni (user nice cpu time): user-mode cpu time ratio allocated by processes weighted by nice

Id (idle cpu time): the ratio of idle cpu time. If this value persists at 0 and the sy is twice as large as us, the system is usually facing a shortage of CPU resources.

Wa (wait): time to wait for CPU to be used.

Hi (hardware irq): hard interrupt elapsed time

Si (software irq): soft interrupt elapsed time

St (steal time): virtual machine steals time

Vmstat

Vmstat is used to detect the status of the system, including CPU and memory, which is very convenient for system debugging.

Procs-memory- swap---io-----system-- cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 1146440 18564 415260 00 2 10 95 00 100 00 1146476 18564 415260 00 00 0384 00 100 00 1146104 18564 415260 00 00 0375 00 100 00 1146724 18564 415260 00 00 0387 00 00 00 1146848 18564 415260 00 00 0369.00 100 0 "what is the load balance managed by the Linux process"? Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report