--- deliantra/server/ext/checkrusage.ext 2007/01/27 00:14:03 1.4 +++ deliantra/server/ext/checkrusage.ext 2016/11/16 22:14:05 1.9 @@ -2,23 +2,26 @@ # restart server when certain resource limits are exceeded -our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; +# TODO, CONF framework? +our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; $^O eq "linux" or die "only linux supported right now.\n"; -Event->timer ( - reentrant => 0, - data => cf::WF_AUTOCANCEL, - interval => 10, - after => 10, - cb => sub { - open my $fh, "= $MAX_VMSIZE; - }, -); + $TIMER = cf::periodic 10, sub { + sysseek $STAT_FH, 0, 0; + sysread $STAT_FH, my $stat, 4096; # only a single line + my $vmsize = (split / /, $stat)[22]; + + cf::cleanup "memory usage growing high ($vmsize > $MAX_VMSIZE), server would run out of memory soon", 0 + if $vmsize >= $MAX_VMSIZE; + }; + }; +};