-
Notifications
You must be signed in to change notification settings - Fork 503
Slave Groups
A slave group is a group of slaves to which queries are distributed. In other words, all the slaves in the same slave group are load-balanced. Octopus does not load-balance between slaves across multiple slave groups.
Octopus picks slaves in a slave group using a round robin algorithm same as the Multiple Slaves scenario which does not utilize slave groups.
Slaves groups can be used concurrently with Sharding.
An usecase of slave groups is to distribute/completely seperate loads of SELECT queries from each part of an application to seperate databases.
For example, consider that you have a Web application consists of the A part which serves Web pages for users, and the B part which serves Web pages for admins.
If you just send heavy SELECT queries while serving for admins, they will degrade performance serving Web pages for other users.
This is where slave groups come in.
You can configure seperate slave groups for A and B to make them not affect each other's performance.
You can configure any number of slave groups in shards.yml.
To configure two slave groups slave_group_a and slave_group_b for the development environment, you need shards.yml like:
octopus:
replicated: true
environments:
- development
development:
slave_group_a:
slave1:
# ...
slave2:
# ...
slave_group_b:
slave3:
# ...
slave4:
# ...
Then:
- In
Octopus.using(slave_group: :slave_group_a)blocks, all theSELECTqueries are distributed betweenslave1andslave2 - In
Octopus.using(slave_group: :slave_group_b)blocks, all theSELECTqueries are distribuetd betweenslave3andslave4 - Without
using, all theSELECTqueries go to the development database configured indatabase.yml
To use slave groups with sharding, you need shards.yml like:
octopus:
replicated: true
environments:
- development
development:
shard_1:
slave_group_a:
slave1:
# ...
slave2:
# ...
slave_group_b:
slave3:
# ...
slave4:
# ...
shard_2:
slave_group_a:
slave5:
# ...
Then:
- In
Octopus.using(shard: :shard_1, slave_group: :slave_group_a)blocks, all theSELECTqueries are distributed betweenslave1andslave2 - In
Octopus.using(shard: :shard_1, slave_group: :slave_group_b)blocks, all theSELECTqueries are distribuetd betweenslave3andslave4 - Without
using, all theSELECTqueries go to the development database configured indatabase.yml