Thursday, March 31, 2011

GSLB and JVM

GSLB ( Global Server Load Balancer) uses DNS to load balance traffic to multiple Data centers.  One of the issue when the clients are Servers that are running Java is DNS caching. Below is an extract from Sun ( oracle ) site explaining the restriction and how to fix it.

example where one could expect the clients to be servers than web browser is when the provider is offering APIs. EX: Payment Gateways, billing are some examples ...



JVM and DNS Cache
JVM ( Java Virtual Machine) caches DNS entries both for successful and unsuccessful lookups for security and performance reasons. These parameters are part of JVM properties as below
Ref: http://download.oracle.com/javase/1.5.0/docs/guide/net/properties.html

Specified in java.security to indicate the caching policy for successful name lookups from the name service.. The value is specified as as integer to indicate the number of seconds to cache the successful lookup. A value of -1 indicates "cache forever".

Specified in java.security to indicate the caching policy for un-successful name lookups from the name service.. The value is specified as as integer to indicate the number of seconds to cache the failure for un-successful lookups. A value of 0 indicates "never cache". A value of -1 indicates "cache forever".

There are two different ways to overcome DNS caching in JVM
1.       Changing the networkaddress cache property under <JAVA_HOME>/jre/lib/security/java.security.
a.        This will change the behavior for all the java applications that uses that JVM
2.       Set the security property per application using code as follows
java.security.Security.setProperty ("networkaddress.cache.ttl" , "0");
a.       This will change the DNS caching behavior only for the application that is setting this parameter unlike the previous one which affects all applications that is using that specific JVM

No comments:

Post a Comment