Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have tracked down a performance issue in my perl script which is killing me. I have created a test script below that highlights the issue. I am running activestate perl 5.8.9 (full perl -V below).
In my real script I am receiving data from a socket and adding it to an object (the data is binary, hence the pack) once the data has been received (I can never know the size of the data), I use storeable to freeze the object and pass that onto another thread for processing. Everything works well, except when I am dealing with large (ish) datasets.
Initially I was storing the data in a hash, and it was the freeze that was taking a massive amount of time (longer that it took to process the data on the socket). Google seem to suggest that this problem was due to the use of Windows malloc rather than perls internal malloc. I changed the object to use a single long (binary) string, but now building this string takes a long time (and when I CTRL-C the script I sometimes get Out of memory! panic: pp_iter at X errors). If I pre-allocate memory for the string (using $string = 1 x 56000000), the script below finishes in a second. If I dont preallocate the string the script takes over 3 minutes.I assume my problem is the same Windows malloc problem that was suggested for the freeze issue? Any other way around this? Am I missing something?
Regards, red.Test Script ================== use strict; use warnings; use Storable qw(freeze thaw); #number of items to pack my $iter = 1000000; #our string to pack into my $string =''; #time how long it takes to create a string large enough to hold the da +ta... Time(); #if the line below is commented out, things take a long time... $string = 1 x ($iter*56); Time(); #reset our string... $string=''; #now lets create the data block... for my $count (1..$iter) { $string.=pack('ddddddd',1,2,3,4,5,6,7); } Time(); #how long does it take to freeze this object? my $fr = freeze( \ $string); Time(); print "Finished\n"; sleep(2000); sub Time { my ($user,$system,$cuser,$csystem) = times; print "$user,$system\n"; } =======================
C:\MinGW>perl -V Set up gcc environment - gcc (TDM-1 mingw32) 4.4.1 Summary of my perl5 (revision 5 version 8 subversion 9) configuration: Platform: osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=define use5005threads=undef useithreads=define usemulti +plicity=de fine useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE +_DES_FCRYP T -DNO_HASH_SEED -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPL +ICIT_CONTE XT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -DHASATTRIBU +TE -fno-st rict-aliasing -mms-bitfields', optimize='-O2', cppflags='-DWIN32' ccversion='', gccversion='gcc (TDM-1 mingw32) 4.4.1', gccosandvers +='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64 +', lseeksi ze=8 alignbytes=8, prototype=define Linker and Libraries: ld='g++', ldflags ='-L"C:\Perl\lib\CORE"' libpth=\lib libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 +-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion +-lodbc32 - lodbccp32 -lmsvcrt perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvap +i32 -lshel l32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lvers +ion -lodbc 32 -lodbccp32 -lmsvcrt libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl58.lib gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-mdll -L"C:\Perl\lib\CORE"' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT PERL_IMPLIC +IT_SYS PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_FAST_STD +IO USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_SITECUSTOMIZE Locally applied patches: ActivePerl Build 826 [290470] f7bbab select() generates 'Invalid parameter' messages on Wind +ows Vista. 36f064 do/require don't treat '.♀oo' or '..♀oo' as + absolute paths on Win dows 287a96 Fix -p function and Fcntl::S_IFIFO constant under Micro +soft VC co mpiler Iin_load_module moved for compatibility with build 806 Less verbose ExtUtils::Install and Pod::Find Rearrange @INC so that 'site' is searched before 'perl' Partly reverted #dafda6 to preserve binary compatibility 5e162c Problem killing a pseudo-forked child on Win32 3e5d88 ANSIfy the PATH environment variable on Windows c71e9b,29e136 win32_async_check() can loop indefinitely aeecf6 Fix alarm() for Windows 2003 Built under MSWin32 Compiled at May 24 2009 09:21:05 @INC: C:/Perl/site/lib C:/Perl/lib .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Memory allocation/performance issue for large strings (of binary data) under Windows.
by BrowserUk (Patriarch) on Nov 30, 2009 at 04:59 UTC | |
by Anonymous Monk on Nov 30, 2009 at 06:10 UTC | |
by BrowserUk (Patriarch) on Nov 30, 2009 at 08:38 UTC | |
|
Re: Memory allocation/performance issue for large strings (of binary data) under Windows.
by GrandFather (Saint) on Nov 30, 2009 at 03:29 UTC |