jrief/django-websocket-redis — pull request #57 by smcdonald-bepress (2014-10-23 20:55:30+00:00)
Title: Exponential backoff in websocket connection

Based on the example in this blog post: http://blog.johnryding.com/post/78544969349/how-to-reconnect-web-sockets-in-a-realtime-web-app this patch updates the reconnect logic to use exponential backoff with a random component.

This is intended to prevent a "thundering heard" problem if the server goes down. If all the clients are using the same reconnect interval, they'll all attempt to reconnect at the same time. We mitigate this by using the random component.

The original backoff was from 0.5s to 5s in 0.5s steps. The new backoff is randomly chosen from 0 - 1s ramping up exponentially (2^k-1 where k is the number of failed attempts) to 0 - 30s. This is a bit less aggressive, so you might prefer other timings. The timings I used are based off that blog post.

It would certainly be possible to apply the random component to a linear backoff (like the original), though exponential backoff seems to be more widely recommended.