mysql连接远程主机时速度慢正常吗?
mysql 连接远程主机时速度慢是正常的还是应该与连接本地主机具有相同的性能?
当我尝试连接到远程主机时,我注意到性能存在微小差异,所以我想知道这是否正常?
Is it normal for mysql to be slow when connecting to a remote host or should it have the same performance as connecting to a local host?
I noticed a small performance difference, when I tried to connect to a remote host, so I'm wondering if that's normal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设远程计算机的处理能力与本地计算机相同,那么速度的主要差异应该是网络延迟 - 网络流量的往返时间。如果您要发送大量数据(例如,读取或写入大型 BLOB),那么网络带宽也会发挥作用并“减慢”速度。但一般来说,往返费用往往是最大的因素。如果您正在执行大量“小”查询,则在将本地连接与远程连接进行比较时,这种成本差异可能相当大。
出于好奇,我刚刚运行了一个已经构建的测试,该测试仅运行一堆更新查询。这不是使用 MySQL,而是使用另一个客户端/服务器 DBMS。因此,结果可能会有所不同,但想法是相同的,我想相对差异不会有显着差异。
这涉及大约 50,000 次操作。远程主机在 LAN 上有 2 个跃点,对于具有 1 字节有效负载的数据包,往返延迟约为 0.25 毫秒(如果我测量正确的话)。
Assuming that the remote machine is equal in terms of processing power as your local machine, then the primary difference in speed should be network latency - the round trip time for a network traffic. If you are sending huge amounts of data (e.g., reading or writing large BLOBs), then the network bandwidth can come into play as well and "slow" things down. But in general, the round trip cost is often the biggest factor. If you are executing a large number of "small" queries, this cost difference can be fairly significant when comparing a local connection to a remote connection.
Out of curiosity, I just now ran a test that I had already built that simply runs a bunch of update queries. This is not using MySQL but another client/server DBMS. Thus the results would likely be different, but the idea is the same and I would imagine the relative differences would not be significantly different.
This involved about 50,000 operations. The remote host was 2 hops away on the LAN with (if I measured it correctly) a round trip latency of approximately 0.25 ms for a packet with a 1 byte payload.
这完全取决于程序和MySQL数据库服务器之间的网络连接。缓慢的网络会使数据库显得缓慢。
我希望“小的性能差异”(正如您所描述的那样)对于远程连接来说是正常的。
It depends entirely on the network connection between the program and the MySQL database server. A slow network will make the database appear slow.
I'd expect a "small performance difference" (as you described it) to be normal for a remote connection.
默认情况下,MySQL 服务器将在客户端第一次连接时执行反向 DNS 查找。然后它将其存储在其缓存中。这可能会对性能造成影响,具体取决于反向 DNS 解析的速度。
By default the MySQL server will perform a reverse DNS lookup the first time a client connects to it. It then stores this in its cache. This can potentially give a performance hit depending on the speed of the reverse DNS resolution.
这取决于您正在执行的 MySQL 查询数量:慢速 MySQL 远程连接
您可以优化通过将许多小查询转换为更大的查询来编写代码。
It can depend on how many MySQL queries you're doing: Slow MySQL Remote Connection
You can optimize your code by converting many small queries into larger ones.