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

Add ng-http-caching request debouncing and caching #2171

Merged
merged 17 commits into from
Nov 20, 2024

Conversation

hudson-newey
Copy link
Member

@hudson-newey hudson-newey commented Nov 18, 2024

Add ng-http-caching request debouncing and caching

Changes

  • Replaces ng-cashew with ng-http-caching for request batching and improve caching
    • Allows us to only emit one GET request (by merging observables) if multiple requests contact the same endpoint
  • Adds unit tests to ensure the correct requests clear the http cache
  • Adds tests to the admin cache settings page

Issues

Fixes: #2159

Final Checklist

  • Assign reviewers if you have permission
  • Assign labels if you have permission
  • Link issues related to PR
  • Ensure project linter is not producing any warnings (npm run lint)
  • Ensure build is passing on all browsers (npm run test:all)
  • Ensure CI build is passing
  • Ensure docker container is passing (docs)

@hudson-newey hudson-newey self-assigned this Nov 18, 2024
Copy link
Contributor

github-actions bot commented Nov 18, 2024

Size Change: +311 B (+0.01%)

Total Size: 3.59 MB

Filename Size Change
dist/workbench-client/browser/index.html 4.79 kB +1 B (+0.02%)
dist/workbench-client/browser/main-NJJYAUE5.js 0 B -1.13 MB (removed) 🏆
dist/workbench-client/server/main.js 1.94 MB +218 B (+0.01%)
dist/workbench-client/browser/main-IF5TMIGN.js 1.13 MB +1.13 MB (new file) 🆕
ℹ️ View Unchanged
Filename Size
dist/workbench-client/browser/@ecoacoustics/web-components/abstractComponent-gI12hGSz.js 6.49 kB
dist/workbench-client/browser/@ecoacoustics/web-components/assets/buffer-builder-processor-BhnxGUx8.js 1.16 kB
dist/workbench-client/browser/@ecoacoustics/web-components/assets/high-accuracy-time-processor-BevUJNwo.js 354 B
dist/workbench-client/browser/@ecoacoustics/web-components/attributes-DayhhJl-.js 313 B
dist/workbench-client/browser/@ecoacoustics/web-components/class-map-BJ2wQJjp.js 675 B
dist/workbench-client/browser/@ecoacoustics/web-components/classification-CIken_-O.js 128 B
dist/workbench-client/browser/@ecoacoustics/web-components/components.js 116 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/axes.js 3.19 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/classification.js 1.77 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/data-source.js 63.3 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/decision.js 246 B
dist/workbench-client/browser/@ecoacoustics/web-components/components/help-dialog.js 2.61 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/helpers/constants/contextTokens.js 209 B
dist/workbench-client/browser/@ecoacoustics/web-components/components/indicator.js 1.12 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/info-card.js 1.59 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/logger.js 418 B
dist/workbench-client/browser/@ecoacoustics/web-components/components/media-controls.js 38.2 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/progress-bar.js 1.13 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/spectrogram.js 226 B
dist/workbench-client/browser/@ecoacoustics/web-components/components/verification-grid-settings.js 1.48 kB
dist/workbench-client/browser/@ecoacoustics/web-components/components/verification-grid-tile.js 408 B
dist/workbench-client/browser/@ecoacoustics/web-components/components/verification-grid.js 396 B
dist/workbench-client/browser/@ecoacoustics/web-components/components/verification.js 1.29 kB
dist/workbench-client/browser/@ecoacoustics/web-components/consume-D2RSb1qY.js 614 B
dist/workbench-client/browser/@ecoacoustics/web-components/context-request-event-Bc4uem__.js 239 B
dist/workbench-client/browser/@ecoacoustics/web-components/custom-elements.json 9.74 kB
dist/workbench-client/browser/@ecoacoustics/web-components/decision-BcFlFKnV.js 1.49 kB
dist/workbench-client/browser/@ecoacoustics/web-components/decision-BvBt2W07.js 4.03 kB
dist/workbench-client/browser/@ecoacoustics/web-components/decorators-zsXcIcN9.js 516 B
dist/workbench-client/browser/@ecoacoustics/web-components/directive-B76A7YXI.js 343 B
dist/workbench-client/browser/@ecoacoustics/web-components/if-defined-YSzpD1Zv.js 178 B
dist/workbench-client/browser/@ecoacoustics/web-components/keyboard-c8_TPhbG.js 117 B
dist/workbench-client/browser/@ecoacoustics/web-components/lit-element-CNpxFSzF.js 6.77 kB
dist/workbench-client/browser/@ecoacoustics/web-components/map-D8heArFD.js 184 B
dist/workbench-client/browser/@ecoacoustics/web-components/property-cctOu2Be.js 639 B
dist/workbench-client/browser/@ecoacoustics/web-components/provide-Ce8Vz0mw.js 1.18 kB
dist/workbench-client/browser/@ecoacoustics/web-components/query-sbFTBDPt.js 340 B
dist/workbench-client/browser/@ecoacoustics/web-components/signal-watcher-CbQ3umdl.js 377 B
dist/workbench-client/browser/@ecoacoustics/web-components/signals-core.module-BUxpRF5s.js 1.59 kB
dist/workbench-client/browser/@ecoacoustics/web-components/spectrogram-CYEtaRIV.js 168 kB
dist/workbench-client/browser/@ecoacoustics/web-components/state-DJrhCpxL.js 203 B
dist/workbench-client/browser/@ecoacoustics/web-components/verification-grid-CT6ze_9z.js 12.4 kB
dist/workbench-client/browser/@ecoacoustics/web-components/verification-grid-tile-CvcYjTk-.js 4.49 kB
dist/workbench-client/browser/@ecoacoustics/web-components/watch-D97VecW3.js 1.42 kB
dist/workbench-client/browser/@ecoacoustics/web-components/when-CDK1Tt5Y.js 168 B
dist/workbench-client/browser/assets/environment.json 555 B
dist/workbench-client/browser/assets/test-assets/index.html 21 B
dist/workbench-client/browser/manifest.json 147 B
dist/workbench-client/browser/polyfills-C5CKP5CH.js 12.4 kB
dist/workbench-client/browser/styles-ETV6J7SM.css 39.6 kB
dist/workbench-client/server/952.js 4.21 kB

