开发者

Is it normal for mysql to be slow when connecting to a remote host?

开发者 https://www.devze.com 2023-02-09 13:01 出处:网络
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?

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开发者_高级运维?


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.

Local host (using IPC comm):  5.3 seconds
Remote host (UDP comm):  20.2 seconds

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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号