Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Depends on which version of Apache and mod_perl you're using. Personally, I only have experience with the Apache 1.X series and the Apache 2.X with the prefork MPM.

The way I understand it, is that Apache 1.X and 2.X (prefork MPM) start a Perl interpreter at server load time (well, actually two times, but that doesn't matter here right now). Any modules loaded at server startup time, either through directives in the Apache configuration, or in a PerlRequire file, become part of that interpreter. If any of the special regex variables is seen at that time, then all processes that fork off the initial process (the Apache children that do the actual handling of the requests), will have the regex execution speed penalty.

If the special regex variables have not been seen, each Apache child starts out with a fast regex. But as soon as any of the children load code that use the special regexes, then that request and all future requests of that child will have the slower regex performance.

One way to get around that would be to have the child die after handling a request that loaded a module with the special regex characters (see $r->child_terminate). Forking nowadays is pretty fast. On the other hand, the loading of that module might occur often enough to make it worthwhile to keep the child anyway. YMMV.

Now, with Apache 2 with MPM's other than prefork, I understand there's actually a pool of Perl interpreters each with their own characteristics. So it should be possible to have a Perl interpreter with the magic regex characters enabled in it, and one that doesn't. On the other hand, you seem to need a threaded Perl in those situations (someone please correct me if I'm wrong), which has its own drawbacks execution speed wise.

I think in conclusion I would have to say: don't use (modules that use) "$&", "$`" or "$'". Or don't worry about the execution speed penalty.

In general, I would worry less about execution speed in mod_perl, but more about shared memory usage. If your server goes into swap, who cares about slower regexes?

Hope this helps.


In reply to Re: Naughty Regular Expressions and mod_perl by liz
in thread Naughty Regular Expressions and mod_perl by Ovid

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.