ehdonhon has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I've recently discovered the IPC::Shareable module. It seems to really fit a need I have in one of my present projects. However, in using it, I'm finding that my code is crashing a lot whenever the hash that I am tying execedes the amount of space that I am allocating for it. :(

Questions:

  1. Is there any way to find out how much actual memory is being used by an un-tied hash? I'd like to be able to benchmark the object that I'm using to try to find out an appropriate size to specify when tying it. I know you can find out the number of keys and buckets, but that doesn't really help much in this case.
  2. Is there any way to find out what percentage of the allocated memory an IPC::Shareable object is using?
  3. Ideally, I'd like to be able to monitor how close I am to execeding the allocated memory bounds and then re-allocating a larger memory space when that happens. Is this possible?

Thanks in advance for any pointers!

  • Comment on Determining size of an IPC::Shareable object

Replies are listed 'Best First'.
Re: Determining size of an IPC::Shareable object
by perrin (Chancellor) on Feb 20, 2002 at 03:45 UTC
    My advice is to drop IPC::Shareable in favor of something that won't make you fuss with size issues like this. Obvious options are MLDBM::Sync and Cache::Cache (with File backend).

      Thank you. I should add that performance speed is a really big concern here. Given that additional information what module would you recommend?

        The fastest options are IPC::MM and Cache::Mmap. However, Cache::Cache and MLDBM::Sync are fast enough for most things and easy to setup. You may be surprised to learn that file-based systems tend to be faster than shared memory systems on OSes like Linux that aggressively cache the file system.
Re: Determining size of an IPC::Shareable object
by tstock (Curate) on Feb 20, 2002 at 00:53 UTC
    Wild and ugly plan follows for comments...

    If the code below gives me the memory footprint of the perl interpreter,
    my $mem1 = `perl -e 'print \`ps h -o sz \$\$\`'`;
    and the code below gives me the footprint of this mini script
    my $mem2 = `perl -e '\$a = {A=>1, B=>2, C=>3}; print \`ps h -o sz \$\$ +\`'`;
    Then shouldn't $mem2 - $mem1 = rought overhead of $a ? full test:
    my $mem1 = `perl -e 'print \`ps h -o sz \$\$\`'`; my $mem2 = `perl -e '\$a = {A=>1, B=>2, C=>3}; print \`ps h -o sz \$\$ +\`'`; print "$mem2 - $mem1 = ". ($mem2 - $mem1) . "\n";
    Feel free to say "why don't you use module xy instead ?"... I would much rather do just that :)

    Tiago
Re: Determining size of an IPC::Shareable object
by gav^ (Curate) on Feb 20, 2002 at 04:28 UTC