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

fix: Heap usage request throttling #1450

Merged
merged 8 commits into from
Aug 25, 2023
Merged

Conversation

bmingles
Copy link
Contributor

@bmingles bmingles commented Aug 17, 2023

fixes #1439 - Heap usage code now guarantees that new requests won't be scheduled until all previous requests are complete.

Testing

I tested by shutting my Mac for ~2 hours and returning. Timings looks something like this:

Summary

image

It seems that requests still happen occasionally while sleeping. On Wake up, there were a few ticks resulting in "Unable to get heap usage" console errors. Then a prompt showed up indicating credentials had expired at which point requests start succeeding again.

Full Console Log

useAsyncInterval.ts:37 [useAsyncInterval] tick #1. 10068 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9918
useAsyncInterval.ts:37 [useAsyncInterval] tick #2. 9936 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #3. 10026 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9958
useAsyncInterval.ts:62 [useAsyncInterval] Setting interval minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #1. 941977 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #2. 13 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #3. 2038465 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #4. 19 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #5. 537820 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #6. 16 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #7. 191633 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #8. 18 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #9. 23720 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #10. 18 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #11. 886367 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #12. 17 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #13. 1010951 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #14. 6 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #15. 650011 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #16. 13 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #17. 731687 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #18. 19 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #19. 120545 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #20. 16 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #21. 446345 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 0
useAsyncInterval.ts:37 [useAsyncInterval] tick #22. 13 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #23. 10999 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 8987
useAsyncInterval.ts:37 [useAsyncInterval] tick #24. 9020 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #25. 10030 ms elapsed since last tick.
HeapUsage.tsx:68 [HeapUsage] Unable to get heap usage Error: Authentication details invalid
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9955
useAsyncInterval.ts:37 [useAsyncInterval] tick #26. 9979 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #27. 10027 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9956
useAsyncInterval.ts:62 [useAsyncInterval] Setting interval minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #1. 10695 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9290
useAsyncInterval.ts:37 [useAsyncInterval] tick #2. 9311 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 10000
useAsyncInterval.ts:37 [useAsyncInterval] tick #3. 10017 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9969
useAsyncInterval.ts:37 [useAsyncInterval] tick #4. 9992 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9992
useAsyncInterval.ts:37 [useAsyncInterval] tick #5. 10680 ms elapsed since last tick.
useAsyncInterval.ts:56 [useAsyncInterval] adjusted minIntervalMs: 9308

@bmingles bmingles requested a review from mofojed August 17, 2023 14:53
@codecov
Copy link

codecov bot commented Aug 21, 2023

Codecov Report

Merging #1450 (af1fba9) into main (2a4ec0d) will increase coverage by 0.05%.
Report is 1 commits behind head on main.
The diff coverage is 58.49%.

@@            Coverage Diff             @@
##             main    #1450      +/-   ##
==========================================
+ Coverage   45.70%   45.75%   +0.05%     
==========================================
  Files         513      515       +2     
  Lines       35046    35073      +27     
  Branches     8781     8784       +3     
==========================================
+ Hits        16017    16048      +31     
+ Misses      18978    18974       -4     
  Partials       51       51              
Flag Coverage Δ
unit 45.75% <58.49%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
packages/console/src/HeapUsage.tsx 0.00% <0.00%> (ø)
packages/utils/src/TestUtils.ts 90.76% <33.33%> (-2.78%) ⬇️
packages/react-hooks/src/useAsyncInterval.ts 100.00% <100.00%> (ø)
packages/react-hooks/src/useIsMountedRef.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

'ms elapsed since last tick.'
);

await callback();
Copy link
Member

Choose a reason for hiding this comment

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

If the component unmounts during this callback, I think the timer will continue on - it returns from this callback, and there's nothing to stop it from calling window.setTimeout at the end.
Should set an isCancelled ref when unmounted, or you could overload the setTimeoutRef instead.

@bmingles bmingles requested a review from mofojed August 24, 2023 16:29
@bmingles bmingles requested a review from mofojed August 24, 2023 19:18
@mofojed mofojed merged commit 5cc2936 into deephaven:main Aug 25, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 25, 2023
@bmingles bmingles deleted the 1439_heap-usage branch August 31, 2023 15:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI becomes unresponsive after suspending computer for a while
2 participants