Skip to content

API JSON caching for tags endpoint [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Robert May requested to merge tags-api-performance into master

What does this MR do?

Caches generated JSON for objects, in this instance tags, and bypasses the Grape output to return it directly. This is basically fragment caching but for Grape::Entity objects.

Cuts about 100ms off rendering the tags endpoint locally. You can see the difference in the examples below; it removes some DB queries and what looks like a single Gitaly call, so I expect this will have a bigger impact on production under load 😄

This is a generic change which we can then apply to other endpoints with minimal effort.

Related #299529 (closed)

Feature Flag

:api_caching_tags

Uncached

{
  "time": "2021-02-23T19:07:08.424Z",
  "severity": "INFO",
  "duration_s": 0.30612,
  "db_duration_s": 0.0231,
  "view_duration_s": 0.28302,
  "status": 200,
  "method": "GET",
  "path": "/api/v4/projects/4/repository/tags.json",
  "params": [],
  "host": "localhost",
  "remote_ip": "127.0.0.1",
  "ua": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",
  "route": "/api/:version/projects/:id/repository/tags",
  "user_id": 1,
  "username": "root",
  "queue_duration_s": 0.073815,
  "gitaly_calls": 2,
  "gitaly_duration_s": 0.151372,
  "db_count": 47,
  "db_write_count": 0,
  "db_cached_count": 19,
  "cpu_s": 0.25497,
  "correlation_id": "01EZ84KDWCAG3G17E0B0X0VABB",
  "meta.user": "root",
  "meta.project": "root/gitlab-mirror",
  "meta.root_namespace": "root",
  "meta.caller_id": "/api/:version/projects/:id/repository/tags",
  "meta.remote_ip": "127.0.0.1",
  "meta.feature_category": "source_code_management"
}

Cached

{
  "time": "2021-02-23T19:07:09.892Z",
  "severity": "INFO",
  "duration_s": 0.18786,
  "db_duration_s": 0.00343,
  "view_duration_s": 0.18443,
  "status": 200,
  "method": "GET",
  "path": "/api/v4/projects/4/repository/tags.json",
  "params": [],
  "host": "localhost",
  "remote_ip": "127.0.0.1",
  "ua": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",
  "route": "/api/:version/projects/:id/repository/tags",
  "user_id": 1,
  "username": "root",
  "queue_duration_s": 0.066894,
  "gitaly_calls": 1,
  "gitaly_duration_s": 0.125807,
  "db_count": 5,
  "db_write_count": 0,
  "db_cached_count": 0,
  "cpu_s": 0.137,
  "correlation_id": "01EZ84KFE5GWBXPTQMW2C8234S",
  "meta.user": "root",
  "meta.project": "root/gitlab-mirror",
  "meta.root_namespace": "root",
  "meta.caller_id": "/api/:version/projects/:id/repository/tags",
  "meta.remote_ip": "127.0.0.1",
  "meta.feature_category": "source_code_management"
}

Screenshots (strongly suggested)

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 🤖 GitLab Bot 🤖

Merge request reports