- Readability.
- Pronounceability.
- Representing one context.
- Do not use acronyms.
- Follow two points are taken from a tweet of Robert C Martine ( AKA uncle bob )
- The length of a variable name should be proportional to its scope. The length of a function or class name is the inverse.
amiths' notes
Wednesday, November 22, 2017
Pick the correct name
Tuesday, October 10, 2017
How I performed a Redis fail over.
Recently we have encountered a failure, on one of our Redis nodes due to reaching the maximum number of clients connected. As an immediate action for resolving the incident, we wanted to modify the existing connection timeout property of the node and do a failover master node into a slave, since the master node is not responsive anymore.
The approach we followed for the first time.We modify the redis.conf file on both master and the slave nodes. Then do a Redis service restart on the master node. Due to the service restart on the master, slave promoted itself into a master node.
The disadvantage of this approach is, once the master is restarting, it is losing any of the ongoing operations in the master node. This is not the appropriate approach recommended by the Redis.
The approach recommended by Redis. Redis has inbuild command to failover master node into a slave node. CLUSTER FAILOVER [FORCE|TAKEOVER]Sunday, July 16, 2017
Are you limiting your rate with Thread Sleep ?
If we look at those two, you may think it's really simple to solve those issues by sleeping the thread. For the first scenario, you can define a maximum number of retries and sleep in between each retry. For the second scenario, imposing explicit thread sleep will reduce the rate of your API access.
Let's assume we are checking connectivity each second and assume we got the connectivity by 6.5 seconds. If we use a sequential approach such as thread sleep, we are attempting 7 times to establish a connection.
When re connecting we have to consider two key aspects
- Limit number of attempts ( each attempt is an overhead to the application)
- Reconnect should happen as soon as connectivity back to normal.
With spring retry we can try out few different approaches, it can be a linear or Fibonacci or a custom approach.With the latest spring versions you may find this as a feature of the frame work but if you are not using spring or using an older version of spring framework, you can use this library as a dependency.So we are no longer required to use thread sleep as our default wait mechanism as well as we are not required to re invent the wheel when we wanted to try out some other re trying sequence.
Please visit the spring retry git hub project for more information and examples.