How to limit the number of child processes that MySQL spawns

memoryMySQLprocess

Is there a way to limit the number of children than mysqld spawns? Or should one not worry about that? My VPS only has 512MB of RAM.

Here's the output of htop, after I set max_connections to 6 and restarted the mysql service:

  PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
27082 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.41  `- /usr/sbin/mysqld
27121 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.05  |   `- /usr/sbin/mysqld
27099 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.23  |   `- /usr/sbin/mysqld
27097 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.00  |   `- /usr/sbin/mysqld
27096 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.00  |   `- /usr/sbin/mysqld
27095 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.00  |   `- /usr/sbin/mysqld
27094 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.02  |   `- /usr/sbin/mysqld
27093 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.01  |   `- /usr/sbin/mysqld
27091 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.00  |   `- /usr/sbin/mysqld
27090 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.00  |   `- /usr/sbin/mysqld
27089 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.00  |   `- /usr/sbin/mysqld
27088 mysql     20   0  136M 28868  5800 S  0.0  5.7  0:00.00  |   `- /usr/sbin/mysqld

I've installed MySQL using aptitude.

$ aptitude search '~i'
i A mysql-client-5.1                                                                - MySQL database client binaries
i A mysql-client-core-5.1                                                           - MySQL database core client binaries
i A mysql-common                                                                    - MySQL database common files, e.g. /etc/mysql/my.cnf
i   mysql-server                                                                    - MySQL database server (metapackage depending on the latest version)
i A mysql-server-5.1                                                                - MySQL database server binaries and system database setup
i A mysql-server-core-5.1                                                           - MySQL database server binaries

Best Answer

you could use max_user_connections to limit the number of connections that a single mysql user can have at one time

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_user_connections

you'd need to try a few different settings / combinations of max_connections and max_user_connections to get the best performance without running out of connections.

also, its not a 1:1 ratio between connections and threads.

http://dev.mysql.com/doc/internals/en/threads.html

Related Question