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
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


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?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.