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

Replace Time.now with monotonic in lru cache and resource update #443

Merged
merged 1 commit into from
Nov 23, 2022

Conversation

miry
Copy link
Contributor

@miry miry commented Nov 12, 2022

Resource updated_at used only for LRU cache to clean unused resources.
There is no need in keeping timestamp.

Sidecar:
Implement basic travel time helper to cover Monotonic clocks.

@miry miry force-pushed the monotonic-resource-updated-at branch from 67abc55 to 17d3054 Compare November 12, 2022 12:27
@miry miry added the Semian label Nov 12, 2022
@miry miry force-pushed the monotonic-resource-updated-at branch 2 times, most recently from b7fcb45 to 297eeab Compare November 12, 2022 21:26
@miry miry self-assigned this Nov 20, 2022
@miry miry force-pushed the monotonic-resource-updated-at branch 2 times, most recently from 5d2afa4 to 4ce482b Compare November 20, 2022 17:53
@miry miry requested review from casperisfine, a team, muz, chopify and atraver-shopify and removed request for a team November 20, 2022 17:57

Timecop.travel(2000) do
@lru_hash.set("d", create_circuit_breaker("d"))
sleep(3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh, no sleep in test please. The suite is slow enough already.

You can use mocha to stub Process.clock_gettime. You can even write a small test helper that would work like Timecop.travel, would only take 5 lines of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote small mock solution for travel. it would require either both Time.now and Monotonic time mocking or merge changes from #441 to single PR -> remove any Time.now usage from semian.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introduced Time helper to freeze time with +/-duration.
Because circuit breaker requires Time.now for now and LRU hash uses Monotnic did universal stub mechanism for both clocks:
https://github.com/Shopify/semian/pull/443/files#diff-4063630c1592331c02bf7c3561f5eb835eaff847cc9d3bd993ea2488e3492cb3R3

@AbdulRahmanAlHamali
Copy link

AbdulRahmanAlHamali commented Nov 21, 2022

Could you explain, for my learning, the value of this change?.

NVM, I just read this

Copy link
Contributor

@casperisfine casperisfine left a comment

Choose a reason for hiding this comment

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

LGTM. Time.now is quite a waste of resource in tight loops.

@miry miry force-pushed the monotonic-resource-updated-at branch 3 times, most recently from 19b1f15 to b888976 Compare November 23, 2022 17:09
Resource updated_at is not require be timestamp value.
Replaced the value with monotonic time, instead.

It requires to update tests - timecop does not support monotonic time changes,
replaced timecop with `sleep`.

Intorduce TimeHelper to test monotonic.
@miry miry force-pushed the monotonic-resource-updated-at branch from b888976 to 5ca75c0 Compare November 23, 2022 17:38
@miry miry merged commit 5ca75c0 into Shopify:master Nov 23, 2022
@miry miry deleted the monotonic-resource-updated-at branch November 23, 2022 17:45
@miry miry mentioned this pull request Dec 13, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants