Skip to content

CounterAttribute concern to increment counters using Redis

Fabio Pitino requested to merge efficient-counters-redis into master

What does this MR do?

Related to #24469 (closed)

Problem

The problem is largely defined and discussed in #24469 (closed)

In short, concurrent updates to counters in statistics tables (e.g. project_statistics) often fail with query timeouts due to resource contention. We need to make updates more performant and non-blocking while still allow the values to be read correctly.

Solution

Let's use the ProjectStatistics model as an example. We want to efficiently update build_artifacts_size counter without incurring into query timeouts.

In this MR we introduce a new module ConterAttribute that brings counter attributes functionality. It provides a methods increment_counter that increments the counter on Redis and schedules a worker after some time to flush the increments to the database.

This way:

  • writes to the primary columns are only performed by the background worker
  • reads can be performed against the primary columns (with some delay in accuracy) or including pending increments

Feature flag

This MR introduces the changes behind efficient_counter_attribute feature flag, disabled by default.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Fabio Pitino

Merge request reports