[sf-perl] Log stomping

Bill Moseley moseley at hank.org
Wed Aug 24 06:22:18 PDT 2005

On Tue, Aug 23, 2005 at 02:15:17PM -0700, David Alban wrote:
> I've replicated the "real world" problem into a pair of simple perl
> programs.  "foo" prints a couple lines of data.  "foo-flocking" does
> the same thing, but only after successfully acquiring an exclusive
> flock.

This really sounds more like an OS question, so I'll be guessing from
this point on.  This makes me realize I don't understand shell redirection
very well.

Stdout is buffered by perl -- seems possible that Perl is closing your
lock file before flushing stdout.  That's basically the same thing as
(the commonly done) explicitly unlocking before closing.

Why not flock the log file and write directly to that?

The OS should also buffer, which is why this seem odd to me.  I have
a web application that handles about 3-4 million requests a month and
doesn't use locking at all to write to log file -- the processes just
keep the log file open and do single writes.  The OS seems to buffer
and not collide.

Bill Moseley
moseley at hank.org

More information about the SanFrancisco-pm mailing list