[Twisted-Python] UDP Logging Server
screwtape at froup.com
Sat Mar 12 20:15:37 EST 2011
On Sat, Mar 12, 2011 at 02:33:45PM +0200, Pandelis Theodosiou wrote:
> On Sat, Mar 12, 2011 at 3:32 AM, Tim Allen <screwtape at froup.com> wrote:
> > Of course, if you flush after every disk read, your program will run
> > a bit more slowly and with more I/O... for an application where
> > reliability is more important than performance (like logging) that's
> > probably acceptable.
> You may also setup a timer that flushes files every, say, 5 minutes.
> One other thing I've read in the Python.org site is that flush() is not 100%
> sure to work immediately and should be used in combination with os.fsync().
> Is there someone that can explain if that is correct?
Depends what you mean by 'work'. The standard library (Python's or C's)
buffers reads and writes because calling into the kernel is expensive.
The kernel buffers reads and writes because disk I/O is even more
expensive. flush() tells the standard library "send buffered data to the
kernel right now" which means your data should survive if your process
crashes. fsync() tells the kernel "send buffered data to the disk right
now", which means your data should survive if the entire machine
Whether you call nothing, just flush(), or both flush() and fsync()
depends on how your software balances performance versus reliability.
More information about the Twisted-Python