compressed-size-action

@hudson-newey hudson-newey added enhancement New feature or request architecture Architectural changes to the software labels Nov 18, 2024
@hudson-newey hudson-newey marked this pull request as ready for review November 18, 2024 06:23
Copy link
Contributor

github-actions bot commented Nov 18, 2024

Unit Test Results

         6 files           6 suites   10m 50s ⏱️
24 180 tests 23 550 ✔️ 630 💤 0
24 402 runs  23 772 ✔️ 630 💤 0

Results for commit 55b8dfd.

♻️ This comment has been updated with latest results.

Copy link
Member

@atruskie atruskie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes.

Most importantly, I can't see what the default TTL is. Remember this is a performance optimisation task, not a caching task. We don't need to reinvent the browser's cache, so we should be using a short TTL.

Measure the performance of this change:

  • 2 pages
  • 4 TTLs: 0, 200ms, 10 seconds, 60 seocnds
  • 10 samples each

See if average load times change.

src/app/components/admin/settings/settings.component.ts Outdated Show resolved Hide resolved
Comment on lines 123 to 124
// TODO: we should do targeting cache invalidation and invalidate all cache
// keys that contain the item being deleted from cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand what this means

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was supposed to add a todo stating "instead of clearing the entire cache when a single item is updated, we should just delete that one item from the cache. However, when an model is updated/deleted, it may be used as an association to another model, meaning that we will have to invalidate the changed model, and any other models that reference the newly invalidated model".

However, since we have lowered the cache lifetime to one second and our caching is designed to reduce the impact of associations and N+1 queries, this is no longer a problem we have to worry about.

src/app/services/baw-api/baw-api.service.ts Outdated Show resolved Hide resolved
src/app/services/cache/cache-settings.ts Outdated Show resolved Hide resolved
src/app/services/cache/ngHttpCachingConfig.ts Show resolved Hide resolved
@hudson-newey
Copy link
Member Author

hudson-newey commented Nov 19, 2024

Methodology

Results were gathered using a docker container to replicate the production environment as close as possible.

The "Cooloola" "Annotation Search" page was used in all tests.

Before each testing round, the Cooloola annotation search page was loaded without recording the results so that all audio files would be recalled, and would minimise deviations in the tests due to server caching.

A new browser tab was used between each test to prevent potential v8 caching.

Network caching was disabled.


The starting page for the tests was the "Cooloola" project details page.

The "Cooloola" project details page would be hard-reloaded, and the "Search Annotations" menu item would be clicked.

Performance would be measured from the start of the menu's "click" event to the end of the annotation search page load.

Performance test results

Results are recorded in seconds

Cache lifetime 1 2 3 4 5 6 7 8 9 10 Average Std-Deviation
Baseline (without caching) 3.852 3.285 3.844 3.886 3.968 3.698 3.755 3.819 3.509 4.102 3.772 0.232
0ms (with debouncing) 3.370 3.134 4.048 3.225 3.664 3.935 3.370 2.731 3.496 3.410 3.438 0.383
200ms 2.830 2.614 2.801 3.436 3.676 3.232 3.086 3.200 3.339 3.274 3.149 0.322
10s 3.179 3.047 3.283 3.747 3.207 3.450 3.090 3.257 3.553 3.571 3.338 0.230
60s 3.478 3.397 3.341 3.152 3.191 2.997 3.182 2.681 3.426 3.331 3.218 0.239

@atruskie
Copy link
Member

From discussion of the results we can see that the actual cache part of this library has little to no effect on performance. TTL does not seem to matter either. The main win is the request de-duplication.

so the understanding here is:

  • debounce is effective at deduplicating requests for the same data on a page that is loading
  • TTL has no effect unless more data is requested later by a user

We're going to trial 10 second TTL with the hope that for anyone doing any kind of quickly successive actions, they'll see a benefit from the cache (like flicking through pages of results). Also at the same time, anyone doing anything on a page is likely to take more than 10 seconds, stale cache results should basically be a non-issue.

We'll do some more testing when #2160 is implemented. #2170 should also help.

@hudson-newey hudson-newey changed the title Add ng-http-caching request batching and caching Add ng-http-caching request debouncing and caching Nov 19, 2024
@hudson-newey hudson-newey merged commit 3ad116b into master Nov 20, 2024
14 checks passed
@hudson-newey hudson-newey deleted the http-batching-interceptor branch November 20, 2024 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Architectural changes to the software enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find http request debounce interceptor
2 participants