CounterAttribute concern to increment counters using Redis
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
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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