Jeffrey Baker wrote:
> 
> I tried this program in Perl (outside of modperl) and the memory
> consumption is only 4.5MB:
> 
> #!/usr/bin/perl -w
> 
> $foo = {};
> 
> for ($i = 0; $i < 14000; $i++) {
>     $foo->{sprintf('%020d', $i)} = 'A'x150;
> }
> 
> <>;
> 
> 1;
> 
> So I suggest something else might be going on causing your memory
> problems.
> 
Hi Jeffrey,

good idea to boil it down.

Yes, your prog gave me only:

SIZE   RSS  SHARE
 4696  4696  964

Running my code snippet outside mod_perl (with real data) still gives:

SIZE   RSS  SHARE
14932  14M  1012

A simulation like this:

#!/usr/bin/perl -w

$foo = {};

$line = "AAAA\tBBBB\tCCCC\tDDDD";       #       4 string fields (4 chars)
$line .= "\t10.99"x9;                   #       9 float fields (5 chars)
$line .= "\t" . 'A'x17;                 #       5 string fields (rest)
$line .= "\t" . 'B'x17;                 #
$line .= "\t" . 'C'x17;                 #
$line .= "\t" . 'D'x17;                 #
$line .= "\t" . 'E'x17;                 #

@record = split "\t", $line;

for ($i = 0; $i < 14000; $i++)
{
        map { $_++ } @record;

        $foo->{$i} = [ @record ];

        print "$i\t$foo->{$i}->[0],$foo->{$i}->[5]\n"   unless $i % 1000;
}

<>;

1;

prints:

0       AAAB,11.99
1000    ABMN,1011.99
2000    ACYZ,2011.99
3000    AELL,3011.99
4000    AFXX,4011.99
5000    AHKJ,5011.99
6000    AIWV,6011.99
7000    AKJH,7011.99
8000    ALVT,8011.99
9000    ANIF,9011.99
10000   AOUR,10011.99
11000   AQHD,11011.99
12000   ARTP,12011.99
13000   ATGB,13011.99

and gives:

SIZE   RSS  SHARE
14060  13M  1036

There is no difference between real and random data.

But I think, there is an optimization mechanism in perl concerning
strings, so you need less memory for your code.

So what is going on?  2 MB -> 14 MB ?

Still lost in space ;-))

Ernest



-- 

*********************************************************************
* VIRTUALITAS Inc.               *                                  *
*                                *                                  *
* European Consultant Office     *      http://www.virtualitas.net  *
* Internationales Handelszentrum *   contact:Ernest Lergon          *
* Friedrichstraße 95             *    mailto:[EMAIL PROTECTED] *
* 10117 Berlin / Germany         *       ums:+49180528132130266     *
*********************************************************************
       PGP-Key http://www.virtualitas.net/Ernest_Lergon.asc

Reply via email to