Home > Backend Development > PHP Tutorial > Performance comparison between PhpRedis and Predis (example)

Performance comparison between PhpRedis and Predis (example)

藏色散人
Release: 2023-04-05 16:16:02
Original
5062 people have browsed it

The discussion about the performance comparison between PhpRedis and Predis has been around for a long time. In this article, I will introduce to you how to measure the performance of these libraries based on the most popular framework Laravel.

Performance comparison between PhpRedis and Predis (example)

PhpRedis is a PHP extension for communicating with Redis storage. (Related recommendations: Redis Tutorial)

Predis is an alternative to PhpRedis on pure PHP and does not require any additional C extensions by default, but can optionally be paired with phpiredis.

I tested these two libraries using high-load project code, with about 10K online users.

Test environment:

Operating system: Ubuntu 18.04.2 LTS x86_64

CPU: Intel i7-6820HQ (8) @ 3.600GHz

Memory: 32 gb

PHP: v7.2.15

Laravel: v5.7.25

MySQL: MySQL v5.7

Redis: v5.0.3

PhpRedis: v4.2.0

Predis: v1.1.1

The script generates a cache from the database and stores the convincing model in Redis.

By default, Laravel does not support custom serializers for Redis, but I used the Laravel Lodash package to achieve this.

Result:

Predis (serializer: php)
Execution time: 00:05:53.0355
Cache storage used: 936.92MB
— — — — — — — — — — — — — — — — — — 
Predis (serializer: igbinary)Execution time: 00:07:45.2460
Cache storage used: 342.66MB
— — — — — — — — — — — — — — — — — 
Predis (serializer: igbinary, with ext-phpiredis)Execution time: 00:07:51.9046
Cache storage used: 342.66MB
— — — — — — — — — — — — — — — — — 
PhpRedis (serializer: php)Execution time: 00:01:36.9863
Cache storage used: 936.75MB
— — — — — — — — — — — — — — — — — 
PhpRedis (serializer: igbinary)Execution time: 00:01:37.3176
Cache storage used: 342.66MB
Copy after login

Note:

Execution time:执行时间
Cache storage used:缓存存储
Copy after login

Conclusion:

The speed of PhpRedis is about x6 times. Using the igbinary serializer can reduce the size of stored data by about 3 times. If you install Redis on a different machine, reducing network traffic will speed things up significantly.

The above is the detailed content of Performance comparison between PhpRedis and Predis (example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template