views:

2343

answers:

3

Trying to determine the Processor Queue Length (the number of processes that ready to run but currently aren't) on a linux machine. There is a WMI call in Windows for this metric, but not knowing much about linux I'm trying to mine /proc and 'top' for the information. Is there a way to determine the queue length for the cpu?

Edit to add: Microsoft's words concerning their metric: "The collection of one or more threads that is ready but not able to run on the processor due to another active thread that is currently running is called the processor queue."

+1  A: 

uptime will give you the recent load average, which is approximately the average number of active processes. uptime reports the load average over the last 1, 5, and 15 minutes. It's a per-system measurement, not per-CPU.

Not sure what the processor queue length in Windows is, hopefully it's close enough to this?

Alastair
+1  A: 

vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 2  0 256368  53764  75980 220564    2   28    60    54  774 1343 15  4 78  2

The first column (r) is the run queue - 2 on my machine right now

Edit: Surprised there isn't a way to just get the number

Quick 'n' dirty way to get the number (might vary a little on different machines):

  vmstat|tail -1|cut -d" " -f2
Brabster
The metric on windows deals with ready threads and not ready threads that are running. The man vmstat indicates the r value being both ready threads and running threads.
+2  A: 

sar -q will report queue length, task list length and three load averages.

Example:

matli@tornado:~$ sar -q 1 0
Linux 2.6.27-9-generic (tornado)    01/13/2009  _i686_

11:38:32 PM   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15
11:38:33 PM         0       305      1.26      0.95      0.54
11:38:34 PM         4       305      1.26      0.95      0.54
11:38:35 PM         1       306      1.26      0.95      0.54
11:38:36 PM         1       306      1.26      0.95      0.54
^C
matli
Subtract the number of CPUs from the runq?
pjc50
Aye what pjc50 said - runnable state threads are in the run queue, the amount of runnable threads depends on the amount of logical CPUs (sockets * cores per socket * threads per core) in your box.
nailer