I think you may actually be able to use a WriteStream instead, as far as I 
recall, 
those queued data up in an array, then they write it out as soon as possible, 
which should guarantee ordering.

Alternatively, since this is a log file, you could use something like the 
winston 
by Charlie Robbins.

– Micheil

On 24/03/2012, at 10:45 PM, Jorge wrote:

> And WRT "That is besides the point": you've asked "What's with "Note that it 
> is unsafe to use fs.write multiple times on the same file without waiting for 
> the callback.?"
> 
> On Mar 24, 2012, at 11:19 PM, Jaka Jančar wrote:
> 
>> That is besides the point. The question is, will the fs.write()'s map 1:1 to 
>> write()'s?
>> 
>> On Saturday, March 24, 2012 11:05:25 PM UTC+1, Jorge wrote:
>> 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
> 
> -- 
> 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

-- 
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