Skip to content
Permalink
Browse files

bug #30351 Fix getItems() performance issue with RedisCluster (php-re…

…dis) (andrerom)

This PR was merged into the 3.4 branch.

Discussion
----------

Fix getItems() performance issue with RedisCluster (php-redis)

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | TBD
| License       | MIT

On any kind of multi loads, including tags loading where it's always the case, current code leads to an explosion of Redis lookups affecting performance on RedisCluster _(as it does not support pipeline)_.

This backports the code for mget() usage from 4.x in order to fix it.
It's done with one small improvment which would also be relevant for 4.x, only using pipeline on cluster on predis as mget is more efficient (ref redis doc).

Commits
-------

178506e Fix getItems() performance issue with RedisCluster (php-redis)
  • Loading branch information...
fabpot committed Feb 23, 2019
2 parents 83fec23 + 178506e commit 4cc10062e23acb4c745cb298ad43cc0b51674ab9
Showing with 16 additions and 5 deletions.
  1. +16 −5 src/Symfony/Component/Cache/Traits/RedisTrait.php
@@ -169,18 +169,29 @@ public static function createConnection($dsn, array $options = [])
*/
protected function doFetch(array $ids)
{
if ($ids) {
if (!$ids) {
return [];
}
$result = [];
if ($this->redis instanceof \Predis\Client && $this->redis->getConnection() instanceof ClusterInterface) {
$values = $this->pipeline(function () use ($ids) {
foreach ($ids as $id) {
yield 'get' => [$id];
}
});
foreach ($values as $id => $v) {
if ($v) {
yield $id => parent::unserialize($v);
}
} else {
$values = array_combine($ids, $this->redis->mget($ids));
}
foreach ($values as $id => $v) {
if ($v) {
$result[$id] = parent::unserialize($v);
}
}
return $result;
}
/**

0 comments on commit 4cc1006

Please sign in to comment.
You can’t perform that action at this time.