MySQL server starts very slowly in Docker container

该文章根据 CC-BY-4.0 协议发表,转载请遵循该协议。
本文地址:https://fenying.net/en/post/2023/03/19/mysql-starts-slowly-in-docker/

I have a MySQL server deployed in a Docker container for testing purposes.

Recently, I found that the server started extremely slowly in the container.

After investigation, it turned out that the problem was caused by the too large open-file limits…

The problem occurs recently after several versions of Archlinux rolling upgrades, and the specific symptoms are:

  • The server starts extremely slowly, and it takes a very long time to start successfully;
  • After the container starts, the mysqld process occupies a large amount of memory;
  • With Docker container memory limits configured, the server starts to fail with a high probability;

I searched for solutions online for this problem, and occasionally found a solution: docker-library/mysql#579.

What? The problem is caused by the huge default open-file limits in the container.

You can confirm this by running the following command:

1docker run --rm mysql:5.7 /bin/bash -c 'ulimit -Hn && ulimit -Sn'

In my environment, the output is:

11073741816
21073741816

The cause of this problem is that the LimitNPROC option in docker configuration is set to infinity by default. While the infinity has been changed from 1048576 (2^20) to 1073741816 (2^30) in some systems.

So, after adding ulimit settings for the container, the problem is gone.

References:

comments powered by Disqus

Translations: