dsyua2828 2015-06-04 15:21
浏览 58

MySQL连接不见了

I am using clearDB database for my windows azure based php application. I am getting intermittent error on mysql connections. Currently we have nearly 2000 online customers. And we have 30 connections from database.

How can I scale the website and overcome this situation?

I am taking care of closing connection most of the times. For now I have prevented server errors by 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 to database. Please try again!");
}

So, if there is no connections left, then it'll show appropriate message. But, It's not feasible for customer facing websites. How can I solve this problem?

EDIT

How can I analyse this 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 WHERE variable_name LIKE 'Threads_%' OR variable_name = 'Connections'

  • 写回答

1条回答 默认 最新

  • dousu8767 2015-06-05 10:20
    关注

    Per my understanding of the issue, it is not easy to design a scalable database. Consider the following suggestions:

    • Use connection pools. A connection pool will try to automatically reuse an existing connection whenever possible. So the 30 connections may be used by more than 30 concurrent users. Please refer to http://php.net/manual/en/mysqlnd-ms.pooling.php for more information.

    • Partition the database. That is, if one database is insufficient, then use multiple. This is a bit huge topic, you can begin from https://dev.mysql.com/doc/refman/5.7/en/partitioning-overview.html. Those guidelines for Azure SQL Databases (https://msdn.microsoft.com/en-us/library/azure/dn495641.aspx) can also help, while the database engine is different, most concepts are the same.

    • Use in memory storage. MySQL currently does not offer a complete set of in-memory database features. But the MEMORY Storage Engine could help. In-memory storage can usually improve performance a lot. But please note there’re some limitations. This is actually
      one area where major database vendors (including open source) are continuously investing. And remember if the database server does not have sufficient memory, it will not help at all. Please check https://dev.mysql.com/doc/refman/5.7/en/memory-storage-engine.html to see if helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?