The part of the code that you mention as being slow (and as using a lot of CPU) is the part that uses complex regexes to parse HTML. See Mojo::DOM::HTML's source for more details.

Looking briefly at the regexes, I can imagine there being some versions of Perl where their performance is much worse than for other versions of Perl.

But you don't even mention whether you are using the same versions of the Mojo modules between the two systems, so it could be that much different regexes are being used between the two.

I don't consider this next item to be very likely to be the problem. But we recently discovered that some VM systems default to acting like they support every single optional CPU feature. This is probably done with the thinking of preventing some code from breaking because it requires some specific optional CPU feature. However, the more common case (in our experience) is that code only makes use of certain CPU features when they are available and works around the absence when not. And this leads to code that tries to make use of advanced, optional CPU features that the VM must emulate because the physical CPUs don't support it. Such emulation of a general feature can be orders of magnitude slower than the code's work around (for its specific use case). We have seen this lead to significant server performance problems.

Simply configuring the VM to report support for only the CPU features that the physical CPUs actually support, made such performance problems disappear.

- tye        


In reply to Re: Simple script goes from 2s to ~2mins when run on VPS (regexes) by tye
in thread Simple script goes from 2s to ~2mins when run on VPS by Anonymous Monk

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.