Skip to content

Avoid loading Project and Snippet from initializers

Matt Kasa requested to merge mk-snippets-schema-load into master

What does this MR do and why?

While investigating database CPU saturation I found that we access and therefore load schema for 11 tables during application boot, among them are Project and Snippet, which can be avoided by using symbols instead of classes for SUPPORTED_TYPES in Gitlab::Pagination::Keyset.

The result is a decrease in database queries at boot, a decrease in files loaded, and an improvement in application boot time.

Results

Before (10 samples):
bash -c 'bundle exec rake environment &>/dev/null'  6.25s user 2.60s system 89% cpu 9.840 total
bash -c 'bundle exec rake environment &>/dev/null'  6.25s user 2.53s system 92% cpu 9.530 total
bash -c 'bundle exec rake environment &>/dev/null'  6.28s user 2.53s system 88% cpu 9.978 total
bash -c 'bundle exec rake environment &>/dev/null'  6.31s user 2.51s system 93% cpu 9.476 total
bash -c 'bundle exec rake environment &>/dev/null'  6.43s user 2.52s system 92% cpu 9.690 total
bash -c 'bundle exec rake environment &>/dev/null'  6.25s user 2.54s system 90% cpu 9.724 total
bash -c 'bundle exec rake environment &>/dev/null'  6.29s user 2.50s system 93% cpu 9.445 total
bash -c 'bundle exec rake environment &>/dev/null'  6.24s user 2.51s system 92% cpu 9.477 total
bash -c 'bundle exec rake environment &>/dev/null'  6.28s user 2.53s system 92% cpu 9.484 total
bash -c 'bundle exec rake environment &>/dev/null'  6.48s user 2.53s system 92% cpu 9.743 total
After (10 samples):
bash -c 'bundle exec rake environment &>/dev/null'  6.12s user 2.55s system 91% cpu 9.514 total
bash -c 'bundle exec rake environment &>/dev/null'  6.40s user 2.52s system 93% cpu 9.552 total
bash -c 'bundle exec rake environment &>/dev/null'  6.25s user 2.52s system 92% cpu 9.480 total
bash -c 'bundle exec rake environment &>/dev/null'  6.44s user 2.52s system 90% cpu 9.907 total
bash -c 'bundle exec rake environment &>/dev/null'  6.15s user 2.52s system 93% cpu 9.312 total
bash -c 'bundle exec rake environment &>/dev/null'  6.25s user 2.52s system 92% cpu 9.516 total
bash -c 'bundle exec rake environment &>/dev/null'  6.13s user 2.53s system 88% cpu 9.782 total
bash -c 'bundle exec rake environment &>/dev/null'  6.16s user 2.51s system 92% cpu 9.394 total
bash -c 'bundle exec rake environment &>/dev/null'  6.27s user 2.53s system 92% cpu 9.506 total
bash -c 'bundle exec rake environment &>/dev/null'  6.24s user 2.52s system 92% cpu 9.438 total

Average boot time:

  • 9.6387 seconds
  • 9.5401 seconds

Tables accessed during boot:

 licenses
 application_settings
-snippets
-projects
 users
 schema_migrations
 geo_nodes
 shards
 postgres_partitioned_tables
 postgres_partitions
 loose_foreign_keys_deleted_records

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports