Understading sys_getloadavg();

2020-07-27 02:27发布

I am using this function http://it2.php.net/sys_getloadavg to get a hint about my server load.

The docu says the numbers returned are the number of processes in the system run queue

For the last 15 minutes I am getting values between: 0.40 and 0.60 Does this mean I had almost no processes in the system run queue for last 15 min? How should I convert this value to get a percentage ?

I would like to get: load in the last 15 min: 30%

标签: php
2条回答
Root(大扎)
2楼-- · 2020-07-27 02:34

The load numbers on a Linux system are often confusing for people coming from Windows and other operating systems. The number often looks like a percentage, but it isn't.

When you evaluate the system load you have to know the number of CPUs your system has. Otherwise those numbers mean nothing.

To describe this in general terms as it was taught to me, I would first start with the concept that a CPU core can do 1 thing at a time. Knowing this, the number of items in the system run queue can start to make sense. The system queue is the jobs that are eiterh being worked on, or about to be started.

In a 1 CPU system any number below 1 means that the system is keeping up with its tasks. It has 1 CPU and there is on average 1 task being worked on (or about to be started). In a 2 CPU/dual core system, if there is 1 item in the system queue, one or the other CPU is working on it or just about to grab it and you won't have any delay. If you are on a 16 core server and your load average is creeping up to 14, you are still not in bad shape because that's less than your CPU core count and all of the jobs are being worked on or are about to be started.

Now if your numbers are double your CPU count, then you are definitely overloaded and the system is falling behind. All of the CPUs are busy and they all have another job to work on after they are done with their current job.

After that, you need to watch out for a snowballing effect as the system starts to spend more and more time juggling its resources and less time processing the demand of the users.

Hope that helps!

(Oh and as far as the "73% 50% 698% based on 1.73 0.50 7.98" that makes no sense to me either. It looks like they subtracted 1 and multiplied by 100 except for with the 0.5. It makes no sense at all and I think it was removed from the page you linked to anyway.)

查看更多
够拽才男人
3楼-- · 2020-07-27 02:41

Load average is not a percentage of anything, therefore converting it to a percentage is mostly pointless, but if you insist then that article talks about it.

查看更多
登录 后发表回答