[Tutor] A further question about opening and closing files

Alan Gauld alan.gauld at btinternet.com
Wed Sep 9 21:25:06 CEST 2015


On 09/09/15 19:20, Laura Creighton wrote:
> In a message of Wed, 09 Sep 2015 17:42:05 +0100, Alan Gauld writes:
>> You can force the writes (I see Laura has shown how) but
>> mostly you should just let the OS do it's thing. Otherwise
>> you risk cluttering up the IO bus and preventing other
>> programs from writing their files.
> Is this something we have to worry about these days?  I haven't
> worried about it for a long time, and write real time multiplayer
> games which demand unbuffered writes ....  Of course, things
> would be different if I were sending gigabytes of video down the
> pipe, but for the sort of small writes I am doing, I don't think
> there is any performance problem at all.
>
> Anybody got some benchmarks so we can find out?
>
> Laura
If you are working on a small platform - think mobile device - and it has
a single channel bus to the storage area then one of the worst things
you can do is write lots of small chunks of data to it. The overhead
(in hardware) of opening and locking the bus is almost as much as
the data transit time and so can choke the bus for a significant amount
of time (I'm talking milliseconds here but in real-time that's significant).

But even on a major OS platform bus contention does occasionally rear
its head. I've seen multi-processor web servers "lock up" due to too many
threads dumping data at once. Managing the data bus is (part of) what
the OS is there to do, it's best to let it do its job, second guessing 
it is
rarely the right thing.

Remember, the impact is never on your own program it's on all the
other processes running on the same platform. There are usually tools
to monitor the IO bus performance though, so it's fairly easy to
diagnose/check.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list