This is my code:
start = Time.now
File.write('/tmp/a.txt', 'Hello, world!')
puts "Saved in #{Time.now - start}"
In some cases, I see this in the log:
Saved in 0.001
Saved in 0.002
Saved in 0.245
Saved in 0.002
Why is there occasionally such a spike? What could that be? I'm not using flock anywhere. My suspicion is that some library has overridden the method File.write() and added some locking/synchronization there. Is it possible?
Update: It seems that Dir.new(), which regularly gets access to the directory, blocks access to it.