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

Update the access time of a cached entry immediately after the entry is read #363

Merged
merged 1 commit into from
Dec 27, 2023

Conversation

tatsuya6502
Copy link
Member

@tatsuya6502 tatsuya6502 commented Dec 24, 2023

Fixes #359.

(We will merge this into the main branch after #348 is merged)

Problem

When a cached entry is read (by e.g. the get method) or write (by e.g. the insert method), the last_accessed time of the entry is updated. When time_to_idle of the Cache is set, the last_accessed time is used to determine whether the entry is expired or not.

Up to Moka v0.12.1, last_accessed time was eventual consistent for read operations. So it will not be updated immediately after read, but will be updated sometime later when pending tasks are processed. (Note: It will be updated to the time when read was performed, not to the time when pending task is processed). This was designed so to achieve better throughput as updating last_accessed has a small performance overhead from a synchronous primitive such as AtomicU64 when the default features are enabled, and Mutex when the atomic64 or quanta feature is disabled.

Note that last_accessed time is strong consistent for write operations, and it is updated during the write.

Before v0.12.0, pending tasks were processed periodically (every ~0.3 secs) by a background thread, so the delay after read was not obvious. However we removed the background thread completely from v0.12.0, and the delay becomes obvious.

Fix

Like the write operations, make last_accessed strong consistent for read operations.

@tatsuya6502 tatsuya6502 self-assigned this Dec 24, 2023
@tatsuya6502 tatsuya6502 added the bug Something isn't working label Dec 24, 2023
@tatsuya6502 tatsuya6502 added this to the v0.12.2 milestone Dec 24, 2023
Base automatically changed from fix-race-in-handle-upseart to main December 27, 2023 02:41
@tatsuya6502 tatsuya6502 linked an issue Dec 27, 2023 that may be closed by this pull request
Copy link
Member Author

@tatsuya6502 tatsuya6502 left a comment

Choose a reason for hiding this comment

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

Merging.

@tatsuya6502 tatsuya6502 merged commit 4e26b76 into main Dec 27, 2023
38 checks passed
@tatsuya6502 tatsuya6502 deleted the update-access-time-immediately branch December 27, 2023 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] time_to_idle not working as expected
1 participant