Re: Log_file behavior in long running apps
| From: | Roman Neuhauser | Date: | Fri, 04 Jul 2003 18:45:22 +0000 |
| Subject: | Re: Log_file behavior in long running apps | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-18011@lists.php.net to get a copy of this message | ||
# jon@php.net / 2003-07-04 13:50:55 -0400:
> On Fri, Jul 04, 2003 at 12:02:01PM +0200, Roman Neuhauser wrote:
>
> > > > What effect will using Log::file in a long running application (non-web
> > > > environment) have on memory usage given that it defers the writing till
> > > > the end of the execution?
> > >
> > > I'm not sure. You'd have to run your own benchmarks.
> >
> > Well, I think we'll agree that it would cause evergrowing memory
> > consupmtion.
> >
> > It also hampers functionality. Imagine any daemon like Apache only
> > writing its logs on shutdown. You wouldn't be able to monitor its
> > activity.
>
> Sure. I believe the current Log_file class was designed for
> short-lived web scripts, where the total output would be reasonable
> and caching it is a performance win.
The current Log_file is Richard Heyes' work committed by you in 1.11
(AFAICT from cvs.php.net). Given that it used to actually call
fwrite() in log() up untill 1.10, this is a regression (what you
said still applies). Now, take this with a grain of salt as I'm your
average PHP hacker, isn't this optimization a matter of (not)
calling fsync(2)? I haven't read the source, and www.php.net/fflush
doesn't mention fsync() at all, so I'm not sure.
Ok, you got me to test it. log.1 is a bit slower than log.2, making
the performance gain negative (I'm using 4.3.2-cli):
// log.1
$msg = "World without heroes is like a world without sun, you can't look up to anyone
without heroes.";
$fd = fopen('/tmp/2.out', 'w');
$msgs = array();
for ($i = 0; $i < 10000; $i++) {
array_push($msgs, $msg);
}
for ($i = 0; $i < 10000; $i++) {
fwrite($fd, $msgs[$i]);
}
fclose($fd);
// log.2
$msg = "World without heroes is like a world without sun, you can't look up to anyone
without heroes.";
$fd = fopen('/tmp/1.out', 'w');
for ($i = 0; $i < 10000; $i++) {
fwrite($fd, $msg);
}
fclose($fd);
It's not so strange when you think about all the stuff what PHP does
to maintain that array.
> > > When I find the time to rewrite the Log_file class, I'll make the
> > > output buffering optional.
> >
> > What are the other changes you want to make?
>
> People have been asking for configurable timestamp and output formats.
Add reverting to fwrite() right in log() to that list, please. :)
--
If you cc me or remove the list(s) completely I'll most likely ignore
your message. see http://www.eyrie.org./~eagle/faqs/questions.html