So I think in the master-slave database design, all session-related tables should be treated in a special way. That is: All session data tables can be updated and queried, when a user visits the site, the user is bound to the specified database, all session access and query operations on this database. The session table does not synchronize, and other non session-class updates are updated from the primary database. In fact, this can not escape the session update when the database switch, so if you do not want to trouble, or the session stored in the text of the good.
Sub-database design, will probably from the pressure performance will improve a few grades, of course, single execution efficiency will not be higher than the single database, after all, there is the efficiency of database switching. Library and master-slave database collocation is a better solution to improve the bottleneck of database concurrency. Principle: Large amount of data, sub-library, large number of visits, master and subordinate. Most of the time, this is both parallel (this article does not discuss cache).
I think if you want to implement the library and master-slave relationship, then the number of database servers will be very considerable, in the application to switch to a certain server at any time, will be a very headache problem, configuration replacement, variable name, is not there will be a lot of it? How to find a better solution will be the topic of this article.
The first is the problem that the database makes a lot of data base. Under what circumstances is the sub-Library? Perhaps some people still do not understand why want to divide a storehouse, I briefly say my own experience guess. For example, a blog program, the general design is to store the log in a log table. Assuming it's a multi-user blog, then will be associated with a UID, if the amount of data is not large, so the design is not a problem, but the day is huge, hundreds of thousands of log entries a day, and the number of visits is also considerable, I think it is impossible for each user to access the log list, To find a few of the data tables that contain tens of millions of of logs, the efficiency is evident. This is the time to take into account the problem of the sub-Library. How to divide? There is a very simple method of the table, that is, according to the UID section, the log is recorded in each database, of course, this distribution still needs to be adjusted according to the previous statistical results, because the user log distribution is certainly not uniform. Set the UID segment, and then create a database object based on the UID index to the specified database configuration. The configuration information may be as follows:
Copy Code code as follows:
$configs [' Db_info '] [' blog '][0] = array (
' Db_host ' => ' 192.168.0.1 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' blog '][1] = array (
' Db_host ' => ' 192.168.0.2 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' blog '][2] = array (
' Db_host ' => ' 192.168.0.2 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
//... There's a lot more.
As for which server to choose, just make a simple match based on the UID.
Again, the master-slave database is mentioned. Under what circumstances is the master-slave database used? For example, a celebrity blog, the amount of traffic is quite large, there is no way to his data to be split, this time to consider the master database server, using multiple databases to divert. This applies to the master-slave and the library, which may have to be slightly altered configuration information.
Copy Code code as follows:
$configs [' Db_info '] [' blog '][0][' master '] = Array (
' Db_host ' => ' 192.168.0.1 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' blog '][0][' slave '][0] = array (
' Db_host ' => ' 192.168.0.2 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' blog '][0][' slave '][1] = array (
' Db_host ' => ' 192.168.0.3 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' blog '][1][' master '] = Array (
' Db_host ' => ' 192.168.0.4 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' blog '][1][' slave '][0] = array (
' Db_host ' => ' 192.168.0.5 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' blog '][1][' slave '][1] = array (
' Db_host ' => ' 192.168.0.6 ',
' Db_name ' => ' blog ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' Session '][0][' master '] = Array (
' Db_host ' => ' 192.168.0.7 ',
' Db_name ' => ' session ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
$configs [' Db_info '] [' Session '][1][' master '] = Array (
' Db_host ' => ' 192.168.0.8 ',
' Db_name ' => ' session ',
' Db_user ' => ' root ',
' Db_pass ' => ',
);
Write here, I think should know how to divide the table and allocate your database, then I will say how easy to read such configuration information, how to integrate these configurations into your database driver.
Current 1/2 page
12 Next read the full text