ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/checkrusage.ext
Revision: 1.7
Committed: Fri May 14 22:56:47 2010 UTC (14 years ago) by root
Branch: MAIN
CVS Tags: rel-3_0
Changes since 1.6: +10 -8 lines
Log Message:
music groups, music conf file, post_init async

File Contents

# Content
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 our $STAT_FH;
10 our $TIMER;
11
12 cf::post_init {
13 cf::async_ext {
14 $STAT_FH = Coro::AIO::aio_open "/proc/self/stat", IO::AIO::O_RDONLY, 0
15 or return;
16
17 $TIMER = cf::periodic 10, sub {
18 sysseek $STAT_FH, 0, 0;
19 sysread $STAT_FH, my $stat, 4096; # only a single line
20 my $vmsize = (split / /, $stat)[22];
21
22 cf::cleanup "memory usage growing high, server would run out of memory soon", 0
23 if $vmsize >= $MAX_VMSIZE;
24 };
25 };
26 };