Reading a small file k times + small writes vs read large file k times + small appends
I have to make a decision for a script that shows the most recent event.
Each event can be less than 250 bytes.
There are two ways to do this
- Write to a file after every event. Read the file and output.
- Append to a file after every event. Read the entire file, find the last item, output. (the size of the file can grow pretty big, up to 1MB)
Assuming the reads are very frequent(up to once per second), writes are quite frequent (say arou开发者_如何学Gond 1000 times per day)
Which way is better for the hard drive?
Don't worry about it. Hard drives are cached (read and write).
Do what is simplest and the easiest to understand.
精彩评论