n******t 发帖数: 4406 | 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is not true.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
why do you need to force it?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The diefference should be trivial. | p******f 发帖数: 162 | 2 of course write() is buffered, the data is buffered in the OS memory.
while with fwrite(), the data is buffered on the user application
level first, then passed to OS via write(). | w**n 发帖数: 88 | 3 This , you never know for sure, sometimes yes sometimes no. the system
usually has a daemon process periodcally update the system buffer to
harddisk (i.e. 30 seconds).
you should read about some database application's recovery scheme if
your target is reliable IO -- it is not a simple issue at all. | p******f 发帖数: 162 | 4 fflus() just sends the data to OS buffer, as white(), it does not touch
phisical hard disk.
as wien suggested, some systems are doing background fsync at about 30
sec frequency, if you feel you can't afford 30 second data lost, you
at do a fsync every 10, or 5 or 1 seconds. adjust the intervals to find
the best frquency.
BTW, are you worring about application crash or OS crash, IIRC, the data
in OS buffer will not lost even if your application crashed.
maybe, your concern is data integrity, the | p******f 发帖数: 162 | 5
As I said, you do not have to worry about application crash,
'cause OS buffered data will not lost in such occasions.
fsync() only forces OS level data flush to disk, you have to write()
or fflush() first. | l****y 发帖数: 18 | 6 Actually, I think there is always a conflict between realibility and performance.
you always want to buffer much data enough b4 make a fsync() request, then it
causes the reliablity problem
If you are REALLY serious about this, My suggestion is to use NVRAM (non-
violate RAM) it won't lose any data even when there is a power-off. for further
reading:
http://citeseer.nj.nec.com/hitz95file.html | n******t 发帖数: 4406 | 7 this is not a real buy.
Why need to sync it?
you need to focus on what you have surely written. |
|