The post Database tricks which will blow your mind ! | StudyObject appeared first on StudyObject.
]]>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.
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.
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.
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.
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
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]
The post Database tricks which will blow your mind ! | StudyObject appeared first on StudyObject.
]]>