任何使Java符合DNS缓存超时(TTL)的方式? [英] Any way to make Java honor the DNS Caching Timeout (TTL)?

查看:1227
本文介绍了任何使Java符合DNS缓存超时(TTL)的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用GSLB进行地理分布和负载平衡。每个服务都被分配一个固定的域名。通过一些DNS魔法,域名被解析为一个最接近负载最小的服务器的IP。为了使负载平衡起作用,应用服务器需要从DNS响应中兑现TTL,并在缓存超时时再次解析域名。但是,我无法找到在Java中做到这一点的方法。

We use GSLB for geo-distribution and load-balancing. Each service is assigned a fixed domain name. Through some DNS magic, the domain name is resolved into an IP that's closest to the server with least load. For the load-balancing to work, the application server needs to honor the TTL from DNS response and to resolve the domain name again when cache times out. However, I couldn't figure out a way to do this in Java.

应用程序在Java 5中,在Linux(Centos 5)上运行。

The application is in Java 5, running on Linux (Centos 5).

推荐答案

Java有一些非常奇怪的dns缓存行为。你最好的办法是关闭dns缓存或将其设置为5秒钟以内的低位数。

Java has some seriously weird dns caching behavior. Your best bet is to turn off dns caching or set it to some low number like 5 seconds.


networkaddress.cache.ttl(默认值: -1)


表示从名称服务成功进行名称查找的缓存策略。该值指定为整数,以指示缓存成功查找的秒数。值为-1表示缓存永远。



networkaddress.cache.negative.ttl(默认值:10)


表示来自名称服务的未成功名称查找的缓存策略。该值指定为整数,以指示缓存未成功查找失败的秒数。值为0表示从不缓存。值-1表示永久缓存。

networkaddress.cache.ttl (default: -1)
Indicates 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".

networkaddress.cache.negative.ttl (default: 10)
Indicates 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".



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