I have an application which runs on cgi. I have ported it to mod_perl2 ( using apache2::compat) and rewriting the cgi file into a mod_perl handler. Strangely, the performance I am obtaining due to the mod_perl is over shadowed by the latency in 开发者_如何学编程the logging.
The logging mechanism in the application is like logger->logmsg(msg)
logger::logmsg { my $msg = shift; open LOGFILE, ">>logfile"; print LOGFILE $msg close LOGFILE; }
There is a lot of logging done by the application and is controlled by different levels of logging. When i turn off logging, the transaction work 80% faster on mod_perl than on cgi (code base is same. I am just running using a handler for mod_perl and gateway script for cgi). when i turn on logging application on mod_perl runs 80% slower.
From the logs, I could see that same log module takes .01 seconds for appending msg into file when run as cgi script and .03 seconds when run thro mod_perl handler.
I have tried different methods like using STDOUT and redirecting the same to log file, using request_obj->log method, etc but I can't beat the time taken by cgi. Is there something I am doing wrong with this approach ?
Why is file operation 3 times slower when performed through mod_perl scripts in the same apache server.
Any pointer is highly appreciated.
Thanks.
This was not a problem with the file IO itself. There was a system call (date +%Y%m%d
) to fetch the timestamp which was thrice as slow as it was in cgi. This was having the slowing effect.
However, I am not sure why apche is able to execute the system command thrice as fast when run through cgi rather than modperl.
Sorry for the mis-information in the question.
精彩评论