Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database concurrent connections in regard to web (http) requests and scalability

One database connection is equal to one web request (in case, of course, your client reads the database on each request). By using a connection pool these connections are pre-created, but they are still used one-per-request.

Now to some numbers - if you google for "Tomcat concurrent connections" or "Apache concurrent connections", you'll see that they support without any problem 16000-20000 concurrent connections.

On the other hand, the MySQL administrator best practices say that the maximum number of concurrent database connections is 4096.

On a quick search, I could not find any information about PostgreSQL.

Q1: is there a software limit to concurrent connections in PostgreSQL, and is the one of MySQL indeed 4096

Q2. Do I miss something, or MySQL (or any db imposing a max concurrent connections limit) will appear as a bottleneck, provided the hardware and the OS allow a large number of concurrent connections?

Update: Q3 how exactly a higher connection count is negative to performance?

like image 548
Bozho Avatar asked Feb 26 '23 05:02

Bozho


1 Answers

Q2: You can have far more users on your web site than connections to your database because each user doesn't hold a connection open. Users only require a connection every so often and then only for a short time. Your web app connection pool will generally have far fewer than the 4096 limit.

Think of a restaurant analogy. A restaurant may have 100 customers (users) but only 5 waiters (connections). It works because customers only require a waiter for a short time every so often.

The time when it goes wrong is when all 100 customers put their hand up and say 'check please', or when all 16,000 users hit the 'submit order' button at the same time.

like image 171
Qwerky Avatar answered Apr 27 '23 06:04

Qwerky