ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/checkrusage.ext
(Generate patch)

Comparing deliantra/server/ext/checkrusage.ext (file contents):
Revision 1.6 by root, Tue May 4 21:45:42 2010 UTC vs.
Revision 1.9 by root, Wed Nov 16 22:14:05 2016 UTC

1#! perl 1#! perl
2 2
3# restart server when certain resource limits are exceeded 3# restart server when certain resource limits are exceeded
4 4
5# TODO, CONF framework?
5our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; 6our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000;
6 7
7$^O eq "linux" or die "only linux supported right now.\n"; 8$^O eq "linux" or die "only linux supported right now.\n";
8 9
9our $STAT_FH; 10our $STAT_FH;
10our $TIMER; 11our $TIMER;
11 12
12cf::post_init { 13cf::post_init {
14 cf::async_ext {
13 $STAT_FH = Coro::AIO::aio_open "/proc/self/stat", IO::AIO::O_RDONLY, 0 15 $STAT_FH = Coro::AIO::aio_open "/proc/self/stat", IO::AIO::O_RDONLY, 0
14 or return; 16 or return;
15 17
16 $TIMER = cf::periodic 10, sub { 18 $TIMER = cf::periodic 10, sub {
17 sysseek $STAT_FH, 0, 0; 19 sysseek $STAT_FH, 0, 0;
18 sysread $STAT_FH, my $stat, 4096; # only a single line 20 sysread $STAT_FH, my $stat, 4096; # only a single line
19 my $vmsize = (split / /, $stat)[22]; 21 my $vmsize = (split / /, $stat)[22];
20 22
21 cf::cleanup "memory usage growing high, server would run out of memory soon", 0 23 cf::cleanup "memory usage growing high ($vmsize > $MAX_VMSIZE), server would run out of memory soon", 0
22 if $vmsize >= $MAX_VMSIZE; 24 if $vmsize >= $MAX_VMSIZE;
25 };
23 }; 26 };
24}; 27};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines