Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scale MySQL with multiple machines?

I have a web app running LAMP. We recently have an increase in load and is now looking at solutions to scale. Scaling apache is pretty easy we are just going to have multiple multiple machines hosting it and round robin the incoming traffic.

However, each instance of apache will talk with MySQL and eventually MySQL will be overloaded. How to scale MySQL across multiple machines in this setup? I have already looked at this but specifically we need the updates from the DB available immediately so I don't think replication is a good strategy here? Also hopefully this can be done with minimal code change.

PS. We have around a 1:1 read-write ratio.

like image 832
erotsppa Avatar asked Apr 24 '09 14:04

erotsppa


People also ask

Can MySQL handle multiple connections?

By default 151 is the maximum permitted number of simultaneous client connections in MySQL 5.5. If you reach the limit of max_connections you will get the “Too many connections” error when you to try to connect to your MySQL server. This means all available connections are in use by other clients.

How many TPS can MySQL handle?

MySQL reaches maximum efficiency for 128 user threads, with its max TPS (1.8 million) and low latency (70 microseconds).

Can MySQL be Sharded?

Monolithic databases such as MySQL, Oracle, PostgreSQL, Amazon Aurora, etc. do not support automatic sharding. As the data increases the complexity to handle MySQL sharding becomes an additional development task.


2 Answers

There're only two strategies: replication and sharding. Replication comes often in place when you have less write and much read traffic, so you can redirect the reads to many slaves, with the pitfall of lots of replication traffic with the time and a probability for inconsitency.

With sharding you shard your database tables across multiple machines (called functional sharding), which makes especially joins much harder. If this doenst fit anymore you also need to shard you rows across multiple machines, but this is no fun and depends a sharding layer implemented between you application and the database.

Document oriented databases or column stores do this work for you, but they are currently optimized for OLAP not for OLTP.

like image 52
Mork0075 Avatar answered Sep 26 '22 08:09

Mork0075


Depends on the application backend (i.e. how the PKs, transactions and insert IDs are handled), you might consider MASTER-MASTER replication with different auto_increment setups. This can be tricky and needs to be thoroughly tested but it can work.

Also, in new MySQL 5.6 there is a GTID (Global Transaction Identifier) that generally helps a lot in keeping the replication in sync, especially in this scenario.

like image 34
warden Avatar answered Sep 22 '22 08:09

warden