2

Does twitter finagle library does DNS caching on its own? I ask this because we removed some of the hosts behind the vip but they were still getting requests from our client.

If there is such a cache, how do I set a time out for it ?

Piyush
  • 321
  • 2
  • 13
  • 1
    Have you already set the JVM DNS TTL cache value on the command line of the running Finagle using process? Here is the Oracle documentation for it in 8: http://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html#nct – Susan Potter Feb 21 '15 at 02:56
  • 1
    By default it caches successful lookups for the life time of the JVM process so you should set a value. This is on the JVM level not inside Finagle, to be clear. – Susan Potter Feb 21 '15 at 02:58
  • Yes that value is set to be 120. – Piyush Feb 21 '15 at 21:53
  • It's mentioned here that the values are cached - https://groups.google.com/forum/#!topic/finaglers/HqfNWJF3qZk – Piyush Feb 21 '15 at 21:53

1 Answers1

7

Yes, Finagle caches DNS internally. The details might be found in com.twitter.finagle.AsyncInetResolver class in Resolver.scala.

Finagle uses networkaddress.cache.ttl system property, so it's only possible to change TTL for whole JVM.

I'd recommend to use following code snippet to work with services with frequently changing hosts: https://gist.github.com/agleyzer/6909056. It allows to specify TTL on per-service basis. This is especially useful when working with services that use Amazon Route 53 failover routing policy.

Wildfire
  • 6,358
  • 2
  • 34
  • 50
  • Thanks for your answer. I've some follow up questions - Suppose finagle library cache some DNS entries, are those entries refreshed according to the networkaddress.cache.ttl property? What happens to the existing connection pools? Are they refreshed as well ? Also does using the code snippet that you mentioned make sure that any new connection made in the existing connection pool would have the new DNS value ? – Piyush Feb 22 '15 at 01:35
  • Yes on both questions: Existing connection pools are refreshed by both DnsCluster & Finagle (at least version 6.24, I'm not sure when it has been implemented). More precisely, new connection attempts will be made in accordance with latest DNS data. Existing connections will be retained as long as they stay alive. – Wildfire Feb 22 '15 at 10:55
  • So if I understand correctly both the existing connection pools and the new connections will use the new DNS names, and this behavior is default in finagle. So the code snipper that you mentioned is only for specifying a per service TTL ? – Piyush Feb 22 '15 at 19:16
  • So we have a service which has a failover policy similar Amazon Route. Would just setting networkaddress.cache.ttl to some small value be enough for handling changing DNS names ? – Piyush Feb 23 '15 at 19:51
  • That's possible, but not always desired. I.e., setting TTL to 1 second JVM-wide might have unpredictable consequences. – Wildfire Feb 24 '15 at 10:52