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 ($Sesse::pr0n::Config::overload_mode) {
29 # By default we are not in overload mode
30 if (!defined($in_overload)) {
34 my $enable_threshold = $Sesse::pr0n::Config::overload_enable_threshold // 10.0;
35 my $disable_threshold = $Sesse::pr0n::Config::overload_disable_threshold // 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 Sesse::pr0n::Common::log_info($r, "Current load average is $loadavg (threshold: $disable_threshold), leaving overload mode");
54 Sesse::pr0n::Common::log_warn($r, "Current load average is $loadavg (threshold: $disable_threshold), staying in overload mode");
57 if ($loadavg > $enable_threshold) {
58 Sesse::pr0n::Common::log_warn($r, "Current load average is $loadavg (threshold: $enable_threshold), entering overload mode");
61 Sesse::pr0n::Common::log_info($r, "Current load average is $loadavg (threshold: $enable_threshold)");