近日在和朋友在搭建minecraft服务器的时候,发现motd响应异常缓慢,大概要6-7秒的加载时间,而ping延迟只有100ms左右,这显然不合常理。
一番操作后无果,最后从晓空和他朋友处得知了一个模组
根据mod介绍,加载时间长是因为mc会对纯ip地址服务器进行反向dns解析,这个过程会导致额外1-5秒的加载时间。
For servers whose addresses are represented solely by IP, e.g. , disable reverse DNS lookups in the corresponding object192.168.2.10:25565
InetAddress
Many non-loopback IPs lack associated domain names, which makes reverse lookups time-consuming
This option sets the domain of those servers directly to their IP, bypassing the reverse DNS check
This results in a 1s ~ 5s reduction in time for servers with pure IP address. Affects the following environments:
Pinging the server in the server list screen
Connecting to the server
使用此模组,或者将域名通过 A / SRV 记录解析到IP,然后通过域名进入服务器,即可解决加载速度慢的问题
截至java22,为了向后兼容性,java对于双栈域名解析,默认优先使用IPv4
jvm中有关于IPv6的参数
java.net.preferIPv6Addresses(默认值false)
By default, IPv4 addresses are preferred over IPv6 addresses, for example, when querying the name service (for instance, DNS service), IPv4 addresses would be returned ahead of IPv6 addresses.
若要使得域名优先解析IPv6,需要在客户端更改jvm参数,添加
-Djava.net.preferIPv6Addresses=true
文章评论