php - MySQL connection gone -
i using cleardb
database windows azure
based php
application. getting intermittent error on mysql
connections. have 2000 online customers. , have 30 connections database.
how can scale website , overcome situation?
i taking care of closing connection of times. have prevented server errors this:
try { $this->_conn = $this->dbh = new pdo('mysql:host=' . db_server . ';dbname='. db_name, db_user, db_pass); $this->dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); } catch (pdoexception $e) { die("couldn't connect database. please try again!"); }
so, if there no connections left, it'll show appropriate message. but, it's not feasible customer facing websites. how can solve problem?
edit
how can analyse data:
array ( [0] => array ( [variable_name] => connections [value] => 505369 ) [1] => array ( [variable_name] => threads_cached [value] => 54 ) [2] => array ( [variable_name] => threads_connected [value] => 65 ) [3] => array ( [variable_name] => threads_created [value] => 1038 ) [4] => array ( [variable_name] => threads_running [value] => 4 ) )
i got above result after: show status variable_name 'threads_%' or variable_name = 'connections'
per understanding of issue, not easy design scalable database. consider following suggestions:
use connection pools. connection pool try automatically reuse existing connection whenever possible. 30 connections may used more 30 concurrent users. please refer http://php.net/manual/en/mysqlnd-ms.pooling.php more information.
partition database. is, if 1 database insufficient, use multiple. bit huge topic, can begin https://dev.mysql.com/doc/refman/5.7/en/partitioning-overview.html. guidelines azure sql databases (https://msdn.microsoft.com/en-us/library/azure/dn495641.aspx) can help, while database engine different, concepts same.
use in memory storage. mysql not offer complete set of in-memory database features. memory storage engine help. in-memory storage can improve performance lot. please note there’re limitations. actually
1 area major database vendors (including open source) continuously investing. , remember if database server not have sufficient memory, not @ all. please check https://dev.mysql.com/doc/refman/5.7/en/memory-storage-engine.html see if helps.
Comments
Post a Comment