mod_perl: performance tips

mod_perl: performance tips

am 25.06.2008 16:57:09 von tyju tiui

Hi,

I'm curious to know if anyone has any mod_perl-specific performance tips?
I've scoured google but most of the performance tips are related specifically to perl which is good, but my application is still quite slow.

I managed to work out the same module in C and I got nearly 5 times the throughout (according to apache bench - ab) than perl module. I was shocked by this. C is all well and fine, but the c module is much less maintainable / portable (by me at least) compared to the perl module.

So I'm wondering if there might be some tips / tricks that you all might be able to share.

Any advice would be greatly appreciated.

Thanks,

Ty

Re: mod_perl: performance tips

am 25.06.2008 17:19:35 von Christopher Taranto

On Wed, June 25, 2008 7:57 am, tyju tiui wrote:
> Hi,
>
>
> I'm curious to know if anyone has any mod_perl-specific performance tips?
> I've scoured google but most of the performance tips are related
> specifically to perl which is good, but my application is still quite
> slow.
>
> I managed to work out the same module in C and I got nearly 5 times the
> throughout (according to apache bench - ab) than perl module. I was
> shocked by this. C is all well and fine, but the c module is much less
> maintainable / portable (by me at least) compared to the perl module.
>
> So I'm wondering if there might be some tips / tricks that you all might
> be able to share.
>
> Any advice would be greatly appreciated.
>
>
> Thanks,
>
>
> Ty

Hi Ty,

Try here:

http://www.modperlbook.org/

Specifically - Part II: mod_perl Performance

Re: mod_perl: performance tips

am 25.06.2008 18:17:04 von Perrin Harkins

On Wed, Jun 25, 2008 at 11:19 AM, Christopher Taranto
wrote:
> Try here:
>
> http://www.modperlbook.org/
>
> Specifically - Part II: mod_perl Performance

Yes, read that, profile your code, and then ask for help with specific
slow parts. There's lots of performance information in the docs on
the mod_perl site too.

- Perrin

Re: mod_perl: performance tips

am 25.06.2008 18:19:35 von Adam Prime

Quoting Perrin Harkins :

> On Wed, Jun 25, 2008 at 11:19 AM, Christopher Taranto
> wrote:
>> Try here:
>>
>> http://www.modperlbook.org/
>>
>> Specifically - Part II: mod_perl Performance
>
> Yes, read that, profile your code, and then ask for help with specific
> slow parts. There's lots of performance information in the docs on
> the mod_perl site too.
>
> - Perrin
>

for MP1 specific stuff, the guide has this section:

http://perl.apache.org/docs/1.0/guide/performance.html

Adam

Re: mod_perl: performance tips

am 25.06.2008 22:24:03 von tyju tiui

hmmm, I read the performance chapters from http://www.modperlbook.org/ but there really isn't much in the way of mod_perl-specific tweaks.
It's mostly about hardware tips, benchmarking tips, and apache server tweaks (and of course perl language tweaks).

The book recommended preloading perl modules which was helpful, but it is still way behind the C module (4 - 5 times fewer requests per second).
Is mod_perl just that much slower than a pure C module?

The code is pretty simple and even uses most of the same libs as the C module.
What I'm saying is I don't think it's the code which is making such a huge difference ... I think mod_perl itself is the bottleneck.

Don't get me wrong, I'm not bashing mod_perl ... I had read in a few different places that mod_perl is on par or only slightly behind C for writing Apache modules. This is why I am searching for performance tweaks to begin with - also because I really want to use perl in place of C :-)

Ty


----- Original Message ----
From: Christopher Taranto
To: tyju tiui
Cc: modperl@perl.apache.org
Sent: Wednesday, June 25, 2008 11:19:35 AM
Subject: Re: mod_perl: performance tips

On Wed, June 25, 2008 7:57 am, tyju tiui wrote:
> Hi,
>
>
> I'm curious to know if anyone has any mod_perl-specific performance tips?
> I've scoured google but most of the performance tips are related
> specifically to perl which is good, but my application is still quite
> slow.
>
> I managed to work out the same module in C and I got nearly 5 times the
> throughout (according to apache bench - ab) than perl module. I was
> shocked by this. C is all well and fine, but the c module is much less
> maintainable / portable (by me at least) compared to the perl module.
>
> So I'm wondering if there might be some tips / tricks that you all might
> be able to share.
>
> Any advice would be greatly appreciated.
>
>
> Thanks,
>
>
> Ty

