Anybody writing Apache modules in Perl?
Hi,
I just read the O'Reilly book: Writing Apache Modules with Perl
I have .cgi scripts which have to pull a large data structure (a hash of hashes read from a text file) into memory each time the scripts are called. So if this script is called 10,000 times a day, this same large data structure has to be pulled into memory 10,000 times.
If I understand what I've read in the book though, then I can write an Apache module that will load this data structure into memory only once - every time Apache starts - and then make it available to the .cgi scripts (kind of like an environmental variable). The performance benefit to my .cgi scripts would be enormous.
Can anyone comment on this? Will this work the way I've described? Is this a common technique?
(I'll also be moving this large data structure to a MySQL database, but that's something to tackle on another day...)
Thanks in advance...
Wil posted this at 18:38 — 15th February 2003.
They have: 601 posts
Joined: Nov 2001
You looked into mod_perl ?
critical posted this at 19:32 — 15th February 2003.
They have: 46 posts
Joined: May 2002
Yes, mod_perl is already installed on my server.
Wil posted this at 10:34 — 16th February 2003.
They have: 601 posts
Joined: Nov 2001
Then I recommend you looking into that for what you want to do instead of rolling out your own module.
critical posted this at 15:24 — 16th February 2003.
They have: 46 posts
Joined: May 2002
Admittedly I'm not an expert on what mod_perl does or how it does it. My understanding is that it greatly speeds up Apache's ability to run Perl scripts because most of the Perl "overhead" is done on Apache-start rather than every time every individual Perl script runs. Because of this I would never run Apache without mod_perl.
My original question was... is anybody out there a sophisticated enough web developer to have written their own Apache modules? O'Reilly has a whole book on the subject. I'm definitely *not* talking about reinventing the wheel and re-writing mod_perl.
And we're not talking about brain-surgery here... a simple example would be to load $MY_CONSTANT = "3.14" into memory every time Apache starts so that it is available as an environmental variable to all scripts. My original example would be to load a much larger, more complex data structure into memory - so that every time a script runs it doesn't have to repeat this processing and use up additional memory.
Anybody out there doing this? Thanks in advance...
Wil posted this at 17:36 — 16th February 2003.
They have: 601 posts
Joined: Nov 2001
Ah, OK. Sorry, I must have misunderstood you the first time. No, I have never written a module for Apache.
But my initial answer was why don't you use mod_perl to load your data structures into memory?
- wil
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.