1 # Note: This package is shared between server processes as much as we can,
2 # for obvious reasons (you don't want just half the server to go in
3 # overload mode if you can help it)
5 package Sesse::pr0n::Overload;
11 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
19 our ($last_update, $loadavg, $in_overload);
24 # Manually set overload mode
25 if (lc($r->dir_config('OverloadMode')) eq 'on') {
29 # By default we are not in overload mode
30 if (!defined($in_overload)) {
34 my $enable_threshold = $r->dir_config('OverloadEnableThreshold') || 10.0;
35 my $disable_threshold = $r->dir_config('OverloadDisableThreshold') || 5.0;
37 # Check if our load average estimate is more than a minute old
38 if (!defined($last_update) || (time - $last_update) > 60) {
39 open LOADAVG, "</proc/loadavg"
40 or die "/proc/loadavg: $!";
44 $line =~ /^(\d+\.\d+) / or die "Couldn't parse /proc/loadavg";
50 if ($loadavg < $disable_threshold) {
51 $r->log->info("Current load average is $loadavg (threshold: $disable_threshold), leaving overload mode");
54 $r->log->warn("Current load average is $loadavg (threshold: $disable_threshold), staying in overload mode");
57 if ($loadavg > $enable_threshold) {
58 $r->log->warn("Current load average is $loadavg (threshold: $enable_threshold), entering overload mode");
61 $r->log->info("Current load average is $loadavg (threshold: $enable_threshold)");