Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql show no more than 5 concurrent connection

I'm performing some load tests on my brand new server Apache/PHP/Mysql (Bitnami LAMP stack. Php 7.0.3/MySQL 5.7.10 ). I'm using AWS with 1 EC2 instance behind a loadBalancer. At the moment I'm using loader.io or jmeter for the tests. I'm testing a very simple API that perform this query:

select *,sleep(0.5) from debug limit 1

I added the sleep(0.5) because I wanted to see how the server behave with multiple concurrent connections and I found a bottleneck: if I run "SHOW PROCESSLIST" I can see only 5 process even if I have 10 concurrent user. The load test show that the connections are queued because the response time is growing during the test from 500 milliseconds to several seconds (depending on the duration of the test and the number of concurrent users).

I checked

select @@max_connections

and it's 151 (the default). max_user_connections is 0. What other parameter should I check to increase the number of concurrent connection on my DB?

If I run the test with 5 concurrent users, each one get a response in 500 milliseconds. If I add more concurrent users than the response time slow down.

If I run the load test on an API that does not access the DB there are no issues even with 400 concurrent users.

EDIT:

Monitoring with HTOP I see:

Tasks: 34, 245 thr; 2 running

Could be here the issue?

Thanks a lot

like image 787
Stefano Giacone Avatar asked Feb 19 '16 14:02

Stefano Giacone


People also ask

How many concurrent connections can MySQL 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 see total connections in MySQL?

The active or total connection can be known with the help of threads_connected variable. The variable tells about the number of currently open connections. mysql> show status where `variable_name` = 'Threads_connected'; Here is the output.


1 Answers

There are two areas for allowing concurrent connections:

1. Web servers

Check number of concurrent connections allowed by your web server.

See

  1. The Secret To 10 Million Concurrent Connections -The Kernel Is The Problem, Not The Solution
  2. How many socket connections can a web server handle?
  3. How do you increase the max number of concurrent connections in Apache?
  4. How to optimize apache web server for maximum concurrent connections or increase max clients in apache

Select your web server wisely to handle more concurrent connections.

2. Database and Open Files

Check your MySQL DB is capable of handling max concurrent connection coming from WebServer PHP.

Set max_connections to some higher amount.

set global max_connections := 800;

Also check open_files_limit for your OS. On linux, your process is limited to 1024 files, by default. This is very low, since every thread, connection, and, of course, file -- make for a file handle in linux. So set open_files_limit to some generous number (say 10000) to clear up your many connections with the operating system.

like image 141
Somnath Muluk Avatar answered Sep 22 '22 20:09

Somnath Muluk