Basically I'm writing hundreds of times per minute to a log file, I wonder if it makes a significant difference to the longevity of a hdd / ssd whether I write every change directly to the log file, or if I should just temporarily save the changes in ram and dump them once a minute to the log?

Not sure if relevant, but I'm using python's:

with open('log.txt', 'a') as log: log.write('a') command

3

There are 3 best solutions below

0
Barmar On BEST ANSWER

It shouldn't make any significant difference. Python uses buffered output when writing the file, and the OS has file buffers in the kernel.

4
Mozart Hasse On

Usually modern hardware prevents excessive writes to disk by using a cache. This solves the hardware degradation problem, however the performance is affected significantly. You'll spend a lot less CPU if you write these log entries in blocks.

0
ken On

In general, the dominant factor in the longevity of a HDD/SSD is the number of writes to sectors/cells. This is basically how many bytes are written. It is unlikely that how users write, with or without buffering, will have a significant impact on its lifespan.