Grokking DevOps and SRE Interviews
Vote

0% completed

​

Exercise: Reading the End of a Large File

A payment service writes 40 GB of logs a day into one file. During an incident, the on-call engineer runs tail -n 20 on that file and sees the last 20 lines immediately.

A script that reads the same file line by line from the start must read all 40 GB first. At 500 MB a second, that takes 80 seconds, because 40,000 MB divided by 500 MB a second is 80. A script that calls readlines() is worse, because it also tries to hold all 40 GB in memory.

The tail command avoids both costs on a regular file. It moves to the end and reads backward in fixed-size blocks until it has seen enough lines

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content