Jump to content


Submitter

SUPPORT TOPIC File Information

  • Submitted: Dec 27 2010 09:09 AM
  • Last Updated: Feb 08 2012 11:36 AM
  • File Size: 6.92KB
  • Views: 4627
  • Downloads: 51
  • Supported IPS Software Version: 3.1.4

Previous Versions

  • 29 Dec 2010 Download High Performance MySQL Driver 1.1.3

Download High Performance MySQL Driver 1.1.3

* * * * - 5 Votes



Screenshots
ABOUT THIS DRIVER:

This driver allows you to set up your mysql servers in a master-slave configuration where you have one master that you can both read and write updates to, and several slave databases that are read-only and stay in-sync with the master server. You can then use this driver to randomly distribute read (select) queries across one or more slave databases. You can also distribute read (select) queries to the master server as well. Using a setup like this you can potentially boost performance by using more than one database server.

NOTE: If you do not use mysql replication this driver will not improve your performance at all, as it relies on the native IPS MySQL drivers. This driver primarily implements load distribution of queries.

PRIOR TO ANY APPLICATION UPGRADES OR INSTALLATIONS YOU MUST CHANGE YOUR DRIVER IN conf_global.php BACK TO 'mysql'. OTHERWISE YOU MUST RENAME ALL APPLICATION SQL QUERY FILES TO REFLECT THE balancedmysql DRIVER NAME. ONCE UPGRADES/INSTALLATIONS ARE COMPLETE YOU CAN RESUME USING THE balancedmysql DRIVER. A SPECIAL HOOK HAS BEEN INCLUDED THAT WILL PREVENT YOU FROM ACCIDENTILY MAKING INSTALLATIONS/UPGRADES WHILE 'balancedmysql' DRIVER IS ACTIVE.




Sample High Performance Setup:
Posted Image
(source: http://dev.mysql.com...s-scaleout.html)

What this script will do is randomly distribute select queries between the master and one or more slaves.

INSTALLATION:

Step 1: Upload the contents of the attached zip file to your server..

Step 2: In your conf_global.php set your sql driver to 'balancedmysql' and keep your existing mysql settings.

$INFO['sql_driver'] = 'balancedmysql';

Step 3:

In your /hooks/hpmysql_config.php file add the following lines toward the bottom to define your slave databases (make sure you keep the
driver set to mysql!) Be sure to fill in the correct host, username, and password.



$INFO['sql_slaves'] = Array (

// First read slave details
Array (
'name' => 'slave1', // REQUIRED!!!!
'weight' => 5, // (OPTIONAL)
'sql_driver' => 'mysql',
'sql_host' => 'localhost',
'sql_database' => '',
'sql_user' => '',
'sql_pass' => '',
'sql_tbl_prefix' => ''
),

// Second read slave details
Array (
'name' => 'slave2', // REQUIRED!!!!
'weight' => 3, // (OPTIONAL)
'sql_driver' => 'mysql',
'sql_host' => 'localhost',
'sql_database' => '',
'sql_user' => '',
'sql_pass' => '',
'sql_tbl_prefix' => ''
)

);




The name field (not optional) is a key that will identify the slave mysql server in the database driver, and the weight field
is a positive INTEGER that is used to control how often the particular slave is chosen by random selection.

For example, if slave "apple" has weight = 1 and slave "banana" has weight = 9 then think of it like putting 1 apple and 9
bananas in a basket. Choosing the server will be as simple as drawing one item from the basket.

This new addition will allow you to route all select queries to one or more slaves or even balance randomly among all available
servers.



Step 4: Additional configuration items

Now some other very important configuration items. The first configuration item is 'read_selection', which allows you to define
what servers to balance traffic across. Note that your master server will ALWAYS be used for deletions, inserts, create tables,
etc.

$INFO['read_selection'] Possible Values


$INFO['read_selection'] = "random"; // When issuing read (select) queries, choose a random server from among all slaves

-or-

$INFO['read_selection'] = "randomslave"; // When issuing read (select) queries, choose a random server from among all slaves

-or-

$INFO['read_selection'] = "master|slave2|slave3"; // Choose randomly between the master server, slave2, and slave3.
These are the names you have given to each of the slaves when setting
them up in $INFO['sql_slaves']. Note that "master" is reserved






$INFO['read_weighted'] (OPTIONAL)



$INFO['read_weighted'] = true; // Apply weights when choosing a random read server

-or-

$INFO['read_weighted'] = false; // Do not apply weights when choosing a random read server (any configured weights will be
ignored and a purely random server will be chosen)





$INFO['master_weight'] (OPTIONAL)



$INFO['master_weight'] = 5; // Apply a weight to the master server






So putting this all together, your /hooks/hpmysql_config.php might look like this:




$INFO['read_selection'] = "randomslave";
$INFO['read_weighted'] = true;
$INFO['master_weight'] = 2; // this won't do anything with 'randomslave' enabled

// First read slave details
Array (
'name' => 'slave1', // REQUIRED!!!!
'weight' => 5, // (OPTIONAL)
'sql_driver' => 'mysql',
'sql_host' => 'localhost',
'sql_database' => '',
'sql_user' => '',
'sql_pass' => '',
'sql_tbl_prefix' => ''
),

// Second read slave details
Array (
'name' => 'slave2', // REQUIRED!!!!
'weight' => 3, // (OPTIONAL)
'sql_driver' => 'mysql',
'sql_host' => 'localhost',
'sql_database' => '',
'sql_user' => '',
'sql_pass' => '',
'sql_tbl_prefix' => ''
)



What's New in Version 1.1.3 (See full changelog)

  • Modified driver to not rely on changes to conf_global.php
  • Updated documentation to warn against updating/installing with the balancedmysql driver
  • Added special hook that will prevent users from installing\upgrading while the "balancedmysql" driver is active




I am making this free as is in case anybody else needs it. It needs more work distributing queries consistently to the same backend for a user to be more scalable. Right now queries are just randomly sent to different servers.
    • Lucky Star likes this

We have an auto-scaling platform setup via scalr.net in which we have one master and slaves open up as needed.

I want write behavior to the master and all other to the slave if a slave has open up (which is only defined by a certain single connection string that falls back to the master if no slave present).

 

Would that situation work with your driver?

Hi Matt, I love this and it is greatly needed.

 

I am getting an error when I visit the reports page

 

Call to a member function join_com_permissions() on a non-object in htdocs/admin/applications/core/sources/reportLibrary.php on line 313, referer: http://domain.com/fo...-announcements/

Please use the support topic for assistance > http://community.inv...e-mysql-driver/ :)


Other files you may be interested in ..





55 user(s) are online (in the past 30 minutes)

15 members, 37 guests, 2 anonymous users


+RoboHead, +bix, +Ivan Kudinov, +Marcin Nasiadek_439226, +darkmesaia, teez, +Janyour, +jhuberus, +Stefano Slobodiuk, +Miles360x, +pezza, NEFords, ChrisVIPSZONE, +Nicki Boards, +Sefket, Google (1)