franzs has asked for the wisdom of the Perl Monks concerning the following question:
Any idea how to prevent the script from using more and more memory? The script below is a stripped down version of the original script:time/s virtual residential 00:00:00 16504 8428 00:01:00 17528 9468 00:02:00 17656 10292 00:03:00 18680 10740 00:04:00 18680 11536 00:05:00 19704 12228 00:06:00 20728 12916 00:07:00 21752 13812 00:08:00 21752 14288 00:09:00 23800 14964 00:10:00 23800 16108 00:11:00 23800 16380 00:12:00 24824 17168 00:13:00 25848 17912 00:14:00 26872 18760 00:15:00 26872 19228 00:16:00 27896 20164 00:17:00 28920 20860 00:18:00 29944 21688 00:19:00 30968 22592 00:20:00 30968 23328 00:21:00 31992 24060 00:22:00 31992 24696 00:23:00 33016 25328 00:24:00 34040 26140 00:25:00 35064 26812 00:26:00 35064 27780 00:27:00 36088 28340 00:28:00 37112 29272 00:29:00 38136 30084 00:30:00 38136 30856 00:31:00 39160 31368 00:32:00 40184 32268 00:33:00 41208 33032
Details of perl interpreter:#!/usr/bin/perl use strict; use warnings; use Config; use threads; use Time::HiRes qw( usleep ); $Config{useithreads} or die('Recompile Perl with threads to run this p +rogram.'); foreach my $i (1 .. 100000) { while ((my $nthreads = scalar threads->list()) >= 10) { print $nthreads . " running. waiting 1 second.\n"; sleep(1); foreach my $thread (threads->list(threads::joinable)) +{ $thread->join(); } } threads->create(\&sub1); usleep(333333); foreach my $thread (threads->list(threads::joinable)) { $thread->join(); } } foreach my $thread (threads->list()) { $thread->join(); } sub sub1 { my $sleep_value = int(rand(2) * 100) / 100; print "thread id " . threads->tid() . ": Start sleeping " . $s +leep_value . " seconds\n"; usleep($sleep_value * 1000000); print "thread id " . threads->tid() . ": Done sleeping " . $s +leep_value . " seconds\n"; }
Summary of my perl5 (revision 5 version 10 subversion 1) configuration +: Platform: osname=freebsd, osvers=8.2-release, archname=i386-freebsd-thread-m +ulti-64int uname='freebsd hal.hsh 8.2-release freebsd 8.2-release #0: wed feb + 23 11:54:06 cet 2011 dirk@hal.hsh:exportobjusrsrcsyshal i386 ' config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/per +l5/5.10.1/mach -Dprivlib=/usr/local/lib/perl5/5.10.1 -Dman3dir=/usr/l +ocal/lib/perl5/5.10.1/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Ds +itearch=/usr/local/lib/perl5/site_perl/5.10.1/mach -Dsitelib=/usr/loc +al/lib/perl5/site_perl/5.10.1 -Dscriptdir=/usr/local/bin -Dsiteman3di +r=/usr/local/lib/perl5/5.10.1/man/man3 -Dsiteman1dir=/usr/local/man/m +an1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Di +nc_version_list=none -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5. +10.1/BSDPAN" -Doptimize=-O2 -pipe -fno-strict-aliasing -Ud_dosuid -Ui +_gdbm -Dusethreads=y -Dusemymalloc=n -Duse64bitint -Dusemultiplicity= +y' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=define, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: [...]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: memory leak with perl ithreads
by zwon (Abbot) on Apr 03, 2011 at 11:17 UTC | |
by Anonymous Monk on Apr 03, 2011 at 11:25 UTC | |
by zwon (Abbot) on Apr 03, 2011 at 13:13 UTC | |
|
Re: memory leak with perl ithreads
by dave_the_m (Monsignor) on Apr 03, 2011 at 11:12 UTC | |
by dave_the_m (Monsignor) on Apr 03, 2011 at 18:49 UTC | |
by BrowserUk (Patriarch) on Apr 03, 2011 at 18:57 UTC | |
by dave_the_m (Monsignor) on Apr 03, 2011 at 21:51 UTC | |
|
Re: memory leak with perl ithreads
by Anonymous Monk on Apr 03, 2011 at 10:14 UTC | |
|
Re: memory leak with perl ithreads
by Anonymous Monk on Nov 10, 2012 at 02:29 UTC |