Showing posts with label f5. Show all posts
Showing posts with label f5. Show all posts

Tuesday, January 3, 2017

Story of an extra leap second and the mayhem it caused.

If you are not a programmer (or even if you are) chances are you missed the news of an extra second being added to clock. This was done to take care of earth slowing down fractionally for its rotation around sun, but that is not what I would be discussing in this blog.


 What I am going to discuss is the mayhem an extra second can cause to software's, specially the ones where performance measurements are done like Load Balancers (F5 etc.) or other DNS servers.

Now the gist of the problem is that developers assume time is Monotonic. In theory there seems nothing wrong with it, but think carefully and you would realize it is not always true. Consider a scenario where I need to calculate performance of a specific module, a quick way is to getTime at start of a function and do a getTime at end of a function and then subtract these 2 values. This seems perfectly correct, after all this is exactly what we do when referring to our stop watches on wrist right.



Important difference here though is no one suddenly makes your stop watch go faster or slower, which is not always true for a computer clock. When the time changes (Daylight or other occurrences like above), good NTP implementations take care of slowing (of fastening) clocks in a smoother manner, bad NTP implementations can change time with jerks on either side.

So your performance function can in all probability tell you that a piece of functionality finished off in less than 0 seconds. Which off-course you know is wrong and can lead to weird functional flows in your application, specially in an application like Load Balancer. 

So never assume time to be monotonic unless it has been guaranteed by underlying library you are using.

Lot of DNS server faced this when clocks stated adjusting to make up for the extra second, case in point being CloudFlare :How and Why leap second affected Cloudflare DNS

Always rely on better mechanisms like currentTimeMillis / nanoTime or if you are using libraries check if they support CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW.

Merging and Splitting PDF files

We all use and rely on PDF's. There are occasions though when you want to edit certain portions of a pdf and merge the edited version ba...