nextcloud / nextcloud/server

Support MariaDB/MySQL `NO_CACHE` flag for `filecache` SELECT queries

Ouverte
#50,737 6 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

1. to develop enhancement feature: database performance 🚀
Langage dominant
PHP
Étoiles
36.9k
Forks
5.2k
Merge moyen
2 j 3 h
PR mergées (30 j)
713

Description

Background

We're operating a Nextcloud server with up to 800 active users in the last 5 minutes. Recently, we have run into performance bottlenecks.

We found that while the CPU and available memory are not an issue, the load on the CPU was capped at around 25% (see Grafana screenshot in details). This resulted in a degraded user experience, for example waiting times of up to 30s when switching file directories.

When looking into the MariaDB process list, there were dozens or sometimes hundreds of SELECT and UPDATE statements waiting for the lock of the filecache table. With almost 1000 UPDATE queries per second, it seems that obtaining/switching the query cache mutex is the limiting factor holding back the system.

Image

To alleviate the issue, we made the query cache optional with SET GLOBAL query_cache_type = 2;. This is obviously a bad idea in some or even many cases, as this increases the load on the database immediately. However, in our case the server had enough hardware reserves and the page load speed increased.

However, the CPU load increased more than is actually necessary, as we basically disabled the query cache for most if not all queries. We quickly fixed this by hardcoding a SELECT SQL_CACHE ... into the getUserGroups() method of the user_saml app, which immediately reduced about 50% of the CPU load (we have really a lot of users and groups).

Suggestion

A better approach than activating the query cache for each single query would be to use the SQL_NO_CACHE statement for SELECT queries in the filecache table with query_cache_type = 1;. This could be activated with a new entry in the config.php.

There is a caveat: we have not yet fully validated this finding. At this point it seems highly likely and I'm very much interested in feedback.

How to use GitHub
  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par examiner les chemins de requêtes SELECT de filecache et la configuration config.php mentionnée dans l’issue ; l’exemple getUserGroups() montre le comportement prévu du cache de requêtes. Confirmez comment MariaDB/MySQL gèrent SQL_NO_CACHE pour ces requêtes, puis définissez l’achèvement comme une implémentation configurable avec une validation ou des tests couvrant les requêtes filecache résultantes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
mariadb, mysql, php
Domaine
backend, databases, performance
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.