jvm에 dns 서버로부터 domain 정보 저장에 대한 cache 정책(TTL)을 '초단위'로 줄 수 있다.



java -Dsun.net.inetaddr.ttl=<값>



통신, DB같이 failover 를 염두한 애플리케이션에서는 'DNS TTL 캐쉬'는 반드시 써야 한다. 디폴트 값도 jvm마다 다를 수 있다.

-1 의 값을 주면, 캐쉬를 계속(forever)하기 때문에 잘 쓰지 않는다. TTL 값을 0 또는 적은 값으로 주는 것이 좋다.




JVM 문서를 살펴본다. sun.net.inetaddr.ttl 에 대한 디폴트 설정은 OS와 JVM 에 의존을 가지고 있다.



open jdk 7 source를 보면, sun.net.inetaddr.ttl 의 디폴트 값은 30초이다. 음수는 영원히 캐쉬함을 의미한다. 0으로 설정가능하다.

http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/share/classes/sun/net/InetAddressCachePolicy.java





이외에, 

공식 문서로는 sun.net.inetaddr.ttl 과 달리 자바의 security 설정 파일에 관련 설정이 networkaddress.cache.ttl 이 있다.

https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html#nct


networkaddress.cache.ttl

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

A value of -1 indicates "cache forever". The default behavior is to cache forever when a security manager is installed, and to cache for an implementation specific period of time, when a security manager is not installed.


(positive lookup을 의미)


-1의 값에 대해서는 명확히 상세하고 있지만, 디폴트 값에 대해서는 security manager와 구현에 따라 결정된다고 되어 있다. 


windows64, java8에서는 디폴트가 30이라는 얘기가 있긴 하지만, JVM 디폴트가 명세하지 않았기에 JVM 시작할 때 security configuration 설정에 명확히 설정하면 좋을 수는 있지만., 실제 사용할 때 JVM이 뜨기 전 (Security Manager가 실행되기 전)에 소켓이 초기화될 수 있기 때문에, 사실상 크게 의미가 없을 수 있다.


비슷한 사례는 여러 블로그에서도 발견될 수 있다.

https://support.stormpath.com/hc/en-us/articles/203697356-I-can-t-connect-to-the-Stormpath-REST-API-Is-the-server-down-



* 참고로, 

앞의 oracle 문서를 더 자세히 보면, 프러퍼티 하나가 더 추가된 것을 볼 수 있다. lookup의 실패에 대한 cache 정책도 추가할 수 있다. 디폴트가 10이니, 안써도 무관할 듯 싶다.


networkaddress.cache.negative.ttl (default: 10)
Specified in java.security to indicate the caching policy for un-successful name lookups from the name service.. The value is specified 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".


(negative lookup을 의미)

(구) sun.net.inetaddr.negative.ttl







Posted by '김용환'
,