Hi Ty,

Try here:

http://www.modperlbook.org/

Specifically - Part II: mod_perl Performance

Re: mod_perl: performance tips

am 25.06.2008 22:33:02 von mpeters

tyju tiui wrote:
> hmmm, I read the performance chapters from http://www.modperlbook.org/ but there really isn't much in the way of mod_perl-specific tweaks.
> It's mostly about hardware tips, benchmarking tips, and apache server tweaks (and of course perl language tweaks).

mod_perl is the combination of Apache and Perl. So almost all of the performance
tips are about Apache and Perl.

> I think mod_perl itself is the bottleneck.

Maybe it's not mod_perl, but Perl itself, or your usage of it. Perl is not
as fast as C and depending on what you're doing it could be 4-5 times slower. Or
it could be that you're not writing very efficient Perl code.

> Don't get me wrong, I'm not bashing mod_perl ... I had read in a few different places that mod_perl is on par or only slightly behind C for writing Apache modules. This is why I am searching for performance tweaks to begin with - also because I really want to use perl in place of C :-)

I think it depends on what you're doing. Perl is definitely slower than C at
most things and the only places where it's faster are probably because coding
the faster solution in C is too costly.

But as others have mentioned on the list... you need to profile your code. See
(don't guess) where the bottlenecks are and then post here (or Perl monks, etc)
on advice on speeding things up. Just a warning though... if you change your
code to be better performant that usually comes with some
readability/maintainability loss too.

--
Michael Peters
Plus Three, LP

Re: mod_perl: performance tips

am 25.06.2008 22:34:00 von Perrin Harkins

On Wed, Jun 25, 2008 at 4:24 PM, tyju tiui wrote:
> hmmm, I read the performance chapters from http://www.modperlbook.org/ but there really isn't much in the way of mod_perl-specific tweaks.
> It's mostly about hardware tips, benchmarking tips, and apache server tweaks (and of course perl language tweaks).

Well, that's really all there is to tune with mod_perl itself. The
rest is Perl.

> The book recommended preloading perl modules which was helpful, but it is still way behind the C module (4 - 5 times fewer requests per second).
> Is mod_perl just that much slower than a pure C module?

Is C 5 times faster than Perl? Yes, it often is for CPU intensive
number-crunching applications. Is that what you're doing?

> What I'm saying is I don't think it's the code which is making such a huge difference ... I think mod_perl itself is the bottleneck.

Since mod_perl is just the glue code between Apache and Perl, that
doesn't really make sense. The overhead of mod_perl compared to
running a C module is negligible. What's taking all the time is your
Perl code.

There are lots of tricks for improving the speed of Perl, but unless
you can show us some code, there's no way for us to help you. I still
suggest running your code through a profiler and then getting help
with the slowest parts, either here or on a general Perl discussion.

- Perrin

Re: mod_perl: performance tips

am 26.06.2008 11:20:11 von torsten.foertsch

On Wed 25 Jun 2008, tyju tiui wrote:
> but it is still way behind the C module (4 - 5 times fewer requests per
> second). Is mod_perl just that much slower than a pure C module?

Yes it is slower. MP registers hooks at almost all places possible. Your pure
C module probably uses only 1 or 2 of them.

I have seen a factor of 2-2.5 between a very simple PerlResponseHandler
(something like the code below) and a not heavily tuned Apache sending a
plain file consisting of 2 characters. I expect a C module to be even faster.

sub {
use Apache2::RequestRec ();
use Apache2::RequestIO ();
$_[0]->content_type('text/plain');
$_[0]->headers_out->set('Content-Length', 2);
$_[0]->print('ok');
0;
}

Note, without the Content-Length header it would be a lot slower in terms of
requests per second.

If you want performance write C. MP is a real performance gain (and drop of
the server load) compared with CGI loosing almost nothing of the flexibility.

So, disable all unnecessary hooks in mod_perl or even better compile them out
and allways send a Content-Length header. You can also try to write your
output to a temporary file and let the default handler send that file. That
may also speed it up (it'll use sendfile) but it depends.

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net