简体   繁体   English

Codeigniter多租户需要长时间加载租户数据库

[英]Codeigniter Multi Tenant Takes long time in loading tenant database

I am developing a multi tenant app in CodeIgniter, where every tenant has its own db. 我正在CodeIgniter中开发一个多租户应用程序,其中每个租户都有自己的数据库。 At run time I find the tenant name and then load its db info from my master database. 在运行时,我找到租户名称,然后从我的主数据库加载其数据库信息。 In My_Model a function establishes connection with slave database My_Model一个函数与从数据库建立连接

function getDbConFig() {
    $dsn = 'mysql://'.$this->dbs_user.':'.$this->dbs_pwd.'@'.$this->dbs_dbhost.'/'.$this->dbs_dbnam;
    if(!empty($this->dbs_user) && !empty($this->dbs_dbhost) && !empty($this->dbs_dbnam)){
        $this->db_slave = $this->load->database($dsn, TRUE);
    }
}

Every thing is working fine, but problem is it take very long time in establishing slave database connect. 一切正常,但问题是建立从数据库连接需要很长时间。

Any help will be appreciated. 任何帮助将不胜感激。

IMHO, rather than use the getdbconfig at the model level, you should be considering using at the Data access layer level. 恕我直言,您应该考虑在数据访问层级别使用,而不是在模型级别使用getdbconfig。 Did you check out the connection from the connection pools. 您是否从连接池中签出了连接。 You can consider increasing the connection pool recycling frequency. 您可以考虑增加连接池的回收频率。 Also, you should not be handling two connections at any point of time. 另外,您不应在任何时间处理两个连接。

Post your details here for more detailed discussion. 在此处发布您的详细信息以进行更详细的讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM