由 mod_perl 执行时的文件操作比在 CGI 中执行时慢
我有一个在 cgi 上运行的应用程序。我已将其移植到 mod_perl2 (使用 apache2::compat)并将 cgi 文件重写到 mod_perl 处理程序中。奇怪的是,我通过 mod_perl 获得的性能被日志记录中的延迟所掩盖。
应用程序中的日志机制类似于 logger->logmsg(msg)
logger::logmsg { 我的 $msg = 转变; 打开日志文件,“>>日志文件”; 打印日志文件 $msg 关闭日志文件; 。
应用程序完成了大量日志记录,并由不同级别的日志记录控制 当我关闭日志记录时,mod_perl 上的事务处理速度比 cgi 上快 80%(代码库相同。我只是使用 mod_perl 的处理程序和 cgi 的网关脚本运行)。当我在 mod_perl 上打开日志记录应用程序时,运行速度慢了 80%。
从日志中,我可以看到,当作为 cgi 脚本运行时,相同的日志模块需要 0.01 秒将 msg 附加到文件中,而当运行 thro mod_perl 处理程序时,需要 0.03 秒。
我尝试过不同的方法,例如使用 STDOUT 并将其重定向到日志文件、使用 request_obj->log 方法等,但我无法击败 cgi 所花费的时间。我的这种方法有什么问题吗?
为什么在同一 apache 服务器中通过 mod_perl 脚本执行文件操作时速度慢 3 倍?
任何指针都受到高度赞赏。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是文件 IO 本身的问题。有一个系统调用(
date +%Y%m%d
)来获取时间戳,速度比 cgi 中慢三倍。这产生了放缓的效果。但是,我不确定为什么 apche 在通过 cgi 而不是 modperl 运行时能够以三倍的速度执行系统命令。
对于问题中的错误信息表示歉意。
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.