Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on materialized views #13

Closed
wants to merge 2 commits into from
Closed

Conversation

thokra-nav
Copy link
Contributor

@thokra-nav thokra-nav commented Mar 6, 2024

Using materialized views will create a copy of the data in a preprocessed and stored way for postgresql to do more efficient queries against.

Some quick numbers from my local setup, non-scientific, using NAV data:

Query Before After QI Avg
MonthlyCostForTeam 236.52ms 514μs 2.288s
DailyEnvCostForTeam 16.9ms 14.96ms -
ResourceUtilizationRangeForTeam 254.88ms 462μs 1.439s

QI Avg: Average execution time as reported by Query Insights for live NAV environment

Pros

  • Potential way quicker queries (moving time to updating the view)

Cons

  • Extra storage
  • Must remember to refresh views when source changes
  • A bit more clunky to change queries if the source needs a change

Some more testing needs to be done to verify the usefulness of each materialized view.
Need to create trigger when the source changes.

@thokra-nav thokra-nav force-pushed the mat_cost_resources branch from de06ddc to cd9be67 Compare March 6, 2024 16:11
@thokra-nav
Copy link
Contributor Author

Laget litt benchmark for de forskjellige spørringene, er litt mer jobb å gjøre:

                                             │   before.txt    │               after.txt                │
                                             │     sec/op      │    sec/op      vs base                 │
ResourceUtilizationRangeForTeam_exists-8        80314.0µ ± 33%    100.3µ ±  7%   -99.88% (p=0.000 n=10)
ResourceUtilizationRangeForTeam_not_exists-8      283.6µ ±  1%    104.9µ ±  4%   -63.00% (p=0.000 n=10)
MonthlyCostForApp-8                              2005.1µ ± 14%    159.4µ ±  5%   -92.05% (p=0.000 n=10)
MonthlyCostForTeam-8                           136728.1µ ±  1%    172.2µ ±  4%   -99.87% (p=0.000 n=10)
DailyEnvCostForTeam-8                             268.0µ ±  8%    139.6µ ±  5%   -47.90% (p=0.000 n=10)
DailyEnvCostForTeam_with_env-8                    7.402m ±  6%    7.755m ±  2%    +4.76% (p=0.007 n=10)
ResourceUtilizationRangeForTeam-8              103422.0µ ±  9%    155.9µ ± 26%   -99.85% (p=0.000 n=10)
ResourceUtilizationRangeForApp-8                15345.6µ ±  4%    167.2µ ±  5%   -98.91% (p=0.000 n=10)
ResourceUtilizationForTeam-8                   200905.8µ ±  3%    900.7µ ±  1%   -99.55% (p=0.000 n=10)
SpecificResourceUtilizationForTeam-8              933.1µ ±  9%   2413.5µ ±  3%  +158.65% (p=0.000 n=10)
AverageResourceUtilizationForTeam-8              47.553m ±  7%    2.740m ±  2%   -94.24% (p=0.000 n=10)

@thokra-nav
Copy link
Contributor Author

Fra datasettet jeg har, som tilsvarer NAV 6. mars 2024, så er følgende disk i bruk:

Tabell/View Størrelse
cost 627 MB
cost_monthly_team* 424 kB
cost_monthly_app* 12 MB
cost_daily_team* 317 MB
resource_utilization_metrics 6650 MB
resource_team_range* 40 kB
resource_app_range* 800 kB
resource_utilization_team* 361 MB
  • Materialized views

Så for cost er det en økning på ~50%, mens det er ~5% for resource_utilization_metrics

Data hentet via

SELECT pg_size_pretty(pg_total_relation_size('"public"."<table/view>"'));`

@thokra-nav thokra-nav closed this Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant