Solution to the cache problem of JVM DNS

After the host name is resolved to an IP address, the resource IP address is saved in the cache of the JVM. If the IP address of the resource is changed, you need to restart the application server to enable Identity Manager to detect the change (id-3635). This is a setting in sun JDK (version 1.3 and later), which can be controlled by using the sun.net.inetaddr.ttl property (usually set in JRE/lib/security/Java. Security)

//Set the effective time of the cache in the JVM for successfully resolved domain name records. By default, the JVM is always valid. In this way, the domain name IP redirection must restart the JVM. Here, it is modified to be valid for 5 seconds. 0 means that the cache is forbidden and – 1 means that it is always valid

java.security.Security.setProperty(“networkaddress.cache.ttl”, “5”);

//Set the valid time of the cache in the JVM for the domain name record that failed to be resolved. The default time of the JVM is 10 seconds. 0 means that the cache is forbidden, and – 1 means that it is always valid

java.security.Security.setProperty(“networkaddress.cache.negative.ttl”,”2″);

There are also two ways to set DNS cache

1. In Java_ Setting in opts

-Dsun.net.inetaddr.ttl=3 -Dsun.net.inetaddr.negative.ttl=1

2. Modify property

System.setProperty(“sun.net.inetaddr.ttl”, “3”);

System.setProperty(“sun.net.inetaddr.negative.ttl”, “1”);

In general, we don’t need to cancel the DNS cache of the JVM completely, we just need to reduce the effective time

1) One domain name corresponds to one IP and one domain name corresponds to 12 IPS. There is little difference in DNS query response time, and the latter takes up a little more CPU;

2) In the case of high concurrency, the CPU consumption without DNS caching is 3/4 times higher than that with 3S caching, and real-time DNS requests consume CPU;

3) There is little difference between 3S and 30s cache effective time on DNS query response time, and CPU memory consumption is close;

4) It is recommended to use 3-second cache to take care of operation, maintenance and performance;

Reference documents: http://www.verisigninc.com/assets/stellent/030957.pdf

Similar Posts: