Database tricks which will blow your mind ! | StudyObject

Finding how much traffic your website can handle can be a big task, as everything needed to be taken into account, be it memory , optimisation rules, page size and several other factors.

In one of the articles I mentioned about the memory optimisation for WordPress to handle high traffic. We will continue to mention many steps to use the hosting resources optimally so that maximum no of users can be supported by a website.

MYSQL Tweaks

Today we will discuss about mysql configurations which limits the no of concurrent users on your website and how can we change those to allow many more concurrent users with limited hardware resource.

We will also look at why do we get “too many connection error” on a website when there is a sudden surge in traffic. This is seen because all connections between mysql daemon is occupied by users and mysql daemon can not service any further connection request.

How to check default maximum_connections Attribute ?

The no of connections to mysql is limited by max_connections global variable. The default value you can display by executing below command in mysql command line or via phyMyAdmin client. You can also use mysql terminal. I am using phpMyadmin. The default value of max_connection is set to 150.

show variables like ‘max_connections’;

The Actual allowed connection is max_connections+1 , so a total of 151 connections is allowed with mysql. The extra connection is reserved for user with connection_admin privilege. The reason why one extra connection has been provided is to debug the issues by admin even if max no of connection is under use by unprivileged users.

 

How to change max_connections in mysql ?

Most Database connections are open and closed in fraction of seconds. According to data provided by hosting provider , the maximum no of users which can be supported on say 25 connections limits(max_connections) can be around 500. So with 150 default max_connections total no users, which can be supported can be benchmarked at 3000.

Usually most of the website traffic falls under 10000 concurrent users. We recommend to set the max_connections value at 350 so at least it can cater to 7000 users concurrently.

Please use following command to set the max_connections

set global max_connections = 350;

 

Make the change persistent

This change will not persist if mysqld is killed or the system is rebooted. You must update it in the /etc/my.cnf file if you have CentOS. On Some other operating systems the config might be in mysqld.conf.

 

Setting max_connections to higher value makes sure that the database can handle those many concurrent users. There are other factors like Bandwidth which should also be taken into account while calculating the overall number of users a site can support.

You can check no of connections with mysql db with following command

netstat | grep “mysql” | wc -l 

We will be publishing another series where we will discuss few more ways to optimise the mysql database.

 

Author: Rajnish K

About Author :

Rajnishk is a Serial Entrepreneur, R&D Expert and is passionate for Web Stack. He can be reached at [email protected]

 

Customer Testimonials

Colin Bridger

"I'm really happy to hire wordpress expert from studyobject! They looked into our web optimization rules ! It will be the base of my future projects! I strongly recommend them"

Alyssa Thompson

"Guys, you are fantastic! You created the most user friendly e-commerce interface I ever used!""

Tracie G. Murrieta

"Absolutely the best design ! It's far worth the price. Thank you for such a great design for our requirement!"

Wiley Troy

"The most intuitive Interface I have ever used.They provide Incredible transitions and features!"

StudyObject © 2020. All rights reserved.
X