MySQL vs Redis (Concurrent Connections)

Posted on April 29, 2017 at 2:25 pm

I decided to test MySQL and Redis to know how many concurrent connections they can handle in a single dedicated server used as web server. I used Nginx 1.12.0, PHP 7.0.18 (PHP7.0-FPM), MySQL 15.1 Distrib 10.1.22-MariaDB, Redis 3.2.8 and Loader.io to simulate concurrent connections. The dedicated server has 32GB RAM DDR3, Intel(R) Xeon(R) CPU E5-1650 @ 3.20GHz with 12 cores, 250GB SSD HDD and 250 MB/s bandwidth. I tweaked the sysctl.conf in the server like in this post: Optimize Linux Sysctl.conf Parameters

Testing Read Operations

MySQL Read – 1000 Concurrent Connections

select * from users where id = 1

Redis Read – 1000 Concurrent Connections

$redis->get("user-id-1");

MySQL Read – 2000 Concurrent Connections

select * from users where id = 1

Redis Read – 2000 Concurrent Connections

$redis->get("user-id-1");

MySQL Read – 3000 Concurrent Connections

select * from users where id = 1

The response counts is same as for 2000 concurrent connections.

Redis Read – 3000 Concurrent Connections

$redis->get("user-id-1");

The response counts decreased to 369,214.

Testing Write Operations

MySQL Write – 1000 Concurrent Connections

update users set email = '123@aaa.com' where id = 1

The MySQL server crashed after a few seconds

Redis Write – 1000 Concurrent Connections

$redis->set("user-id-1", "123456"); echo $redis->get("user-id-1");

Redis Write – 2000 Concurrent Connections

$redis->set("user-id-1", "123456"); echo $redis->get("user-id-1");

Redis Write – 3000 Concurrent Connections

$redis->set("user-id-1", "123456"); echo $redis->get("user-id-1");

The response counts decreased to 362,860.

Redis Write – 4000 Concurrent Connections

$redis->set("user-id-1", "123456"); echo $redis->get("user-id-1");

The response counts decreased to 246,070.

Conclusions

As you can see from the graphs, MySQL (with MariaDB) is pretty good at handling read operations, it handled 2000 concurrent connections and performed better than Redis in terms of response counts (1,308,200 vs 834,232) and response time (89ms vs 136ms). Redis performed much better at handling write operations, MySQL crashed with 1000 concurrent connections, while Redis handled 1000\2000 concurrent connections without problems.

My conclusion, based on these tests, is that MySQL is very good for read-only operations (better than Redis), while Redis is very good to handle write operations (it handled 2000 concurrent connections perfectly). About stability, I noticed that MySQL and Redis performed good at 1000\2000 concurrent connections for read operations (MySQL wins), while Redis performed perfectly at 1000\2000 concurrent connections for write operations too. So my conclusion is that a single dedicated server with 32GB RAM and a good Intel Xeon processor, used as web server with Nginx, PHP7, MySQL and Redis, can handle up to 1000\2000 (I would say 1000) concurrent connections maintaining stability and a good response time. More than 2000 concurrent connections it degrades a lot and becomes unstable.

Receive updates via email

Other Posts

Updated Posts