Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

memory leak? #9

Closed
bfg opened this Issue · 5 comments

2 participants

@bfg

Hello!

I just installed feersum 1.200 using cpanm and i was left speechless when i ran ab (16Kreqs/sec on my laptop for hello world) - amazing!

However, i think that there's a memory leak somewhere, becouse memory usage usage grows for ~5MB after each ab run:

startup:
bfg 13458 1.7 0.1 10312 5464 pts/2 S+ 23:53 0:00 | _ /usr/bin/feersum

bfg 13458 3.8 0.3 16184 11292 pts/2 S+ 23:53 0:02 | _ /usr/bin/feersum

bfg 13458 5.1 0.5 20456 15776 pts/2 S+ 23:53 0:05 | _ /usr/bin/feersum

bfg 13458 6.4 0.6 25332 20352 pts/2 S+ 23:53 0:07 | _ /usr/bin/feersum

and so on...

The same happens in prefork mode, but memory leak is equally balanced acros workers, master process doesn't seem to leak.

My perl interpreter:

Summary of my perl5 (revision 5 version 12 subversion 3) configuration:

Platform:
osname=linux, osvers=2.6.36, archname=i586-linux-thread-multi
uname='linux build32 2.6.36 #1 smp 2011-02-21 10:34:10 +0100 i686 athlon i386 gnulinux '
config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-fomit-frame-pointer -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -Accflags=-DPERL_USE_SAFE_PUTENV'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-fomit-frame-pointer -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector'
ccversion='', gccversion='4.5.1 20101208 [gcc-4_5-branch revision 167585]', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -fstack-protector'
libpth=/lib /usr/lib /usr/local/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.11.3.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.11.3'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.12.3/i586-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -fomit-frame-pointer -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe'

Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
PERL_TRACK_MEMPOOL PERL_USE_SAFE_PUTENV USE_ITHREADS
USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF
USE_REENTRANT_API
Built under linux
Compiled at May 6 2011 13:32:51
@INC:
/usr/lib/perl5/site_perl/5.12.3/i586-linux-thread-multi
/usr/lib/perl5/site_perl/5.12.3
/usr/lib/perl5/vendor_perl/5.12.3/i586-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.12.3
/usr/lib/perl5/5.12.3/i586-linux-thread-multi
/usr/lib/perl5/5.12.3
.
Application (app.psgi):

#!/usr/bin/perl

use strict;
use warnings;

sub { return [ 200, [ 'Content-Type', 'text/plain' ], [ "Hello world!\n" ]] }

Is this a bug or am i doing something wrong?

Brane

@stash
Owner

Hi Brane,

I think this is a bug; I don't think you're doing anything wrong.

If you're willing to look into it further, does the memory usage grow with a long-and-slow ab run?

I'll try to reproduce this on 64-bit Ubuntu 11.04 today or tomorrow. It seems to me that you're using a 32-bit kernel, but what Linux distro are you running? If I can't reproduce it I'll fire up a VMware image with what you've got.

Some advice: if you want to use Feersum in production you'll probably want to use a perl built with threads disabled. Perl will be faster and use a little less memory. Socialtext uses AnyEvent::Worker and a sub-process to achieve parallelism instead of using threads.

Cheers,
~stash

