fix: optimize performance for platform-wide querying #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Optimize Clickhouse database schema for platform-wide and user-specific querying of multi-tenant audit log data.
Details
As we began running performance tests against the activity apiserver, we noticed that platform-wide queries were performing drastically worse than tenant-level queries. See datum-cloud/enhancements#536 (comment) for a comparison.
This was a result of our initial schema being designed to order data by tenant resulting in platform-wide queries scanning the entire data set instead of being able to skip over irrelevant rows.
This change makes several adjustments to the schema to improve querying performance.
I've modified the
001_initial_schema.sqlmigration instead of adding a new migration because this service has not been released yet.This PR also contains a few other related changes:
stagefrom the schema and the querying interface since we're only collecting theResponseCompletestage from the system.I also included a few unrelated changes:
Performance test results
Previous Clickhouse schema
This shows a performance test that was run against the activity system that was focused on tenant-level querying. The graphs show that the activity api would struggle with a small number of platform-level queries (~4 RPS) and queries would immediately begin timing out.
New optimized Clickhouse schema
This performance test demonstrates the improvements that were made after the new schema was applied. The graphs show that the performance test was able to reach significantly higher throughout ( ~40 RPS) before queries would begin to time out.
Resources
Relates to datum-cloud/enhancements#536