Re: [aliasing] Using mod_perl handlers for max speed?
Heh - you're on the wrong track. The whole quote below is part of a double-quoted string, and each backslash is just to put a literal $ into the code. It will be eval'ed later. [EMAIL PROTECTED] (raptor) wrote: !!! Is it possible to have reference on the left side of the equation !!! I've tried this to alias HASH :) but didn't succeeded... sub { my \$hash = shift; # $_[0] is \%myhash }; Yes I know that there is aliasing : my *hash = \%{$hashref}.. And I see that here u use : \$r-blah Never mind it is cute construct anyway. Do U have any benefit in speed using it in this way ?! PS. didn't u think that there must finaly alias keyword in perl = iVAN [EMAIL PROTECTED] = Files ~ (hello\.bench) Perl # ModPerl Handler package Apache::bench; sub handler { my(\$r) = shift; \$r-content_type('text/html'); \$r-send_http_header(); \$r-print('Hello '); \$r-print('World'); 200; } 1; /Perl SetHandler perl-script PerlHandler Apache::bench /Files ------ Ken Williams Last Bastion of Euclidity [EMAIL PROTECTED]The Math Forum
Re: Using mod_perl handlers for max speed?
On Wed, 11 Jul 2001, Philip Mak wrote: In the recent Hello World 2000 benchmark posted by Joshua Chamas, mod_perl handler was shown to be even faster than static HTML (at least for running hello world), and twice as fast as using Apache::Registry to run a perl script. I honestly think something is up there. The code that mod_perl goes through before executing the actual perl script is a lot slower than the code the static HTML (http_core) handler goes through. FWIW, In AxKit 1.4_80 on axkit.org (beta, has bugs), I've implemented something I call a mod_perl fast handler, which skips most of the stuff in mod_perl, allowing you to go: AddHandler axkit .xml in your httpd.conf, and it works much the same way as SetHandler/PerlHandler does, except faster. Obviously though you lose the benefit of being able to write handlers for the different handler phases with this method. And it requires XS code. Does this mean that if there's a heavily used script on my system that needs to be VERY fast, then it may be worth making it into a mod_perl handler? What are the caveats of using mod_perl handlers instead of normal scripts? Using handlers is better. Hands down. :-) Personally I just find handlers more logical than CGI scripts. They have a known entry point, which I think makes life a hell of a lot easier in structuring complex code. Rather than the entry point being the top of your script. There's a beginners article on take23 about writing your first handler module. -- Matt/ /||** Founder and CTO ** ** http://axkit.com/ ** //||** AxKit.com Ltd ** ** XML Application Serving ** // ||** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** mod_perl news and resources: http://take23.org ** \\// //\\ // \\
Re: [aliasing] Using mod_perl handlers for max speed?
!!! Is it possible to have reference on the left side of the equation !!! I've tried this to alias HASH :) but didn't succeeded... sub { my \$hash = shift; # $_[0] is \%myhash }; Yes I know that there is aliasing : my *hash = \%{$hashref}.. And I see that here u use : \$r-blah ...Never mind it is cute construct anyway. Do U have any benefit in speed using it in this way ?! PS. didn't u think that there must finaly alias keyword in perl = iVAN [EMAIL PROTECTED] = Files ~ (hello\.bench) Perl # ModPerl Handler package Apache::bench; sub handler { my(\$r) = shift; \$r-content_type('text/html'); \$r-send_http_header(); \$r-print('Hello '); \$r-print('World'); 200; } 1; /Perl SetHandler perl-script PerlHandler Apache::bench /Files
Using mod_perl handlers for max speed?
In the recent Hello World 2000 benchmark posted by Joshua Chamas, mod_perl handler was shown to be even faster than static HTML (at least for running hello world), and twice as fast as using Apache::Registry to run a perl script. Does this mean that if there's a heavily used script on my system that needs to be VERY fast, then it may be worth making it into a mod_perl handler? What are the caveats of using mod_perl handlers instead of normal scripts? For those who didn't see it, here is the code for the Hello World mod_perl handler program. It is inserted into httpd.conf directly. Files ~ (hello\.bench) Perl # ModPerl Handler package Apache::bench; sub handler { my(\$r) = shift; \$r-content_type('text/html'); \$r-send_http_header(); \$r-print('Hello '); \$r-print('World'); 200; } 1; /Perl SetHandler perl-script PerlHandler Apache::bench /Files
Re: Using mod_perl handlers for max speed?
Does this mean that if there's a heavily used script on my system that needs to be VERY fast, then it may be worth making it into a mod_perl handler? Not unless you get astonishing amounts of traffic and your script does almost nothing. These are very simple test cases, so they exaggerate the speed differences. (Intentionally.) However, you should be aware that handlers rock, and many of us consider them more fun than Registry scripts. Registry scripts have their fans as well, of course. What are the caveats of using mod_perl handlers instead of normal scripts? You can read more here: http://perl.apache.org/guide/porting.html#Transitioning_from_Apache_Regis - Perrin
Re: Using mod_perl handlers for max speed?
Philip Mak wrote: In the recent Hello World 2000 benchmark posted by Joshua Chamas, mod_perl handler was shown to be even faster than static HTML (at least for running hello world), and twice as fast as using Apache::Registry to run a perl script. Does this mean that if there's a heavily used script on my system that needs to be VERY fast, then it may be worth making it into a mod_perl handler? What are the caveats of using mod_perl handlers instead of normal scripts? Its hard to explain, but try not to focus on the Hits/sec, instead look at the sec/Hits. Notice that the difference between Registry CGI Raw and mod_perl handler is only ~ .00025 seconds. Test Name Test File Hits/sec Total Hits Total Time sec/Hits Bytes/Hit -- -- -- -- -- -- Apache::Registry v2.01 CGI Raw hello_raw. 669.9 40196 hits 60.00 sec 0.001493 52 bytes mod_perl handlerhello.benc 808.4 48522 hits 60.02 sec 0.001237 197 bytes You could easily use that much time with a half page of perl code for your application depending on what its doing, especially if you are doing some heavy lifting like writing to a file, or talking to a database. Now if all you want to do is send a Location: header, and have apache write to the access_log, then you might want to start rewriting some of your scripts as mod_perl handlers. Here's another way to look at Hits/sec as being bad to focus on. Let's say you have something that is 1000/sec and something that is 2000/sec, that's only .0005 different. Most of the time that .0005 is negligible compared to the time you will spend in the executing part of the application, which lets say is .01 in execution time, now the overall execution time is .0110 and .0105 which is 91/sec vs. 95/sec respectively. So what looked like something to be twice as fast is now only 4% faster. But if you write some little fast code, then it can make all the difference in the world. The reason I like Hello World, is that it lets me know the fastest I can go in that app, but there's no guarantees I'll get there. :) --Josh _ Joshua Chamas Chamas Enterprises Inc. NodeWorks Founder Huntington Beach, CA USA http://www.nodeworks.com1-714-625-4051
Re: Using mod_perl handlers for max speed?
[EMAIL PROTECTED] (Philip Mak) wrote: Does this mean that if there's a heavily used script on my system that needs to be VERY fast, then it may be worth making it into a mod_perl handler? What are the caveats of using mod_perl handlers instead of normal scripts? The basic idea is this: with a handler, you're adding new capabilities to the server itself. With a script (CGI or Registry or otherwise), your functionality becomes a resource outside the server, and the server must check that resource, manage it, and cater to its interface needs. How aggressively the server manages reloading, etc. varies from one scheme to another, but that additional stuff is the reason Registry scripts are usually slower than handlers. ------ Ken Williams Last Bastion of Euclidity [EMAIL PROTECTED]The Math Forum