开发者

Reading a small file k times + small writes vs read large file k times + small appends

开发者 https://www.devze.com 2023-03-16 16:55 出处:网络
I have to make a decision for a script that shows the most recent event. Each event can be less than 250 bytes.

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

  1. Write to a file after every event. Read the file and output.
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消