简体   繁体   English

为什么使用MySQL连接进行DNS查找需要这么长时间?

[英]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 . 我了解链接问题中的评论说查找需要很长时间,但是我在问为什么

It might have something to do with sockets and the way MySQL treats localhost . 它可能与套接字以及MySQL处理localhost的方式有关。 See here . 这里

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.

相关问题 Laravel为什么需要这么长时间才能加载? - Why does Laravel take so long to load? 为什么我的网站需要很长时间才能开始下载? - Why does my site take so long to start a download? 为什么file_get_contents需要这么长时间? - Why does file_get_contents take so long? 为什么这个需要平面数组的函数需要这么长时间才能使它成为嵌套数组? - Why does this function that take flat array take so long to make it a nested array? 为什么在PHP中建立与MySQL的连接大约需要2秒钟? - Why does making a connection to MySQL take about 2 seconds in PHP? 为什么 AJAX 这么长? - Why does AJAX is so long? 为什么带有空白上传表单的表单要花这么长时间? 可能是什么原因? - Why does my form with empty upload form take so long? What could be the reason? 通过php .com扩展名使用Internet Explorer-为什么要花这么长时间? - Using Internet Explorer via php .com extension - why does it take so long? 为什么在关系中搜索(在哪里)十进制列会花费这么长时间? - Why does a search (wherehas) for decimal column in a relationship take so long in laravel? 为什么这个正则表达式需要这么长时间才能找到某些文件中的电子邮件地址? - Why does this regex take so long to find email addresses in certain files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM