You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Stas Bekman <st...@stason.org> on 2002/01/25 07:32:55 UTC
performance coding project? (was: Re: When to cache)
Rob Nagler wrote:
> Perrin Harkins writes:
> Here's a fun example of a design flaw. It is a performance test sent
> to another list. The author happened to work for one of our
> competitors. :-)
>
>
> That may well be the problem. Building giant strings using .= can be
> incredibly slow; Perl has to reallocate and copy the string for each
> append operation. Performance would likely improve in most
> situations if an array were used as a buffer, instead. Push new
> strings onto the array instead of appending them to a string.
>
> #!/usr/bin/perl -w
> ### Append.bench ###
>
> use Benchmark;
>
> sub R () { 50 }
> sub Q () { 100 }
> @array = (" " x R) x Q;
>
> sub Append {
> my $str = "";
> map { $str .= $_ } @array;
> }
>
> sub Push {
> my @temp;
> map { push @temp, $_ } @array;
> my $str = join "", @temp;
> }
>
> timethese($ARGV[0],
> { append => \&Append,
> push => \&Push });
> <<
>
> Such a simple piece of code, yet the conclusion is incorrect. The
> problem is in the use of map instead of foreach for the performance
> test iterations. The result of Append is an array of whose length is
> Q and whose elements grow from R to R * Q. Change the map to a
> foreach and you'll see that push/join is much slower than .=.
>
> Return a string reference from Append. It saves a copy.
> If this is "the page", you'll see a significant improvement in
> performance.
>
> Interestingly, this couldn't be "the problem", because the hypothesis
> is incorrect. The incorrect test just validated something that was
> faulty to begin with. This brings up "you can't talk about it unless
> you can measure it". Use a profiler on the actual code. Add
> performance stats in your code. For example, we encapsulate all DBI
> accesses and accumulate the time spent in DBI on any request. We also
> track the time we spend processing the entire request.
While we are at this topic, I want to suggest a new project. I was
planning to start working on it long time ago, but other things always
took over.
The perl.apache.org/guide/performance.html and a whole bunch of
performance chaptes in the upcoming modperl book have a lot of
benchmarks, comparing various coding techniques. Such as the example
you've provided. The benchmarks are doing both pure Perl and mod_perl
specific code (which requires running Apache, a perfect job for the new
Apache::Test framework.)
Now throw in the various techniques from 'Effective Perl' book and voila
you have a great project to learn from.
Also remember that on varous platforms and various Perl versions the
benchmark results will differ, sometimes very significantly.
I even have a name for the project: Speedy Code Habits :)
The point is that I want to develop a coding style which tries hard to
do early premature optimizations. Let me give you an example of what I
mean. Tell me what's faster:
if (ref $b eq 'ARRAY'){
$a = 1;
}
elsif (ref $b eq 'HASH'){
$a = 1;
}
or:
my $ref = ref $b;
if ($ref eq 'ARRAY'){
$a = 1;
}
elsif ($ref eq 'HASH'){
$a = 1;
}
Sure, the win can be very little, but it ads up as your code base's size
grows.
Give you a similar example:
if ($a->lookup eq 'ARRAY'){
$a = 1;
}
elsif ($a->lookup eq 'HASH'){
$a = 1;
}
or
my $lookup = $a->lookup;
if ($lookup eq 'ARRAY'){
$a = 1;
}
elsif ($lookup eq 'HASH'){
$a = 1;
}
now throw in sub attributes and re-run the test again.
add examples of map vs for.
add examples of method lookup vs. procedures
add examples of concat vs. list vs. other stuff from the guide.
mod_perl specific examples from the guide/book ($r->args vs
Apache::Request::param, etc)
If you understand where I try to take you, help me to pull this project
off and I think in a long run we can benefit a lot.
This goes along with the Apache::Benchmark project I think (which is yet
another thing I want to start...), probably could have these two ideas
put together.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: Apache::args vs Apache::Request speed
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
>
>>Also I was only a user of Apache::Request, so I know very little about
>>it. It's about a time I should learn its guts. Does this library work
>>for 2.0 as is, or is there a new implementation for 2.0? I see that ToDo
>>says that it should be ported to 2.0.
>>
>
> I've never tried using it with 2.0, but I'd guess that it won't run
> there as-is. But that should be our top priority after we release
> 1.0. It's really important that we get out a release version that
> we promise not to tinker around with API-wise, so people can start
> developing derivative products without too much worry that we'll break
> their code. Lots of people use apreq outside of the Perl community,
> and getting a 1.x release out there for the C API is very important
> to them.
Certainly.
>>So first the C lib should be ported and then the Perl glue should be
>>written, right?
>>
>
> Yes, exactly. Choosing a new C API for apreq that's geared toward
> apache 2.0 AND improves upon some of the deficiencies of the current
> libapreq is an important first step, and IMO needs to be debated and
> created on the apreq-dev list NOW. It would be great if you signed up
> to that list so we can start discussing these issues there. I've cc-d
> this email to the list just in case :)
I'm on the list now. Let's start.
--
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: Apache::args vs Apache::Request speed
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> Also I was only a user of Apache::Request, so I know very little about
> it. It's about a time I should learn its guts. Does this library work
> for 2.0 as is, or is there a new implementation for 2.0? I see that ToDo
> says that it should be ported to 2.0.
I've never tried using it with 2.0, but I'd guess that it won't run
there as-is. But that should be our top priority after we release
1.0. It's really important that we get out a release version that
we promise not to tinker around with API-wise, so people can start
developing derivative products without too much worry that we'll break
their code. Lots of people use apreq outside of the Perl community,
and getting a 1.x release out there for the C API is very important
to them.
> So first the C lib should be ported and then the Perl glue should be
> written, right?
Yes, exactly. Choosing a new C API for apreq that's geared toward
apache 2.0 AND improves upon some of the deficiencies of the current
libapreq is an important first step, and IMO needs to be debated and
created on the apreq-dev list NOW. It would be great if you signed up
to that list so we can start discussing these issues there. I've cc-d
this email to the list just in case :)
Best.
--
Joe Schaefer
Re: Apache::args vs Apache::Request speed
Posted by Joe Schaefer <jo...@sunstarsys.com>.
John Siracusa <si...@mindspring.com> writes:
> I'm cc-ing this to the Mac OS X Perl list in the hopes that someone can
> provide a test environment for you. (I would, but my OS X box is behind a
> firewall at work.)
>
> So how about it, macosx@perl.org folks, can any of you help get libapreq up
> and running on OS X an long last? (See message quoted below)
>
Maybe this will help:
http://fink.sourceforge.net/doc/porting/porting.html
The Unix build of libapreq goes in 3 steps:
1) build a static c library: libapreq.a
2) build object files Request.o, Cookie.o
3) link each object file against libapreq.a to
make shared libraries Request.so Cookie.so
So each file gets it's own copy of libapreq, symbols and
all. For ELF-based systems, that's not a problem since
the linking executable knows not only the library's filename,
but also the location of the desired symbol within the file
(actually there's something called a jump table inside the
.so that provides some necessary indirection, but that's a
technicality that's not particularly relevant to the issue.)
AIUI, the problem with OS/X is that their linker doesn't
provide the executable with a similar addressing scheme
for unresolved symbols; it just tells the executable which
libraries are needed to resolve them without also telling
it "where to look" for a given symbol. So because Request.bundle
and Cookie.bundle both (accidentally?) provide resolution for
libapreq's symbols, the executable gets confused and bails out.
If I'm right here, then removing the libapreq symbols from
Cookie.bundle and Request.bundle should do the trick. There
are lots of ways to reorganize things in order to achieve this,
and I'm somewhat surprised that none of the OS/X folks have
made any progress in this regard.
So maybe I'm wrong, but I don't think any of us will learn the
answer until some OS/X person actually _attempts_ to fix it.
--
Joe Schaefer
Re: Apache::args vs Apache::Request speed
Posted by Andrew Ho <an...@tellme.com>.
Heyas,
JS>Would someone PLEASE volunteer to try to compile and test
JS>apache+mod_perl & libapreq on OS/X using the experimental
JS>code I posted there? Even if you can't get it working,
JS>ANY feedback about what happened when you tried would be
JS>VERY helpful.
Slightly off topic; I'd like to help with this but I have this curious
problem. I'm trying to build Perl 5.6.itself 1 on Mac OS X (with the
latest 10.1.2 update freshly installed, using the compiler from the
developer tools CD that comes with OS X when you buy the 10.1 boxed
version) before building Apache/mod_perl.
So I go through the entire Configure sequence, and then no Makefile gets
created (it goes through the entire routine of saying it's generating a
Makefile, but whether I run Makefile.SH or have it done through Configure,
no Makefile actually ever gets created).
Has anybody else seen this really weird behavior trying to build Perl
5.6.1 on Mac OS X? A web search didn't turn up any relevant posts.
Humbly,
Andrew
----------------------------------------------------------------------
Andrew Ho http://www.tellme.com/ andrew@tellme.com
Engineer info@tellme.com Voice 650-930-9062
Tellme Networks, Inc. 1-800-555-TELL Fax 650-930-9101
----------------------------------------------------------------------
Re: Apache::args vs Apache::Request speed
Posted by Matt Sergeant <ma...@sergeant.org>.
On 1 Feb 2002, Joe Schaefer wrote:
> Would someone PLEASE volunteer to try to compile and test
> apache+mod_perl & libapreq on OS/X using the experimental
> code I posted there? Even if you can't get it working,
> ANY feedback about what happened when you tried would be
> VERY helpful.
OK, if someone can communicate with me in private, seriously dumbed down
details, I can try this. I'm a libapreq committer, and have sourceforge
farm access, so I'll do my best there - though last time I tried I
couldn't get onto their OSX box...
--
<!-- Matt -->
<:->Get a smart net</:->
Re: Apache::args vs Apache::Request speed
Posted by John Siracusa <si...@mindspring.com>.
On 2/1/02 3:39 PM, Ian Ragsdale wrote:
> On the other hand, I'd be happy to compile it, but what would I need to do
> to test it?
I'm in the process of trying this too (just building a mod_perl httpd in OS
X is a bit tricky...) To test it, I think all you need to do is put these
two lines in your "startup.pl" file (or whatever):
use Apache::Request;
use Apache::Cookie;
If that works, the next step is to make an actual apache handler that uses
both the modules to actually do something. And if that works, post detailed
instructions (starting with the wget of the source tarballs :)
-John
Re: Apache::args vs Apache::Request speed
Posted by Ian Ragsdale <ia...@SKYLIST.net>.
On 2/1/02 2:21 PM, "Joe Schaefer" <jo...@sunstarsys.com> wrote:
> Ian Ragsdale <ia...@SKYLIST.net> writes:
>
>> How about setting something up on SourceForge? I know they have OS X
>> environments available for compiling and testing.
>
> apreq is an ASF project; IMO what we need now is a hero, not a
> change of venue.
>
I'm not suggesting you switch it to stay at sourceforge, I'm just saying
that they have OS X boxes you can compile & test on. Seems pretty simple to
me. I'd volunteer my own computer, but it's an iBook and is constantly
switching IP addresses due to moving around.
On the other hand, I'd be happy to compile it, but what would I need to do
to test it?
Ian
[OT] Mac OS X compilation woes (Was: Apache::args vs Apache::Request
speed)
Posted by Andrew Ho <an...@tellme.com>.
Hello,
JS>An initial build and install of:
JS> http://www.apache.org/~joes/libapreq-1.0-rc1.tar.gz
JS>
JS>on a previously-working apache 1.3.22 mod_perl 1.26 server on OS X 10.1.2
JS>with this:
JS> use Apache::Request;
JS> use Apache::Cookie;
JS>
JS>In its startup.pl file causes the following:
JS>
JS># bin/httpd -d /usr/local/apache -f conf/httpd.conf
JS>dyld: bin/httpd Undefined symbols:
JS>_ap_day_snames
JS>...
JS>_sv2request_rec
I'm having a similar problem but it's for ANY symbols in a .a that you
compile something with. e.g. say I have a C library and it lives in
/usr/local/lib/libfoo.a (include in /usr/local/include/foo.h) and exports
void foo(). If I have a test C program tester.c:
#include <foo.h>
int main { foo(); return 0 }
And I compile it so:
% cc -o tester -lfoo tester.c
And I run it, I'll get the undefined symbols error that you paste above.
This happens for me with a variety of existing open source libraries that
I've built. I theorize your problem with libapreq may stem from a similar
problem (I'm also running 10.1.2).
Humbly,
Andrew
----------------------------------------------------------------------
Andrew Ho http://www.tellme.com/ andrew@tellme.com
Engineer info@tellme.com Voice 650-930-9062
Tellme Networks, Inc. 1-800-555-TELL Fax 650-930-9101
----------------------------------------------------------------------
Re: Apache::args vs Apache::Request speed
Posted by John Siracusa <si...@mindspring.com>.
On 2/1/02 3:21 PM, Joe Schaefer wrote:
> Would someone PLEASE volunteer to try to compile and test
> apache+mod_perl & libapreq on OS/X using the experimental
> code I posted there? Even if you can't get it working,
> ANY feedback about what happened when you tried would be
> VERY helpful.
(The below may not be very helpful, but I've gotta run right now. I'll try
more this weekend if I can.)
An initial build and install of:
http://www.apache.org/~joes/libapreq-1.0-rc1.tar.gz
on a previously-working apache 1.3.22 mod_perl 1.26 server on OS X 10.1.2
with this:
use Apache::Request;
use Apache::Cookie;
In its startup.pl file causes the following:
# bin/httpd -d /usr/local/apache -f conf/httpd.conf
dyld: bin/httpd Undefined symbols:
_ap_day_snames
_ap_find_path_info
_ap_get_client_block
_ap_getword
_ap_getword_conf
_ap_hard_timeout
_ap_ind
_ap_kill_timeout
_ap_log_rerror
_ap_make_array
_ap_make_dirstr_parent
_ap_make_table
_ap_month_snames
_ap_null_cleanup
_ap_pcalloc
_ap_pfclose
_ap_pfdopen
_ap_popenf
_ap_psprintf
_ap_pstrcat
_ap_pstrdup
_ap_pstrndup
_ap_push_array
_ap_register_cleanup
_ap_setup_client_block
_ap_should_client_block
_ap_table_add
_ap_table_do
_ap_table_get
_ap_table_set
_ap_table_unset
_ap_unescape_url
_hvrv2table
_mod_perl_tie_table
_perl_request_rec
_sv2request_rec
More later, I hope... :)
-John
Re: Apache::args vs Apache::Request speed
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Ian Ragsdale <ia...@SKYLIST.net> writes:
> How about setting something up on SourceForge? I know they have OS X
> environments available for compiling and testing.
apreq is an ASF project; IMO what we need now is a hero, not a
change of venue.
[...]
> > On 1/28/02 2:02 PM, Joe Schaefer <jo...@sunstarsys.com> wrote:
[...]
> >> I hope a new release will be just around the corner, but if you want
> >> to test out some of the latest stuff, have a look at
> >>
> >> http://www.apache.org/~joes/
Would someone PLEASE volunteer to try to compile and test
apache+mod_perl & libapreq on OS/X using the experimental
code I posted there? Even if you can't get it working,
ANY feedback about what happened when you tried would be
VERY helpful.
Thanks alot.
--
Joe Schaefer
Re: Apache::args vs Apache::Request speed
Posted by Ian Ragsdale <ia...@SKYLIST.net>.
How about setting something up on SourceForge? I know they have OS X
environments available for compiling and testing.
Ian
On 1/28/02 2:19 PM, "John Siracusa" <si...@mindspring.com> wrote:
> I'm cc-ing this to the Mac OS X Perl list in the hopes that someone can
> provide a test environment for you. (I would, but my OS X box is behind a
> firewall at work.)
>
> So how about it, macosx@perl.org folks, can any of you help get libapreq up
> and running on OS X an long last? (See message quoted below)
>
> -John
>
> On 1/28/02 2:02 PM, Joe Schaefer <jo...@sunstarsys.com> wrote:
>> Stas Bekman <st...@stason.org> writes:
>>> Great! Now we have an even broader benchmark. Please tell me when 1.0 is
>>> released (in case I get carried away with other things and don't notice
>>> the announce) and I'll make sure to update my benchmarking package,
>>> re-run the benchmarks and correct the results in the guide.
>>
>> Great- there's a typo or two in the handler_do sub, but they should be
>> pretty obvious when you try to run it.
>>
>> I hope a new release will be just around the corner, but if you want
>> to test out some of the latest stuff, have a look at
>>
>> http://www.apache.org/~joes/
>>
>> I don't think we'll have a 1.0 that works on OS/X, but I might be able
>> to include a patch in the distro that will build the C api of libapreq
>> directly into httpd. This might allow OS/X to run Apache::Request and
>> Apache::Cookie at the same time, but that platform is unavailable to me
>> for testing.
>
>
Re: Apache::args vs Apache::Request speed
Posted by John Siracusa <si...@mindspring.com>.
I'm cc-ing this to the Mac OS X Perl list in the hopes that someone can
provide a test environment for you. (I would, but my OS X box is behind a
firewall at work.)
So how about it, macosx@perl.org folks, can any of you help get libapreq up
and running on OS X an long last? (See message quoted below)
-John
On 1/28/02 2:02 PM, Joe Schaefer <jo...@sunstarsys.com> wrote:
> Stas Bekman <st...@stason.org> writes:
>> Great! Now we have an even broader benchmark. Please tell me when 1.0 is
>> released (in case I get carried away with other things and don't notice
>> the announce) and I'll make sure to update my benchmarking package,
>> re-run the benchmarks and correct the results in the guide.
>
> Great- there's a typo or two in the handler_do sub, but they should be
> pretty obvious when you try to run it.
>
> I hope a new release will be just around the corner, but if you want
> to test out some of the latest stuff, have a look at
>
> http://www.apache.org/~joes/
>
> I don't think we'll have a 1.0 that works on OS/X, but I might be able
> to include a patch in the distro that will build the C api of libapreq
> directly into httpd. This might allow OS/X to run Apache::Request and
> Apache::Cookie at the same time, but that platform is unavailable to me
> for testing.
Re: Apache::args vs Apache::Request speed
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> Great! Now we have an even broader benchmark. Please tell me when 1.0 is
> released (in case I get carried away with other things and don't notice
> the announce) and I'll make sure to update my benchmarking package,
> re-run the benchmarks and correct the results in the guide.
Great- there's a typo or two in the handler_do sub, but they should be
pretty obvious when you try to run it.
I hope a new release will be just around the corner, but if you want
to test out some of the latest stuff, have a look at
http://www.apache.org/~joes/
I don't think we'll have a 1.0 that works on OS/X, but I might be able
to include a patch in the distro that will build the C api of libapreq
directly into httpd. This might allow OS/X to run Apache::Request and
Apache::Cookie at the same time, but that platform is unavailable to me
for testing.
--
Joe Schaefer
Re: Apache::args vs Apache::Request speed
Posted by Stas Bekman <st...@stason.org>.
mark warren bracher wrote:
> I didn't ever actually see a post with newer numbers, so here goes......
>
> I tested the same 50 clients/5000 requests as stas' test in the guide.
> one pass with 2 uri params; another with 26. naturally I ran it all on
> a server big (and quiescent) enough to handle the 50 concurrent
> requests. I left out CGI since we already know it is slow.
>
> /test/params and /test/args are mod_perl handlers (I don't use
> Apache::Registry for anything) ParamsTest and ArgsTest respectively. the
> code for both handlers and the relevant pieces of ab output are pasted
> in below.
>
> -------------------------------------------------------------
> name query_length | avtime completed failed rps
> -------------------------------------------------------------
> apache_args 25 | 33.77 5000 0 1481
> apache_request 25 | 33.17 5000 0 1507
> apache_args 337 | 43.51 5000 0 1141
> apache_request 337 | 45.31 5000 0 1103
> --------------------------------------------------------------
> Non-varying sub-test parameters:
> --------------------------------------------------------------
> concurrency : 50
> connections : 5000
>
> so $apr->param is marginally faster than $r->args for the shorter query,
> marginally slower for the longer one. I think this may be because we
> can return the full hash $r->args whereas we need to map over
> $apr->param to get a hash (so param gets called three times for the
> short query, 27 times for the larger one). still, much closer numbers
> than the former test...
Thanks Mark for pushing me to rerun the benchmark :)
Actually from the tests that I just run Apache::Request::param is
actually kicks $r->args on long inputs, and a bit faster on the short
query strings. Even though as you have noticed we call $q->param() 2 x
keys times more for each request.
Here are the results:
concurrency connections name query_length | avtime
completed failed rps
--------------------------------------------------------------------------------------------
50 5000 apache_request_param 25 | 53
5000 0 900
50 2000 apache_request_param 25 | 54
2000 0 884
50 5000 r_args 25 | 55
5000 0 879
50 2000 apache_request_param 105 | 54
2000 0 879
10 5000 apache_request_param 25 | 10
5000 0 878
50 5000 r_args 105 | 55
5000 0 876
10 2000 r_args 105 | 10
2000 0 869
50 5000 apache_request_param 105 | 56
5000 0 865
10 5000 apache_request_param 105 | 10
5000 0 855
10 5000 r_args 25 | 11
5000 0 850
10 2000 apache_request_param 105 | 11
2000 0 836
10 2000 r_args 25 | 11
2000 0 835
10 2000 apache_request_param 25 | 11
2000 0 832
50 2000 r_args 25 | 58
2000 0 827
10 5000 r_args 105 | 11
5000 0 810
50 5000 apache_request_param 207 | 64
5000 0 754
50 2000 apache_request_param 337 | 64
2000 0 750
10 2000 apache_request_param 207 | 12
2000 0 749
10 2000 apache_request_param 337 | 12
2000 0 749
50 2000 apache_request_param 207 | 64
2000 0 749
10 5000 apache_request_param 207 | 12
5000 0 746
50 2000 r_args 105 | 64
2000 0 744
10 5000 apache_request_param 337 | 12
5000 0 732
50 5000 r_args 207 | 72
5000 0 671
10 2000 r_args 337 | 14
2000 0 665
10 5000 r_args 207 | 14
5000 0 661
50 2000 r_args 337 | 73
2000 0 660
10 2000 r_args 207 | 14
2000 0 657
50 5000 apache_request_param 337 | 74
5000 0 647
50 2000 r_args 207 | 75
2000 0 645
10 5000 r_args 337 | 15
5000 0 627
50 5000 r_args 337 | 81
5000 0 601
I'll update this and other benchmarks. Something that should be done
once in a while since the software's performance tend to change over the
time :)
I'll probably run many more tests and build graphs, so it'll be much
easier to see what's happening, than from looking at many numbers.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Apache::args vs Apache::Request speed
Posted by mark warren bracher <br...@citysearch.com>.
I didn't ever actually see a post with newer numbers, so here goes......
I tested the same 50 clients/5000 requests as stas' test in the guide.
one pass with 2 uri params; another with 26. naturally I ran it all on
a server big (and quiescent) enough to handle the 50 concurrent
requests. I left out CGI since we already know it is slow.
/test/params and /test/args are mod_perl handlers (I don't use
Apache::Registry for anything) ParamsTest and ArgsTest respectively.
the code for both handlers and the relevant pieces of ab output are
pasted in below.
-------------------------------------------------------------
name query_length | avtime completed failed rps
-------------------------------------------------------------
apache_args 25 | 33.77 5000 0 1481
apache_request 25 | 33.17 5000 0 1507
apache_args 337 | 43.51 5000 0 1141
apache_request 337 | 45.31 5000 0 1103
--------------------------------------------------------------
Non-varying sub-test parameters:
--------------------------------------------------------------
concurrency : 50
connections : 5000
so $apr->param is marginally faster than $r->args for the shorter query,
marginally slower for the longer one. I think this may be because we
can return the full hash $r->args whereas we need to map over
$apr->param to get a hash (so param gets called three times for the
short query, 27 times for the larger one). still, much closer numbers
than the former test...
- mark
package ParamsTest;
use strict;
use Apache;
use Apache::Constants qw( OK );
use Apache::Request;
sub handler {
my $r = Apache::Request->new( shift );
$r->send_http_header( 'text/plain' );
my %args = map { $_ => $r->param( $_ ) } $r->param();
$r->print( join( "\n",
map { join( '',
$_ , ' => ' , $args{$_}
) }
keys %args
)
);
return OK;
}
1;
package ArgsTest;
use strict;
use Apache;
use Apache::Constants qw( OK );
sub handler {
my $r = shift;
$r->send_http_header( 'text/plain' );
my %args = $r->args();
$r->print( join( "\n",
map { join( '',
$_ , ' => ' , $args{$_}
) }
keys %args
)
);
return OK;
}
1;
Document Path: /test/params?a=eeeeeeeeee&b=eeeeeeeeee
Document Length: 31 bytes
Concurrency Level: 50
Time taken for tests: 3.317 seconds
Complete requests: 5000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 883520 bytes
HTML transferred: 155620 bytes
Requests per second: 1507.39 [#/sec] (mean)
Time per request: 33.17 [ms] (mean)
Time per request: 0.66 [ms] (mean, across all concurrent requests)
Transfer rate: 266.36 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 1.9 5 16
Processing: 14 27 4.6 27 50
Waiting: 9 27 4.7 27 49
Total: 14 32 3.7 32 54
Document Path: /test/args?a=eeeeeeeeee&b=eeeeeeeeee
Document Length: 31 bytes
Concurrency Level: 50
Time taken for tests: 3.377 seconds
Complete requests: 5000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 883168 bytes
HTML transferred: 155558 bytes
Requests per second: 1480.60 [#/sec] (mean)
Time per request: 33.77 [ms] (mean)
Time per request: 0.68 [ms] (mean, across all concurrent requests)
Transfer rate: 261.52 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 1.8 5 18
Processing: 12 27 4.5 28 63
Waiting: 8 27 4.5 27 63
Total: 12 32 3.7 32 65
Document Path:
/test/params?a=eeeeeeeeee&b=eeeeeeeeee&c=eeeeeeeeee&d=eeeeeeeeee&e=eeeeeeeeee&f=eeeeeeeeee&g=eeeeeeeeee&h=eeeeeeeeee&i=eeeeeeeeee&j=eeeeeeeeee&k=eeeeeeeeee&l=eeeeeeeeee&m=eeeeeeeeee&n=eeeeeeeeee&o=eeeeeeeeee&p=eeeeeeeeee&q=eeeeeeeeee&r=eeeeeeeeee&s=eeeeeeeeee&t=eeeeeeeeee&u=eeeeeeeeee&v=eeeeeeeeee&w=eeeeeeeeee&x=eeeeeeeeee&y=eeeeeeeeee&z=eeeeeeeeee
Document Length: 415 bytes
Concurrency Level: 50
Time taken for tests: 4.531 seconds
Complete requests: 5000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 2810640 bytes
HTML transferred: 2082885 bytes
Requests per second: 1103.51 [#/sec] (mean)
Time per request: 45.31 [ms] (mean)
Time per request: 0.91 [ms] (mean, across all concurrent requests)
Transfer rate: 620.31 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 7 2.9 6 22
Processing: 18 37 11.2 36 496
Waiting: 12 36 11.1 36 495
Total: 18 44 10.8 43 501
Document Path:
/test/args?a=eeeeeeeeee&b=eeeeeeeeee&c=eeeeeeeeee&d=eeeeeeeeee&e=eeeeeeeeee&f=eeeeeeeeee&g=eeeeeeeeee&h=eeeeeeeeee&i=eeeeeeeeee&j=eeeeeeeeee&k=eeeeeeeeee&l=eeeeeeeeee&m=eeeeeeeeee&n=eeeeeeeeee&o=eeeeeeeeee&p=eeeeeeeeee&q=eeeeeeeeee&r=eeeeeeeeee&s=eeeeeeeeee&t=eeeeeeeeee&u=eeeeeeeeee&v=eeeeeeeeee&w=eeeeeeeeee&x=eeeeeeeeee&y=eeeeeeeeee&z=eeeeeeeeee
Document Length: 415 bytes
Concurrency Level: 50
Time taken for tests: 4.381 seconds
Complete requests: 5000
Failed requests: 0
Broken pipe errors: 0
Total transferred: 2808960 bytes
HTML transferred: 2081640 bytes
Requests per second: 1141.29 [#/sec] (mean)
Time per request: 43.81 [ms] (mean)
Time per request: 0.88 [ms] (mean, across all concurrent requests)
Transfer rate: 641.17 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 7 3.0 7 35
Processing: 13 36 6.5 35 86
Waiting: 8 35 6.5 35 86
Total: 13 42 5.6 42 90
Stas Bekman wrote:
> Joe Schaefer wrote:
>> Right- param() was rewritten as XS about 6-8 months ago; since then
>> I've benchmarked it a few times and found param() to be a bit faster than
>> args(). We'll be releasing a 1.0 version of libapreq as soon as Jim
>> approves of the current CVS version. Here's what I got using it on
>> your benchmark (some differences: the tests were run against localhost
>> running perl 5.00503 + mod_perl 1.26 + apache 1.3.22 and using Perl
>> handlers instead of Apache::RegistryLoader scripts):
>
> Great! Now we have an even broader benchmark. Please tell me when 1.0 is
> released (in case I get carried away with other things and don't notice
> the announce) and I'll make sure to update my benchmarking package,
> re-run the benchmarks and correct the results in the guide.
>
> Thanks Joe!
Re: Apache::args vs Apache::Request speed
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
> Stas Bekman <st...@stason.org> writes:
>
>
>>Well, I've run the benchmark and it wasn't the case. Did it change
>>recently? Or do you think that the benchmark is not fair?
>>
>>we are talking about this item
>>http://perl.apache.org/guide/performance.html#Apache_args_vs_Apache_Request
>>
>
> Right- param() was rewritten as XS about 6-8 months ago; since then
> I've benchmarked it a few times and found param() to be a bit faster than
> args(). We'll be releasing a 1.0 version of libapreq as soon as Jim
> approves of the current CVS version. Here's what I got using it on
> your benchmark (some differences: the tests were run against localhost
> running perl 5.00503 + mod_perl 1.26 + apache 1.3.22 and using Perl
> handlers instead of Apache::RegistryLoader scripts):
Great! Now we have an even broader benchmark. Please tell me when 1.0 is
released (in case I get carried away with other things and don't notice
the announce) and I'll make sure to update my benchmarking package,
re-run the benchmarks and correct the results in the guide.
Thanks Joe!
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: Apache::args vs Apache::Request speed
Posted by John Siracusa <si...@mindspring.com>.
On 1/27/02 3:34 PM, Joe Schaefer wrote:
> param() was rewritten as XS about 6-8 months ago; since then I've benchmarked
> it a few times and found param() to be a bit faster than args(). We'll be
> releasing a 1.0 version of libapreq as soon as Jim approves of the current CVS
> version.
Did I just read that there's a new version of libapreq coming? If so, will
it:
a) eliminate the current confusion between
J/JI/JIMW/libapreq-0.33.tar.gz
and
D/DO/DOUGM/libapreq-0.31.tar.gz
by creating a unified libapreq distribution with a version number greater
than both of the above, and
b) actually work in Mac OS X (please please please!)
(See: http://archive.develooper.com/macosx@perl.org/msg01124.html)
-John
Re: Apache::args vs Apache::Request speed
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> Well, I've run the benchmark and it wasn't the case. Did it change
> recently? Or do you think that the benchmark is not fair?
>
> we are talking about this item
> http://perl.apache.org/guide/performance.html#Apache_args_vs_Apache_Request
Right- param() was rewritten as XS about 6-8 months ago; since then
I've benchmarked it a few times and found param() to be a bit faster than
args(). We'll be releasing a 1.0 version of libapreq as soon as Jim
approves of the current CVS version. Here's what I got using it on
your benchmark (some differences: the tests were run against localhost
running perl 5.00503 + mod_perl 1.26 + apache 1.3.22 and using Perl
handlers instead of Apache::RegistryLoader scripts):
Stas's strings:
my $query = [
join("&", map {"$_=".'e' x 10} ('a'..'b')),
join("&", map {"$_=".'e' x 10} ('a'..'z')),
];
Joe's strings:
%Q = qw/ one alpha two beta three gamma four delta /;
my $query = [
join("&", map "$_=$Q{$_}", keys %Q),
join("&", map "$_=".escape($_), %Q),
];
Stas's Query Joe's Query
short long short long
table 124 91 119 112
args 125 93 116 110
do 124 103 121 118
param 132 106 128 123
noparse 138 136 133 131
REQUESTS PER SECOND
Here I used ab with concurrency = 1 to avoid "complications",
but that shouldn't make a difference if we're talking subroutine
performance. The real disappointment here is handler_table,
which would be the fastest if perl's tied hash implementation
didn't suck so badly. IMO perl's performance for tied-variable
access is shameful, but apparently the problem is unfixable in
perl5.
HANDLERS:
sub handler_args {
my $r = shift;
my %args = $r->args;
$r->send_http_header('text/plain');
print join "\n", %args;
}
sub handler_table {
my $r = Apache::Request->new(shift);
my %args = %{ $r->param };
$r->send_http_header('text/plain');
print join "\n", %$args;
}
sub handler_do {
my $r = Apache::Request->new(shift);
my args; $r->param->do( sub {$args{$_[0]}=$_[1];1} );
$r->send_http_header('text/plain');
print join "\n", %$args;
}
sub handler_param {
my $r = Apache::Request->new(shift);
my %args = map +( $_ => $r->param($_) ), $r->param;
$r->send_http_header('text/plain');
print join "\n", %args;
}
sub handler_noparse {
my $r = shift;
$r->send_http_header('text/plain');
print "OK";
}
--
Joe Schaefer
Apache::args vs Apache::Request speed
Posted by Stas Bekman <st...@stason.org>.
Joe Schaefer wrote:
>>mod_perl specific examples from the guide/book ($r->args vs
>>Apache::Request::param, etc)
>>
>
> Well, I've complained about that one before, and since the
> guide's text hasn't changed yet I'll try saying it again:
>
> Apache::Request::param() is FASTER THAN Apache::args(),
> and unless someone wants to rewrite args() IN C, it is
> likely to remain that way. PERIOD.
>
> Of course, if you are satisfied using Apache::args, than it would
> be silly to change "styles".
Well, I've run the benchmark and it wasn't the case. Did it change
recently? Or do you think that the benchmark is not fair?
we are talking about this item
http://perl.apache.org/guide/performance.html#Apache_args_vs_Apache_Request
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: performance coding project? (was: Re: When to cache)
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Stas Bekman <st...@stason.org> writes:
> I even have a name for the project: Speedy Code Habits :)
>
> The point is that I want to develop a coding style which tries hard to
> do early premature optimizations.
I disagree with the POV you seem to be taking wrt "write-time"
optimizations. IMO, there are precious few situations where
writing Perl in some prescribed style will lead to the fastest code.
What's best for one code segment is often a mediocre (or even stupid)
choice for another. And there's often no a-priori way to predict this
without being intimate with many dirty aspects of perl's innards.
I'm not at all against divining some abstract _principles_ for
"accelerating" a given solution to a problem, but trying to develop a
"Speedy Style" is IMO folly. My best and most universal advice would
be to learn XS (or better Inline) and use a language that was _designed_
for writing finely-tuned sections of code. But that's in the
post-working-prototype stage, *not* before.
[...]
> mod_perl specific examples from the guide/book ($r->args vs
> Apache::Request::param, etc)
Well, I've complained about that one before, and since the
guide's text hasn't changed yet I'll try saying it again:
Apache::Request::param() is FASTER THAN Apache::args(),
and unless someone wants to rewrite args() IN C, it is
likely to remain that way. PERIOD.
Of course, if you are satisfied using Apache::args, than it would
be silly to change "styles".
YMMV
--
Joe Schaefer
Re: performance coding project? (was: Re: When to cache)
Posted by Rob Nagler <na...@bivio.biz>.
> This project's idea is to give stright numbers for some definitely bad
> coding practices (e.g. map() in the void context), and things which vary
> a lot depending on the context, but are interesting to think about (e.g.
> the last example of caching the result of ref() or a method call)
I think this would be handy. I spend a fair bit of time
wondering/testing myself. Would be nice to have a repository of the
tradeoffs.
OTOH, I spend too much time mulling over unimportant performance
optimizations. The foreach/map comparison is a good example of this.
It only starts to matter (read milliseconds) at the +100KB and up
range, I find. If a site is returning 100KB pages for typical
responses, it has a problem at a completely different level than map
vs foreach.
Rob
"Pre-optimization is the root of all evil" -- C.A.R. Hoare
Re: performance coding project? (was: Re: When to cache)
Posted by Stas Bekman <st...@stason.org>.
Issac Goldstand wrote:
> Ah yes, but don't forget that to get this speed, you are sacrificing
> memory. You now have another locally scoped variable for perl to keep
> track of, which increases memory usage and general overhead (allocation
> and garbage collection). Now, those, too, are insignificant with one
> use, but the significance will probably rise with the speed gain as you
> use these techniques more often...
Yes, I know. But from the benchmark you can probably have an idea
whether the 'caching' is worth the speedup (given that the benchmark is
similar to your case). For example it depends on how many times you need
to use the cache. And how big is the value. e.g. may be caching
$foo->bar doesn't worth it, but what about $foo->bar->baz? or if you
have a deeply nested hash and you need to work with only a part of
subtree, do you grab a reference to this sub-tree node and work it or do
you keep on dereferencing all the way up to the root on every call?
But personally I still didn't decide which one is better and every time
I'm in a similar situation, I'm never sure which way to take, to cache
or not to cache. But that's the cool thing about Perl, it keeps you on
your toes all the time (if you want to :).
BTW, if somebody has interesting reasonings for using one technique
versus the other performance-wise (speed+memory), please share them.
This project's idea is to give stright numbers for some definitely bad
coding practices (e.g. map() in the void context), and things which vary
a lot depending on the context, but are interesting to think about (e.g.
the last example of caching the result of ref() or a method call)
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: performance coding project? (was: Re: When to cache)
Posted by Issac Goldstand <ma...@beamartyr.net>.
Ah yes, but don't forget that to get this speed, you are sacrificing
memory. You now have another locally scoped variable for perl to keep
track of, which increases memory usage and general overhead (allocation
and garbage collection). Now, those, too, are insignificant with one
use, but the significance will probably rise with the speed gain as you
use these techniques more often...
Issac
Stas Bekman wrote:
> Rob Nagler wrote:
>
>> Perrin Harkins writes:
>
>
>> Here's a fun example of a design flaw. It is a performance test sent
>> to another list. The author happened to work for one of our
>> competitors. :-)
>>
>>
>> That may well be the problem. Building giant strings using .= can be
>> incredibly slow; Perl has to reallocate and copy the string for each
>> append operation. Performance would likely improve in most
>> situations if an array were used as a buffer, instead. Push new
>> strings onto the array instead of appending them to a string.
>>
>> #!/usr/bin/perl -w
>> ### Append.bench ###
>>
>> use Benchmark;
>>
>> sub R () { 50 }
>> sub Q () { 100 }
>> @array = (" " x R) x Q;
>>
>> sub Append {
>> my $str = "";
>> map { $str .= $_ } @array;
>> }
>>
>> sub Push {
>> my @temp;
>> map { push @temp, $_ } @array;
>> my $str = join "", @temp;
>> }
>>
>> timethese($ARGV[0],
>> { append => \&Append,
>> push => \&Push });
>> <<
>>
>> Such a simple piece of code, yet the conclusion is incorrect. The
>> problem is in the use of map instead of foreach for the performance
>> test iterations. The result of Append is an array of whose length is
>> Q and whose elements grow from R to R * Q. Change the map to a
>> foreach and you'll see that push/join is much slower than .=.
>>
>> Return a string reference from Append. It saves a copy.
>> If this is "the page", you'll see a significant improvement in
>> performance.
>>
>> Interestingly, this couldn't be "the problem", because the hypothesis
>> is incorrect. The incorrect test just validated something that was
>> faulty to begin with. This brings up "you can't talk about it unless
>> you can measure it". Use a profiler on the actual code. Add
>> performance stats in your code. For example, we encapsulate all DBI
>> accesses and accumulate the time spent in DBI on any request. We also
>> track the time we spend processing the entire request.
>
>
> While we are at this topic, I want to suggest a new project. I was
> planning to start working on it long time ago, but other things always
> took over.
>
> The perl.apache.org/guide/performance.html and a whole bunch of
> performance chaptes in the upcoming modperl book have a lot of
> benchmarks, comparing various coding techniques. Such as the example
> you've provided. The benchmarks are doing both pure Perl and mod_perl
> specific code (which requires running Apache, a perfect job for the
> new Apache::Test framework.)
>
> Now throw in the various techniques from 'Effective Perl' book and
> voila you have a great project to learn from.
>
> Also remember that on varous platforms and various Perl versions the
> benchmark results will differ, sometimes very significantly.
>
> I even have a name for the project: Speedy Code Habits :)
>
> The point is that I want to develop a coding style which tries hard to
> do early premature optimizations. Let me give you an example of what I
> mean. Tell me what's faster:
>
> if (ref $b eq 'ARRAY'){
> $a = 1;
> }
> elsif (ref $b eq 'HASH'){
> $a = 1;
> }
>
> or:
>
> my $ref = ref $b;
> if ($ref eq 'ARRAY'){
> $a = 1;
> }
> elsif ($ref eq 'HASH'){
> $a = 1;
> }
>
> Sure, the win can be very little, but it ads up as your code base's
> size grows.
>
> Give you a similar example:
>
> if ($a->lookup eq 'ARRAY'){
> $a = 1;
> }
> elsif ($a->lookup eq 'HASH'){
> $a = 1;
> }
>
> or
>
> my $lookup = $a->lookup;
> if ($lookup eq 'ARRAY'){
> $a = 1;
> }
> elsif ($lookup eq 'HASH'){
> $a = 1;
> }
>
> now throw in sub attributes and re-run the test again.
>
> add examples of map vs for.
> add examples of method lookup vs. procedures
> add examples of concat vs. list vs. other stuff from the guide.
>
> mod_perl specific examples from the guide/book ($r->args vs
> Apache::Request::param, etc)
>
> If you understand where I try to take you, help me to pull this
> project off and I think in a long run we can benefit a lot.
>
> This goes along with the Apache::Benchmark project I think (which is
> yet another thing I want to start...), probably could have these two
> ideas put together.
>
> _____________________________________________________________________
Re: performance coding project? (was: Re: When to cache)
Posted by raptor <ra...@unacs.bg>.
One memory & speed saving is using global VARS, I know it is not
recomended practice, but if from the begining of the project u set a
convention what are the names of global vars it is ok..F.e. I'm using in
all DB pages at the begining :
our $dbh = dbConnect() or dbiError();
See I know (i'm sure) that when I use DB I will always initialize the
var. One other example is (ASP.pm):
our $userID = $$Session{userID};
my $something = $$Request{Params}{something}
This is not saving me memory, but shorten my typewriting especialy if it
is used frequently or if I need to change FORM-param from "something" to
"anything"..etc..
I think in mod_perl world we are about to search MEMORY optimisation
RATHER speed optimisation... :")
raptor
raptor@unacs.bg
Re: performance coding project? (was: Re: When to cache)
Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
> Back to your idea: you're obviously interested in the low-level
> optimization stuff, so of course you should go ahead with it. I don't
> think it needs to be a separate project, but improvements to the
> performance section of the guide are always a good idea.
It has to be a run-able code, so people can verify the facts which may
change with different OS/versions of Perl. e.g. Joe says that $r->args
is slower then Apache::Request->param, I saw the opposite. Having these
as a run-able bits, is much nicer.
> I know that I
> have taken all of the DBI performance tips to heart and found them very
> useful.
:)
That's mostly JWB's work I think.
> I'm more interested in writing about higher level performance issues
> (efficient shared data, config tuning, caching), so I'll continue to
> work on those things. I'm submitting a proposal for a talk on data
> sharing techniques at this year's Perl Conference, so hopefully I can
> contribute that to the guide after I finish it.
Go Perrin!
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: performance coding project? (was: Re: When to cache)
Posted by Ask Bjoern Hansen <as...@valueclick.com>.
On Sat, 26 Jan 2002, Perrin Harkins wrote:
> > It all depends on what kind of application do you have. If you code is
> > CPU-bound these seemingly insignificant optimizations can have a very
> > significant influence on the overall service performance.
>
> Do such beasts really exist? I mean, I guess they must, but I've never
> seen a mod_perl application that was CPU-bound. They always seem to be
> constrained by database speed and memory.
At ValueClick we only have a few BerkeleyDBs that are in the
"request loop" for 99% of the traffic; everything else is in fairly
efficient in-memory data structures.
So there we do of course care about the tiny small optimiziations
because there's a direct correlation between saved CPU cycles and
request capacity.
However, it's only that way because we made a good design for the
application in the first place. :-) (And for all the other code we
rarely care about using a few more CPU cycles if it is
easier/cleaner/more flexible/comes to mind first). Who cares if the
perl code gets ready to wait for the database a few milliseconds
faster? :-)
- ask
--
ask bjoern hansen, http://ask.netcetera.dk/ !try; do();
more than a billion impressions per week, http://valueclick.com
Re: performance coding project? (was: Re: When to cache)
Posted by Ed Grimm <ed...@tgape.org>.
On Sat, 26 Jan 2002, Perrin Harkins wrote:
>> It all depends on what kind of application do you have. If you code
>> is CPU-bound these seemingly insignificant optimizations can have a
>> very significant influence on the overall service performance.
>
> Do such beasts really exist? I mean, I guess they must, but I've
> never seen a mod_perl application that was CPU-bound. They always
> seem to be constrained by database speed and memory.
I've seen one. However, it was much like a normal performance problem -
the issue was with one loop which ran one line which was quite
pathological. Replacing loop with an s///eg construct eliminated the
problem; there was no need for seemlingly insignificant optimizations.
(Actually, the problem was *created* by premature optimization - the
coder had utilized code that was more efficient than s/// in one special
case, to handle a vastly different instance.)
However, there could conceivably be code which was more of a performance
issue, especially when the mod_perl utilizes a very successful cache on
a high traffic site.
>> On the other hand how often do you get a chance to profile your code
>> and see how to improve its speed in the real world. Managers never
>> plan for debugging period, not talking about optimizations periods.
Unless there's already a problem, and you have a good manager. We've
had a couple of instances where we were given time (on the schedule,
before the release) to improve speed after a release. It's quite rare,
though, and I've never seen it for a mod_perl project.
Ed
Re: performance coding project? (was: Re: When to cache)
Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi all,
Stas has a point. Perl makes it very easy to do silly things.
This is what I was doing last week:
if( m/\b$Needle\b/ ) {...}
Eight hours. (Silly:)
if( index($Haystack,$Needle) && m/\b$Needle\b/ ) {...}
Twelve minutes.
73,
Ged.
Re: performance coding project? (was: Re: When to cache)
Posted by Milo Hyson <mi...@cyberlifelabs.com>.
On Saturday 26 January 2002 03:40 pm, Sam Tregar wrote:
> Think search engines. Once you've figured out how to get your search
> database to fit in memory (or devised a cachin strategy to get the
> important parts there) you're essentially looking at a CPU-bound problem.
> These days the best solution is probably some judicious use of Inline::C.
> Back when I last tackled the problem I had to hike up mount XS to find my
> grail...
I agree. There are some situations that are just too complex for a DBMS to
handle directly, at least in any sort of efficient fashion. However,
depending on the load in those cases, Perrin's solution for eToys is probably
a good approach (i.e. custom search software written in C/C++).
--
Milo Hyson
CyberLife Labs, LLC
Re: performance coding project? (was: Re: When to cache)
Posted by Sam Tregar <sa...@tregar.com>.
On Sat, 26 Jan 2002, Perrin Harkins wrote:
> > It all depends on what kind of application do you have. If you code is
> > CPU-bound these seemingly insignificant optimizations can have a very
> > significant influence on the overall service performance.
>
> Do such beasts really exist? I mean, I guess they must, but I've never
> seen a mod_perl application that was CPU-bound. They always seem to be
> constrained by database speed and memory.
Think search engines. Once you've figured out how to get your search
database to fit in memory (or devised a cachin strategy to get the
important parts there) you're essentially looking at a CPU-bound problem.
These days the best solution is probably some judicious use of Inline::C.
Back when I last tackled the problem I had to hike up mount XS to find my
grail...
-sam
Re: performance coding project? (was: Re: When to cache)
Posted by Perrin Harkins <pe...@elem.com>.
> It all depends on what kind of application do you have. If you code is
> CPU-bound these seemingly insignificant optimizations can have a very
> significant influence on the overall service performance.
Do such beasts really exist? I mean, I guess they must, but I've never
seen a mod_perl application that was CPU-bound. They always seem to be
constrained by database speed and memory.
> On the other hand how often do you get a chance to profile your code
and
> see how to improve its speed in the real world. Managers never plan
> for debugging period, not talking about optimizations periods.
If you plan a good architecture that avoids the truly slow stuff
(disk/network access) as much as possible, your application is usually
fast enough without spending much time on optimization (except maybe
some database tuning). At my last couple of jobs we actually did have
load testing and optimization as part of the development plan, but
that's because we knew we'd be getting pretty high levels of traffic.
Most people don't need to tune very much if they have a good
architecture, and it's enough for them to fix problems as they become
visible.
Back to your idea: you're obviously interested in the low-level
optimization stuff, so of course you should go ahead with it. I don't
think it needs to be a separate project, but improvements to the
performance section of the guide are always a good idea. I know that I
have taken all of the DBI performance tips to heart and found them very
useful.
I'm more interested in writing about higher level performance issues
(efficient shared data, config tuning, caching), so I'll continue to
work on those things. I'm submitting a proposal for a talk on data
sharing techniques at this year's Perl Conference, so hopefully I can
contribute that to the guide after I finish it.
- Perrin
Re: performance coding project? (was: Re: When to cache)
Posted by Ask Bjoern Hansen <as...@valueclick.com>.
On Sat, 26 Jan 2002, Stas Bekman wrote:
[...]
> > It's much better to build your system, profile it, and fix the bottlenecks.
> > The most effective changes are almost never simple coding changes like the
> > one you showed, but rather large things like using qmail-inject instead of
> > SMTP, caching a slow database query or method call, or changing your
> > architecture to reduce the number of network accesses or inter-process
> > communications.
>
> It all depends on what kind of application do you have. If you code is
> CPU-bound these seemingly insignificant optimizations can have a very
> significant influence on the overall service performance. Of course if
> you app, is IO-bound or depends with some external component, than your
> argumentation applies.
Eh, any real system will be a combination. Sure; when everything
works then it's worth finding the CPU intensive places and fix them
up, but for the most part the system design is far far more
important than any "code optimiziation" you can ever do.
My usual rhetorics: Your average code optimization will gain you at
most a few percent performance gain. A better design can often make
things 10 times faster and use only a fraction of your memory.
> On the other hand how often do you get a chance to profile your code and
> see how to improve its speed in the real world. Managers never plan
> for debugging period, not talking about optimizations periods. And while
> premature optimizations are usually evil, as they will bait you later,
> knowing the differences between coding styles does help in a long run
> and I don't consider these as premature optimizations.
If you don't waste time profiling every little snippet of code you
might have more time to fix the real bottlenecks in the end. ;-)
[...]
> All I want to say is that there is no one-fits-all solution in Perl,
> because of TIMTOWTDI, so you can learn a lot from running benchmarks and
> picking your favorite coding style and change it as the language
> evolves. But you shouldn't blindly apply the outcomes of the benchmarks
> without running your own benchmarks.
Amen.
(And don't get me wrong; I think a repository of information about
the nitty gritty optimization things would be great - I just find it
to be bad advice to not tell people to do the proper design first).
- ask
--
ask bjoern hansen, http://ask.netcetera.dk/ !try; do();
more than a billion impressions per week, http://valueclick.com
Re: performance coding project? (was: Re: When to cache)
Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
>>The point is that I want to develop a coding style which tries hard to
>>do early premature optimizations.
>>
>
> We've talked about this kind of thing before. My opinion is still the same
> as it was: low-level speed optimization before you have a working system is
> a waste of your time.
>
> It's much better to build your system, profile it, and fix the bottlenecks.
> The most effective changes are almost never simple coding changes like the
> one you showed, but rather large things like using qmail-inject instead of
> SMTP, caching a slow database query or method call, or changing your
> architecture to reduce the number of network accesses or inter-process
> communications.
It all depends on what kind of application do you have. If you code is
CPU-bound these seemingly insignificant optimizations can have a very
significant influence on the overall service performance. Of course if
you app, is IO-bound or depends with some external component, than your
argumentation applies.
On the other hand how often do you get a chance to profile your code and
see how to improve its speed in the real world. Managers never plan
for debugging period, not talking about optimizations periods. And while
premature optimizations are usually evil, as they will bait you later,
knowing the differences between coding styles does help in a long run
and I don't consider these as premature optimizations.
Definitely this discussion has no end. Everybody is right in their
particular project, since there are no two projects which are the same.
All I want to say is that there is no one-fits-all solution in Perl,
because of TIMTOWTDI, so you can learn a lot from running benchmarks and
picking your favorite coding style and change it as the language
evolves. But you shouldn't blindly apply the outcomes of the benchmarks
without running your own benchmarks.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: performance coding project? (was: Re: When to cache)
Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
On Fri, 25 Jan 2002 21:15:54 +0000 (GMT)
Matt Sergeant <ma...@sergeant.org> wrote:
>
> With qmail, SMTP generally uses inetd, which is slow, or daemontools,
> which is faster, but still slow, and more importantly, it anyway goes:
>
> perl -> SMTP -> inetd -> qmail-smtpd -> qmail-inject.
>
> So with going direct to qmail-inject, your email skips out a boat load of
> processing and goes direct into the queue.
>
> Of course none of this is relevant if you're not using qmail ;-)
Yet another solution:
use Mail::QmailQueue, directly
http://search.cpan.org/search?dist=Mail-QmailQueue
--
Tatsuhiko Miyagawa <mi...@bulknews.net>
Re: performance coding project? (was: Re: When to cache)
Posted by David Wheeler <da...@wheeler.net>.
On Fri, 2002-01-25 at 13:15, Matt Sergeant wrote:
> With qmail, SMTP generally uses inetd, which is slow, or daemontools,
> which is faster, but still slow, and more importantly, it anyway goes:
>
> perl -> SMTP -> inetd -> qmail-smtpd -> qmail-inject.
>
> So with going direct to qmail-inject, your email skips out a boat load of
> processing and goes direct into the queue.
Okay, that makes sense. In my activitymail CVS script I just used
sendmail.
http://www.cpan.org/authors/id/D/DW/DWHEELER/activitymail-0.987
But it looks like this might be more efficient, if qmail happens to be
installed (not sure on SourceForge's servers).
> Of course none of this is relevant if you're not using qmail ;-)
Yes, and in Bricolage, I used Net::SMTP to keep it as
platform-independent as possible. It should work on Windows, even!
Besides, all mail gets sent during the Apache cleanup phase, so there
should be no noticeable delay for users.
David
--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
Yahoo!: dew7e
Jabber: Theory@jabber.org
Re: performance coding project? (was: Re: When to cache)
Posted by Matt Sergeant <ma...@sergeant.org>.
On 25 Jan 2002, David Wheeler wrote:
> On Fri, 2002-01-25 at 09:08, Perrin Harkins wrote:
>
> <snip />
>
> > It's much better to build your system, profile it, and fix the bottlenecks.
> > The most effective changes are almost never simple coding changes like the
> > one you showed, but rather large things like using qmail-inject instead of
> > SMTP, caching a slow database query or method call, or changing your
> > architecture to reduce the number of network accesses or inter-process
> > communications.
>
> qmail-inject? I've just been using sendmail or, preferentially,
> Net::SMTP. Isn't using a system call more expensive? If not, how does
> qmail-inject work?
With qmail, SMTP generally uses inetd, which is slow, or daemontools,
which is faster, but still slow, and more importantly, it anyway goes:
perl -> SMTP -> inetd -> qmail-smtpd -> qmail-inject.
So with going direct to qmail-inject, your email skips out a boat load of
processing and goes direct into the queue.
Of course none of this is relevant if you're not using qmail ;-)
--
<!-- Matt -->
<:->Get a smart net</:->
Re: performance coding project? (was: Re: When to cache)
Posted by David Wheeler <da...@wheeler.net>.
On Fri, 2002-01-25 at 09:08, Perrin Harkins wrote:
<snip />
> It's much better to build your system, profile it, and fix the bottlenecks.
> The most effective changes are almost never simple coding changes like the
> one you showed, but rather large things like using qmail-inject instead of
> SMTP, caching a slow database query or method call, or changing your
> architecture to reduce the number of network accesses or inter-process
> communications.
qmail-inject? I've just been using sendmail or, preferentially,
Net::SMTP. Isn't using a system call more expensive? If not, how does
qmail-inject work?
Thanks,
David
--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
Yahoo!: dew7e
Jabber: Theory@jabber.org
Re: performance coding project? (was: Re: When to cache)
Posted by Perrin Harkins <pe...@elem.com>.
> The point is that I want to develop a coding style which tries hard to
> do early premature optimizations.
We've talked about this kind of thing before. My opinion is still the same
as it was: low-level speed optimization before you have a working system is
a waste of your time.
It's much better to build your system, profile it, and fix the bottlenecks.
The most effective changes are almost never simple coding changes like the
one you showed, but rather large things like using qmail-inject instead of
SMTP, caching a slow database query or method call, or changing your
architecture to reduce the number of network accesses or inter-process
communications.
The exception to this rule is that I do advocate thinking about memory usage
from the beginning. There are no good tools for profiling memory used by
Perl, so you can't easily find the offenders later on. Being careful about
passing references, slurping files, etc. pays off in better scalability
later.
- Perrin