Shopware 6: Redis but still slow?

TIL: If you are using Redis and the RedisTagAwareAdapter, which is the default if you want to use tags while caching, then you MUST use a max memory setting which either starts with volatile- or is noeviction.

https://github.com/symfony/symfony/blob/1d68ce9b802701e9fd0d0f13d8610f816e2c67b1/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php#L88

throw new LogicException(sprintf('Redis maxmemory-policy setting "%s" is *not* supported by RedisTagAwareAdapter, use "noeviction" or "volatile-*" eviction policies.', $eviction));

That alone is not a reason to write a blog post about, but this is:

DIE IST SO EIN UHRENSOHN DIESE MELDUNG. Die wird irgendwie mute-gecatcht und niemand sagt dir warum deine Seite Scheiß Langsam ist

Shopware Slack, Joshua Behrens

Roughly translated that means:

This is such a son of a watch, this message. It is catched somewhere and muted and no one is telling you why the page is so fucking slow

Shopware Slack, Joshua Behrens

It is a german joke, because Uhrensohn (son of a watch) and Hurensohn (son of a bitch) is only a typo away.

TL;DR: If you are running redis and it feels slow, check, wether your Symfony throws muted exceptions due to your max-memory setting and therefore your redis doesn’t do anything.

And just to be sure and give more context: Sexwork is work as well and needs more respect.

I wanted to stop here. But no, Joshua dig into his knowledge base and got to more gems, first the link which is in the first line into the Symfony docs and the second is, that the error is muted here:

https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php#L174-L175

public function commit(): bool
{
    $ok = true;
    $byLifetime = (self::$mergeByLifetime)($this->deferred, $this->namespace, $expiredIds, $this->getId(...), $this->defaultLifetime);
    $retry = $this->deferred = [];

    if ($expiredIds) {
        try {
            $this->doDelete($expiredIds);
        } catch (\Exception $e) {
            $ok = false;
            CacheItem::log($this->logger, 'Failed to delete expired items: '.$e->getMessage(), ['exception' => $e, 'cache-adapter' => get_debug_type($this)]);
        }
    }
    foreach ($byLifetime as $lifetime => $values) {
        try {
            $e = $this->doSave($values, $lifetime);
        } catch (\Exception $e) {
        }
        if (true === $e || [] === $e) {
            continue;
        }
        if (\is_array($e) || 1 === \count($values)) {
            foreach (\is_array($e) ? $e : array_keys($values) as $id) {
                $ok = false;
                $v = $values[$id];
                $type = get_debug_type($v);
                $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
                CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);
            }
        } else {
            foreach ($values as $id => $v) {
                $retry[$lifetime][] = $id;
            }
        }
    }

    // When bulk-save failed, retry each item individually
    foreach ($retry as $lifetime => $ids) {
        foreach ($ids as $id) {
            try {
                $v = $byLifetime[$lifetime][$id];
                $e = $this->doSave([$id => $v], $lifetime);
            } catch (\Exception $e) {
            }
            if (true === $e || [] === $e) {
                continue;
            }
            $ok = false;
            $type = get_debug_type($v);
            $message = sprintf('Failed to save key "{key}" of type %s%s', $type, $e instanceof \Exception ? ': '.$e->getMessage() : '.');
            CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e instanceof \Exception ? $e : null, 'cache-adapter' => get_debug_type($this)]);
        }
    }

    return $ok;
}

Thank you very much Joshua!

Leave a Reply

Discover more from Winkelwagen

Subscribe now to keep reading and get access to the full archive.

Continue reading