What does max_connections really mean?
Asked Answered
V

3

22

I'm trying to set the ideal performance setup for MySQL and resources needed on a shared hosting.

My question is, what does max_connections really mean?

Is it the number of unique concurrent requests made to the server? So if there are two users, 1 with 1 tab open and the other with 4 tabs open... and both press all their tabs to reload at the same time, will there be 5 connections made to the MySQL DB? Consequently, if we bump this scenario to: 10 people with 2 tabs and 31 people with one tab all pressing refresh at the same time... with our max_connections at 50, will everyone get locked out?

The reason I ask is because I want to shoot for low max_connections to be conservative with memory resources since I consistently see the site going into cpu throttling mode

Thank you for your help

Vannoy answered 31/12, 2011 at 4:33 Comment(0)
N
18

Yes, there is a separate connection opened for each page. However, assuming you're not doing anything database-intensive, the connection will be short-lived and close itself once the page has been served to the client.

If you do exceed the maximum number of connections, any subsequent connection attempt will fail.

Niggerhead answered 31/12, 2011 at 5:2 Comment(2)
Is there a limitation for setting the value of max_connections? What happens if I set it to 200,000 for example or even more?Outrage
Each connection uses memory both within the OS and in the server process. Eventually you'll hit a limit of the maximum number of connections your box can handle. This is quite old, but the C10K problem gives an idea of some if the issues faced with a large number of connections to a single server.Niggerhead
T
16

The number of connections permitted is controlled by the max_connections system variable. The default value is 151 to improve performance when MySQL is used with the Apache Web server. (Previously, the default was 100.) If you need to support more connections, you should set a larger value for this variable.

mysqld actually permits max_connections+1 clients to connect. The extra connection is reserved for use by accounts that have the SUPER privilege. By granting the SUPER privilege to administrators and not to normal users (who should not need it), an administrator can connect to the server and use SHOW PROCESSLIST to diagnose problems even if the maximum number of unprivileged clients are connected. See Section 12.7.5.30, “SHOW PROCESSLIST Syntax”.

The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform, the amount of RAM available, how much RAM is used for each connection, the workload from each connection, and the desired response time. Linux or Solaris should be able to support at 500 to 1000 simultaneous connections routinely and as many as 10,000 connections if you have many gigabytes of RAM available and the workload from each is low or the response time target undemanding. Windows is limited to (open tables × 2 + open connections) < 2048 due to the Posix compatibility layer used on that platform.

Increasing open-files-limit may be necessary. Also see Section 2.5, “Installing MySQL on Linux”, for how to raise the operating system limit on how many handles can be used by MySQL.

From: MySQL 5.6 Reference Manual:: C.5.2.7 Too many connections

Treble answered 31/12, 2011 at 5:22 Comment(0)
B
2

max_connections is a global variable that can have a minimum value of 1 and a maximum value of 100000. However, It has always been commonly known that settings max_connections to an insanely high value is not too good for performance. Generations of system administrators have followed this rule.

When it comes to performance max_connections value is always bounded to server specs and if it is not in use, no performance issue will occur.

Please use this for more information.

Boxfish answered 19/8, 2019 at 7:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.