I am having this issue for a while I am not sure how to fix it. I have a Docker container running PHP+Apache with an application. The MySQL and MongoDB servers are on the same network as the host. So:
MySQL DB Server IP: 192.168.1.98
Mongo DB Server IP: 192.168.1.98
Host: 192.168.1.90
For some reason the connectivity between the application running on the container and the DB server is pretty slow and sometimes it takes more than one minute running long queries.
I can say the problem is not the DB server because running the same application on the same server works fast so I think is something related to networking but I am not sure what or why.
TLDR; There’s way too many possibilities for slow downs to be able to clearly help on this matter.
Ususally docker does not create noticeable increase in latency. You’d need to describe more how are your containers set-up? If MySQL is in a container, alongside your application container, the connection should be pretty fast…
Have you tried running the query directly on the MySQL server? What are the times there? Also, if you are doing big writes at the same time you are doing reads, it might slow you down to have everything on the same host as the drive can only do so much… You can monitor the containers to see if there are CPU, Memory peaks that would explain some slow downs. There might be swapping involved also.
@salketer no, MySQL isn’t running in a container but a standalone server. That MySQL server has already an Apache and PHP running there so I have test the same query running the application itself in there and it’s pretty fast. There is another developer using Docker here and is raising the same issue with slowness. I am not sure what could be happening there or if there is any way to speed up this.
Well, I’d try running the query from the container using EXPLAIN. This will
help you figure out what takes longer when you compare it to the query ran
on the same machine. If you asked me to guess I’d say that either network
latency or memory swapping on the container side.
Also note that you do need to capture the query from the application and
run it by itself. Unless you have good monitoring that separates query time
and load times, there are no real way to figure out if it really is your
MySQL query that is slower… It could simply be that the PHP using the
result has a lot to do on it and that lower RAM could slow it down.
In doubt, you could install the PHP/Apache stack directly on the machine
and trying from there. I am very convinced that it will not be faster by
more than a dozen microseconds compared to a dockerized environment.
@salketer as I said the problem is not the development server, something is wrong with the container, sometimes it takes a minute to give me an answer and display results when in the development server this is quick for sure less than one minute
Me neither… I was telling you to test your server. You are not giving out
anything precise enough to allow my to help troubleshoot more.
If other developers are not using docker and are running the queries
faster, this might mean that the Apache container does not have access to
enough ram, or if there is disk activity it could be slowed by a not
optimal driver. but I can only guess.