Almost all web developers know what is Redis. Redis is used by many web applications because it has a great performance to store our data in key-value pair format. But not many developers are familiar with Swoole, especially when they’re not using PHP as their main language. What is Swoole? And how we compare it with the Redis?
High Performance Programmatic Server for PHP with Async IO, Coroutines and Fibers. https://www.swoole.co.uk
Swoole is a PHP package built with C, where it offers a lot of features. Especially with the asynchronous tasks. In traditional PHP, there’s no way we run the codes asynchronously. However, we can achieve that async tasks using Swoole, with the support of coroutines. And there are other features as well.
Another feature that Swoole supports is called Swoole Table. Swoole table has very great performance when it comes to read/write operations with key-value pairs into the table. It claims that the read/write speed is up to 2 million per second. That number is fantastic!
So in this article, I’ll do some simple benchmark/comparison for read/write operations between Redis, Swoole Table, and local cache. Because I’m a Laravel developer, I’ll use the Laravel framework to do all the benchmarks.
- Initial Setup
- Write Operations
- Read Operations
- Read & Write Operations
#1 Initial Setup
First thing first, I’ll prepare the Laravel project for this benchmark. I’ll use Laravel version 8 with Laravel Octane installed. If you wonder why I’m using Laravel Octane to serve the application, it’s because the Swoole Table can only run if we’re serving the server on top of the Swoole server.
composer create-project laravel/laravel --prefer-dist whos-the-winner
Then inside the project, I installed the Laravel Octane and Predis packages.
composer require predis/predis
composer require laravel/octane