On Wed, 11 Sep 2002, Perrin Harkins wrote: > Pierre Laplante wrote: > > If I compiled a c module that embed a perl interpreter and > > I benchmark this again the same module in mod_perl > > > > I got a big difference in favor of mod_c. > > It will be hard for anyone to give you a good answer unless you post the > code that you benchmarked. At a guess, I would say that mod_perl is > probably doing more work in order to give you access to apache > internals. You also may not have configured mod_perl for best > performance. For example, if you have it configured to emulate CGI by > setting up environment variables that will take more time. > > - Perrin >
I do not use mod_perl with CGI emulation. Here is my mod_perl code: package Apache::modperl; require 5.001; use strict; use Error qw(:try); use Apache::Constants qw(:common); use Apache::File (); BEGIN { use constant REVISION => '$Revision: 1.5 $ '; use constant DEBUG => 0; use constant BANNIERE => 0; use constant LIST => 1; use constant MTIME => 2; use constant ID => '$Id $ '; } sub handler { my $r = shift; try { &main($r) ; } catch Error::Simple with { my $e = shift; my $error = $e -> {'-text'}; $r -> content_type ('text/html'); $r -> send_http_header; print "<b>Error: $error</b>\n"; $r -> log_error("Erreur d'éxécution de " . '$Id: bannieres.pm,v 1.5 2002/09/10 01:15:11 laplante Exp $' . " : $error.\n"); }; return OK; } sub main { my($r)=@_; $r -> content_type ('text/html'); $r -> send_http_header; $r -> print("<HTML>\n"); $r -> print("<HEADER>\n"); $r -> print("<TITLE>Hello There</TITLE>\n"); $r -> print("</HEADER>\n"); $r -> print("<BODY>\n"); $r -> print("<H1>Hello $ENV{'REMOTE_NAME'}</H1>\n"); $r -> print("</BODY>\n"); $r -> print("</HTML>\n"); } Here is my 'C' mode: #include "httpd.h" #include "http_config.h" #include "http_core.h" #include "http_log.h" #include "http_protocol.h" #include "http_request.h" #include "http_main.h" #include "util_script.h" #include "util_md5.h" #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl=NULL; #ifndef DO_CLEAN #define DO_CLEAN 0 #endif extern void xs_init(); module MODULE_VAR_EXPORT hello_module; /* here's the content handler */ static int hello_handler(request_rec *r) { char *hostname; char *embedding[] = { "", "/tmp/persistent.pl" }; char *args[] = { "/tmp/toto.pl", DO_CLEAN, NULL }; int exitstatus; STRLEN n_a; r->content_type = "text/html"; ap_send_http_header(r); hostname = ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME); ap_rputs("<HTML>\n", r); ap_rputs("<HEADER>\n", r); ap_rputs("<TITLE>Hello There V3</TITLE>\n", r); ap_rputs("</HEADER>\n", r); ap_rputs("<BODY>\n", r); if (my_perl == NULL) { ap_rputs("my_perl is null V3\n", r); if((my_perl = perl_alloc()) == NULL) { fprintf(stderr, "no memory!"); exit(1); } perl_construct(my_perl); exitstatus = perl_parse(my_perl, xs_init, 2, embedding, NULL); if (exitstatus) { fprintf(stderr, "There was some errors\n"); } else { fprintf(stderr, "Running perlrun\n"); perl_run(my_perl); } } else { ap_rputs("my_perl is not null\n", r); } ap_rprintf(r, "<H1>Hello %s</H1>\n", hostname); ap_rputs("Who would take this book seriously if the first example didn't\n",r); ap_rprintf(r, "say \"hello \"?\n"); call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args); /* check $@ */ if(SvTRUE(ERRSV)) { fprintf(stderr, "eval error: %s\n", SvPV(ERRSV,n_a)); } ap_rputs("</BODY>\n", r); ap_rputs("</HTML>\n", r); return OK; } static handler_rec hello_handlers[] = { {"hello-handler", hello_handler}, {NULL} }; /* Tell Apache what phases of the transaction we handle */ module MODULE_VAR_EXPORT hello_module = { STANDARD_MODULE_STUFF, NULL, /* module initializer */ NULL, /* per-directory config creator */ NULL, /* dir config merger */ NULL, /* server config creator */ NULL, /* server config merger */ NULL, /* command table */ hello_handlers, /* [7] content handlers */ NULL, /* [2] URI-to-filename translation */ NULL, /* [5] check/validate user_id */ NULL, /* [6] check user_id is valid *here* */ NULL, /* [4] check access by host address */ NULL, /* [7] MIME type checker/setter */ NULL, /* [8] fixups */ NULL, /* [9] logger */ NULL, /* [3] header parser */ NULL, /* process initialization */ NULL, /* process exit/cleanup */ NULL /* [1] post read_request handling */ };