On Mar 24, 2012, at 6:08 PM, Jaka Jančar wrote:

> I'm writing a node.js server that uses the cluster module. Each worker
> does *lots* of logging to a shared log file (it must be just 1 file).
> 
> - Assuming log lines are smaller than PIPE_BUF (4k), is it safe to do
> fs.write() and rely on it being atomic, or does Node.js break this
> promise of write()?
> 
> - What's with "Note that it is unsafe to use fs.write multiple times
> on the same file without waiting for the callback."?
> 
> - If writes are not atomic or not waiting for callbacks really is a
> problem, what's an *efficient* alternative?

When you have several fs.write()s going on at once, they may end up being 
executed in parallel in a bunch of (up to 4 IIRC) background (libeio's) 
threads, so the write()s may actually happen in ~ any order. If you instead 
wait for the callback before issuing the next write(), then you're serializing 
them.
-- 
Jorge.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to