Skip to content

Instantly share code, notes, and snippets.

@nikopol
Created January 12, 2012 10:38
Show Gist options
  • Save nikopol/1599790 to your computer and use it in GitHub Desktop.
Save nikopol/1599790 to your computer and use it in GitHub Desktop.
dancer memory leak
#!/usr/bin/env perl
use strict;
use warnings;
use Dancer;
#return memory used by the current pid
sub memused {
sysopen(my $fh, "/proc/$$/statm", 0) or die $!;
sysread($fh, my $line, 255) or die $!;
close($fh);
my($vsz, $rss, $share, $text, $crap, $data, $crap2) = split(/\s+/, $line, 7);
return $rss * 4; #4 = page size in kb
}
set session => 'Simple';
my $start;
my $count = 0;
get '/' => sub {
session 'zob'; # <= no leak without this line
my $mem = memused;
$start = $mem unless $start;
++$count;
print 'MEM: ',$mem,'k (+',($mem-$start),'k in ',$count," calls)\n";
};
dance;
#Dancer v1.3091 & perl 5.14.2
#tested with bash: yes 'curl -s localhost:3000 | grep MEM' | sh
#same problem with plack (--workers=1)
#same problem with session => 'YAML'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment