Hello Perl Monks,

I have written a rather large (~7000 LOC) CGI-based Webscript that I am currently restructuring. It is designed to run on as many platforms as possible, including Win32. Here is what I am changing:

1) modularization, by grouping subroutines and putting them into their own file, importing them with "require"
2) Writing my own extension to HTTP::Server::Simple to run the script within its own webserver. The server package runs the script using do <scriptfile>;.
3) Getting rid of global variables and putting them into a package where they are accessed using the package-name. That package is use()ed in every file.

Now to my concerns:
a) The script stores its data using Tie::Persistent which can take up quite a lot of memory during script execution. This wasn't really a problem before, because the perl process died with end of the CGI script execution. But now that the script is running "forever" in the same process with the server, not only am I discovering how much memory it takes up, it also seems to have a memory leak. I am guessing that the leak is related to the fact that the data hash is package-global, but I could use your input here.
I actually expected the memory to be freed again when the script is done (the do <scriptfile>; part), but aparently not. How do I explicitly free memory again (apart from untie and  %myhash = ();)

b) Ever since I introduced the package-global variables, my script is running slower, no matter if it's run as a CGI script or within its own webserver. I try to persuade myself I didn't change anything else besides that, so I hope it's correct to blame it on making the variables package-global.

So, I hope I was clear enough on all the points and thank you for your attention.

Jakob

In reply to modularization, memory usage and performance by jmagiera

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.