Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm confused about concurrent MySQL connections

Tags:

mysql

So, I read a book in Mysql and it says that there's a limit on how many concurrent users that can access a database.

Does that mean that If I have 20k users browsing in my web application concurrently, my web application will fail to load the data in my database? Because my web application is accessing the database every time my website loads.

like image 699
Rho Avatar asked Mar 20 '11 14:03

Rho


People also ask

How many concurrent connections MySQL can handle?

Simultaneous MySQL connection limits Each database user is limited to 38 simultaneous MySQL connections. This limitation helps to prevent overloading the MySQL server to the detriment of other sites hosted on the server.

How do I avoid too many connections error in MySQL?

If clients encounter Too many connections errors when attempting to connect to the mysqld server, all available connections are in use by other clients. The permitted number of connections is controlled by the max_connections system variable. To support more connections, set max_connections to a larger value.

How do I know how many connections MySQL?

SHOW VARIABLES LIKE "max_connections"; To check the number of active connections, you can run the following query: SHOW VARIABLES LIKE "max_used_connections"; Hope it helps.


2 Answers

20k users loading a page at the exact same time ? That's quite a lot -- and your webserver will probably not accept that many concurrent requests itself (For example, Apache generally accepts only between 200 and 400 parallel requests).

The connection limit is the maximum number of users that can be connecter to your database at the exact same time -- if each page needs 100 ms to be generated, one user will only be connected for less than 100 ms.
And if you connect to your database just when you need to do your first SQL query, and disconnect immediately after your last SQL query, this can reduce the time during which your Webserver is connected to the DB.

If you have users reading content from your website, you can consider they will :

  • Load a page (maybe 100 ms on your server)
  • Do nothing but read for a couple of minutes (which takes absolutly no resource on your server)


As a sidenote : quite a long time before getting 20k concurrent connections (which means about 20,000 connections per second or so !), you'll probably have to deal with several scaling-relating problems...

like image 123
Pascal MARTIN Avatar answered Sep 23 '22 20:09

Pascal MARTIN


If you get a Too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients.

The number of connections permitted is controlled by the max_connections system variable. Its default value is 100. If you need to support more connections, you should set a larger value for this variable.

You should ask your system administrators to do these changes only when necessary.

like image 33
Pentium10 Avatar answered Sep 23 '22 20:09

Pentium10