File operation slower when excuted by mod_perl than when executed in CGI.
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.
File operation slower when excuted by mod_perl than when executed in CGI.
===

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.