… | |
… | |
4 | |
4 | |
5 | our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; |
5 | our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; |
6 | |
6 | |
7 | $^O eq "linux" or die "only linux supported right now.\n"; |
7 | $^O eq "linux" or die "only linux supported right now.\n"; |
8 | |
8 | |
9 | Event->timer ( |
9 | our $TIMER = cf::periodic 10, sub { |
10 | reentrant => 0, |
|
|
11 | data => cf::WF_AUTOCANCEL, |
|
|
12 | interval => 10, |
|
|
13 | after => 10, |
|
|
14 | cb => sub { |
|
|
15 | open my $fh, "</proc/self/stat" |
10 | open my $fh, "</proc/self/stat" |
16 | or return; |
11 | or return; |
17 | |
12 | |
18 | sysread $fh, my $stat, 4096; # only a single line |
13 | sysread $fh, my $stat, 4096; # only a single line |
19 | my $vmsize = (split / /, $stat)[22]; |
14 | my $vmsize = (split / /, $stat)[22]; |
20 | |
15 | |
21 | cf::cleanup "memory usage growing high, server would run out of memory soon", 0 |
16 | cf::cleanup "memory usage growing high, server would run out of memory soon", 0 |
22 | if $vmsize >= $MAX_VMSIZE; |
17 | if $vmsize >= $MAX_VMSIZE; |
23 | }, |
18 | }; |
24 | ); |
|
|