MySQL max_connections 的真正含义是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8686291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:12:30  来源:igfitidea点击:

What does max_connections really mean?

mysqldrupal

提问by alex

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

我正在尝试为 MySQL 和共享主机上所需的资源设置理想的性能设置。

My question is, what does max_connectionsreally mean?

我的问题是,max_connections真正的意思是什么?

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_connectionsat 50, will everyone get locked out?

它是对服务器发出的唯一并发请求的数量吗?因此,如果有两个用户,其中 1 个打开 1 个选项卡,另一个打开 4 个选项卡……并且同时按下所有选项卡重新加载,是否会与 MySQL 数据库建立 5 个连接?因此,如果我们将这种情况变成:10 个人有 2 个标签,31 个人有一个标签,他们都同时按下刷新……当我们max_connections50 人时,每个人都会被锁定吗?

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

我问的原因是因为我想降低max_connections内存资源的保守性,因为我一直看到该站点进入 CPU 节流模式

Thank you for your help

感谢您的帮助

采纳答案by Michael Mior

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.

如果确实超过了最大连接数,则任何后续的连接尝试都将失败。

回答by ThinkingMonkey

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.

允许的连接数由 max_connections 系统变量控制。当 MySQL 与 Apache Web 服务器一起使用时,默认值为 151 以提高性能。(以前,默认值为 100。)如果您需要支持更多连接,则应为此变量设置更大的值。

mysqld 实际上允许 max_connections+1 个客户端连接。额外的连接保留供具有 SUPER 权限的帐户使用。通过将 SUPER 权限授予管理员而不是普通用户(他们不应该需要它),管理员可以连接到服务器并使用 SHOW PROCESSLIST 来诊断问题,即使连接了最大数量的非特权客户端。请参见第 12.7.5.30 节,“显示进程列表语法”。

MySQL 可以支持的最大连接数取决于给定平台上线程库的质量、可用 RAM 量、每个连接使用多少 RAM、每个连接的工作负载以及所需的响应时间。Linux 或 Solaris 应该能够常规地支持 500 到 1000 个同时连接,如果您有许多 GB 的可用 RAM 并且每个连接的工作负载很低或响应时间目标不高,则可以支持多达 10,000 个连接。由于该平台上使用的 Posix 兼容层,Windows 仅限于(打开表 × 2 + 打开连接)< 2048。

可能需要增加打开文件限制。另请参阅第 2.5 节 “在 Linux 上安装 MySQL”,了解如何提高操作系统对 MySQL 可以使用的句柄数量的限制。

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

来自:MySQL 5.6 参考手册:: C.5.2.7 连接过多

回答by tk_

max_connectionsis a global variable that can have a minimumvalue of 1 and a maximumvalue 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.

max_connections是一个全局变量,最小值为 1,最大值为 100000。然而,众所周知,将 max_connections 设置为一个非常高的值对性能来说并不是太好。一代又一代的系统管理员都遵循了这条规则。

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

当谈到性能max_connections值时,总是受限于服务器规格,如果不使用,则不会出现性能问题。

Please use this for more information.

请使用此获取更多信息。