[英]Why does a DNS lookup take so long with a MySQL connection?
I was debugging some code and realised that a method was taking almost 2 seconds to connect to MySQL. 我正在调试一些代码,并意识到一种方法需要将近2秒钟才能连接到MySQL。 After a bit of digging ( Why is constructing PDO connection slow? ) I found that it's because I was using 'localhost' instead of '127.0.0.1'. 经过一番挖掘( 为什么构建PDO连接缓慢? ),我发现这是因为我使用的是“ localhost”而不是“ 127.0.0.1”。 This sped it up significantly. 这大大加快了速度。 My question is, why? 我的问题是,为什么? Why does a lookup in my /etc/hosts take so long? 为什么在我的/ etc / hosts中进行查找需要这么长时间? I would've thought it was really quick. 我会以为它真的很快。 Also, this optimisation doesn't speed anything up on my work desktop, but definitely worked on my laptop (they're both running Ubuntu 12.04) 此外,此优化无法在我的工作台式机上加快任何速度,但绝对可以在我的笔记本电脑上工作(它们都在运行Ubuntu 12.04)
Edit: My question is why does it take so long. 编辑:我的问题是为什么要花这么长时间。 I understand that the comment in the linked question says that lookups take a long time, but I am asking why . 我了解链接问题中的评论说查找需要很长时间,但是我在问为什么 。
Could it be more about the inverse resolution? 可能更多关于逆分辨率吗? Normally it is really a better idea to user "real" names and IPs, even if it is a local connection. 通常,即使是本地连接,使用“真实”名称和IP也是一个更好的主意。 Try using the hostname of the server and the IP. 尝试使用服务器的主机名和IP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.