@stash stash referenced this issue from a commit
@stash Fix Memory leak when accept() returns no socket.
(Github issue #9)
f7bb15d
@stash
Owner

Hi,

I used Test::Valgrind to see if there was a leak on the C/XS side of things and indeed found one.

Can you confirm that 1.201 fixes it? I just uploaded it to CPAN.

~stash

@stash stash closed this
@bfg
bfg commented

Sorry for long delay, i've been on summer vacation.

I've installed feersum 1.202 and re-ran tests. memory leak is still there but not so dramatic.

I run test with the following command:

/usr/sbin/ab2 -c 100 -n 50000 -k http://127.0.0.1:9002/

Feersum 1.202 process now grows for 3MB every 50K requests (hello world psgi handler).

I'm running opensuse 11.4, 32bit kernel (2.6.37.6-0.5-default), perl 5.12.3, EV 4.03 (epoll enabled).

Long and slow ab run (/usr/sbin/ab2 -c 1 -n 500000 -k http://127.0.0.1:9002/) also leaks memory:

before:
bfg 6690 4.7 0.9 34672 30060 pts/1 S+ 15:03 0:24 | \_ /usr/bin/feersum

after /usr/sbin/ab2 -c 1 -n 500000 -k http://127.0.0.1:9002/:

bfg 6690 10.6 1.8 60256 55496 pts/1 S+ 15:03 1:08 | \_ /usr/bin/feersum

@stash stash reopened this
@stash
Owner

I think I finally found and fixed the real leak in 197a76f. Doing the same ab command as you now shows no leak!

@stash stash closed this
@bfg

Much, much better!!!

But it seems that there is still something that leaks - not so badly :)

ps output showing feersum process after each run of /usr/sbin/ab2 -n 5000 -c 100 -k http://127.0.0.1:9090/

bfg      26297  0.5  0.1  10424  5716 pts/1    S+   20:40   0:00  |   \_ /usr/bin/feersum                           
bfg      26297  0.9  0.2  11392  6788 pts/1    S+   20:40   0:00  |   \_ /usr/bin/feersum                           
bfg      26297  1.4  0.2  11796  7128 pts/1    S+   20:40   0:00  |   \_ /usr/bin/feersum                           
bfg      26297  1.2  0.2  11796  7128 pts/1    S+   20:40   0:00  |   \_ /usr/bin/feersum                           
bfg      26297  1.6  0.2  12184  7400 pts/1    S+   20:40   0:00  |   \_ /usr/bin/feersum                           
bfg      26297  2.0  0.2  12448  7660 pts/1    S+   20:40   0:01  |   \_ /usr/bin/feersum                           
bfg      26297  2.4  0.2  12844  8200 pts/1    S+   20:40   0:01  |   \_ /usr/bin/feersum                           
bfg      26297  2.7  0.2  12980  8200 pts/1    S+   20:40   0:01  |   \_ /usr/bin/feersum                           
bfg      26297  3.1  0.2  13444  8724 pts/1    S+   20:40   0:01  |   \_ /usr/bin/feersum                           
bfg      26297  3.3  0.2  13596  8840 pts/1    S+   20:40   0:02  |   \_ /usr/bin/feersum                           
bfg      26297  3.6  0.2  13748  9100 pts/1    S+   20:40   0:02  |   \_ /usr/bin/feersum                           
bfg      26297  3.9  0.3  14032  9364 pts/1    S+   20:40   0:02  |   \_ /usr/bin/feersum                           
bfg      26297  4.1  0.3  14452  9628 pts/1    S+   20:40   0:02  |   \_ /usr/bin/feersum                           
bfg      26297  4.3  0.3  14472  9892 pts/1    S+   20:40   0:03  |   \_ /usr/bin/feersum                           
bfg      26297  4.5  0.3  14888 10156 pts/1    S+   20:40   0:03  |   \_ /usr/bin/feersum                           
bfg      26297  4.7  0.3  15176 10420 pts/1    S+   20:40   0:03  |   \_ /usr/bin/feersum                           
bfg      26297  4.9  0.3  15432 10796 pts/1    S+   20:40   0:03  |   \_ /usr/bin/feersum                           
bfg      26297  5.1  0.3  15716 11056 pts/1    S+   20:40   0:04  |   \_ /usr/bin/feersum                           
bfg      26297  5.2  0.3  16000 11320 pts/1    S+   20:40   0:04  |   \_ /usr/bin/feersum                           
bfg      26297  5.4  0.3  16280 11584 pts/1    S+   20:40   0:04  |   \_ /usr/bin/feersum                           
bfg      26297  5.4  0.3  16564 11848 pts/1    S+   20:40   0:04  |   \_ /usr/bin/feersum                           
bfg      26297  5.5  0.3  16876 12040 pts/1    S+   20:40   0:05  |   \_ /usr/bin/feersum                           
bfg      26297  5.6  0.4  17160 12300 pts/1    S+   20:40   0:05  |   \_ /usr/bin/feersum

Performances are still amazing:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.