G
G
GilbertAmethyst2020-02-06 19:49:47
MySQL
GilbertAmethyst, 2020-02-06 19:49:47

What can cause a MySQL connection to drop with a large number of concurrent connections?

Hello.

There are two VPS servers, conditionally VPS-1 (central) and VPS-N (worker).
The worker has 120+ php workers permanently connected to MySQL Database on a central server.
Doctrine ORM (Symfony) is used to interact with the database.

From time to time, processes crash with an error:

PHP Fatal error:  Uncaught Doctrine\ORM\ORMException: The EntityManager is closed. in /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:144
Stack trace:
#0 /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(756): Doctrine\ORM\ORMException::entityManagerClosed()
#1 /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(589): Doctrine\ORM\EntityManager->errorIfClosed()
#2 /var/www/html/worker/Worker.php(133): Doctrine\ORM\EntityManager->persist(Object(App\Entity\Account))
#3 [internal function]: shutdown(Array)
#4 {main}
  thrown in /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php on line 144


By mistake, you can see that the connection was broken, but right before the place where the error refers, there is the following code:
if ($this->em->getConnection()->ping() === false) {
            $this->em->getConnection()->close();
            $this->em->getConnection()->connect();
}
//... ->persist($account)


Changed max_connections, now: Shows: System on both servers: Ubuntu 18.04 (LAMP), MySQL database, php 7.2 What can it be and what system or Mysql limits can interfere with work? UPD 1: MySQL log on the central server (empty on the worker server):
SHOW VARIABLES LIKE "max_connections";
max_connections 4190





2020-02-06T13:53:15.778279Z 14323 [Warning] IP address 'IP_СЕРВЕРА' could not be resolved: Name or service not known
2020-02-06T13:53:15.792611Z 14323 [Note] Access denied for user 'serviced'@'IP_СЕРВЕРА' (using password: YES)
2020-02-06T15:02:37.363830Z 13961 [Note] Aborted connection 13961 to db: 'БАЗА_ДАННЫХ' user: 'root' host: 'IP_СЕРВЕРА' (Got an error reading communication packets)
2020-02-06T15:02:37.363975Z 13960 [Note] Aborted connection 13960 to db: 'БАЗА_ДАННЫХ' user: 'root' host: 'IP_СЕРВЕРА' (Got an error reading communication packets)
2020-02-06T18:11:13.234979Z 15933 [Note] Got timeout reading communication packets

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2020-02-06
@2ord

To get started Optimal configuration of Mysql
You need to know what is the load on the server: the number of read and write operations per second. Mysql may run out of machine resources.
And further https://ruhighload.com/mysql
In general, connections should be kept as short as possible and it is worth checking how to use the connection pool in the ORM. It is worth doing work to evaluate the effectiveness of a web application with a DBMS.
Ubuntu check last option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question