ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/checkrusage.ext
Revision: 1.6
Committed: Tue May 4 21:45:42 2010 UTC (14 years ago) by root
Branch: MAIN
Changes since 1.5: +12 -6 lines
Log Message:
*** empty log message ***

File Contents

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