0

I'm trying to build a service that blocks other requests if the server overloaded. But the load average of 1 minute is not good enough for this, the logic is something like this:

if load_average > core_count 
   return render 503
end
return the_requested_page

but when I try to stress the computer using stress -c 12 -i 100 --timeout 10 command, the load_average showing something like this:

1, 3, 8, 15, 21, 20, 18, 15, 12, 11 
              ^ stress program ends here

how to get load average with smaller resolution (1-2 seconds, instead of 1 minute average)?

Extra information, I read the load average using this code

Kokizzu
  • 9,257
  • 12
  • 55
  • 82

1 Answers1

5

The load average is computed in the kernel — see Why isn't a straightforward 1/5/15 minute moving average used in Linux load calculation? for details. So, you can't just get a reading with a finer resolution. Instead, you could write userspace code which duplicates the functionality, but that seems a little tricky (not least because to do it right, you'd have to sample a lot, which seems like silly overhead on an overloaded server).

Instead, I'd suggest choosing something other than load average to base your decision on — possibly something you know from your service itself. For example, what about backing off if response times go above a median threshold?

mattdm
  • 39,535
  • 18
  • 99
  • 133