Repository navigation
net: Implement eviction in the HTTP cache using quick_cache - #40613
Conversation
107a79d to
20bcd88
Compare
8ef8a29 to
096fd81
Compare
|
I think I'm generally opposed to replacing our HTTP cache with a third party library for the reasons that others have mentioned on Zulip. Let's just fix the bugs! |
|
This does not replace the whole cache. The logic is still completely in servo. It just replaces a HashMap with a proper general cache that can evict. |
quick_cache
|
Please give this PR a general clean up, removing dead code and fixing the failing lint job. |
994322f to
379a4c9
Compare
|
Because currently cargo-update produces not compiling code I had to manually add hashbrown to the deny list. |
|
@gterzian should probably also have a look as he is the original writer. |
gterzian
left a comment
There was a problem hiding this comment.
I think this is the kind of granularity we are looking for when assessing a replacement for the cache, because here the cache is not a middleware but just a kind of concurrent hash map.
But, the current integration is problematic for the following reasons:
- I don't completely understand the eviction semantics of the crate, but I think it could lead to race conditions with the logic we currently implement with the cache state.
- The crate does all kinds of internal atomic stuff which are likely not worth it when paired with our cache state mechanism.
So I recommend the following investigative work: combining your work on the other PR related to updating the cache state to use async mechanisms, and combine it with this one, by using the cache methods returning the async guards to replace what we currently do with the cache state. See methods like https://docs.rs/quick_cache/latest/quick_cache/sync/struct.Cache.html#method.get_value_or_guard_async
|
Note also that at some point the cache will have to be persisted to disk. https://docs.rs/quick_cache/latest/quick_cache/trait.Lifecycle.html looks like interesting, perhaps to hook into an embedder provided persistence method. |
|
ffd0793 to
94b671b
Compare
|
@gterzian I think you can have a look at it now. |
gterzian
left a comment
There was a problem hiding this comment.
Looks good, couple of things on the logic...
|
|
||
| // Step 10. If response is null, then: | ||
| if response.is_none() { | ||
| let mut response = { |
There was a problem hiding this comment.
Why this change? Does it not break the logic? It seems this would make you always hit http_request.cache_mode == CacheMode::OnlyIfCached.
|
On a different note: 'quick_cache::sync' and 'quick_cache::unsync' have different methods. I think having a lock per bucket (which is for a reasonable definition of bucket what 'quick_cache::sync' does) is the correct answer. |
eb7349d to
d582c61
Compare
|
@gterzian Ok you can take another look. I hope I addressed all the comments. When you are done, I can try to rebase it. |
gterzian
left a comment
There was a problem hiding this comment.
I am not quite following. 'construct_response' needs done_chan which it needs &mut access to.
What I mean is that if the method does not use self anymore, which I think is the case since the resources are passed as argument, then it can just be a function without self, and you can still pass the done chan as argument.
In the light of my comments below, this could also be applied to other methods like refresh.
5947c95 to
e8735b7
Compare
There was a problem hiding this comment.
I think this is the structure we're looking for.
we keep the writeguard till line 1554
I think that's a good thing, because it matches the current critical section, which the code exits only at
servo/components/net/http_loader.rs
Line 1555 in 710d02c
Note that
servo/components/net/http_loader.rs
Line 1502 in 710d02c
|
|
|
🔨 Triggering try run (#20205176407) for Linux (WPT) |
|
Test results for linux-wpt from try job (#20205176407): Flaky unexpected result (27)
Stable unexpected results that are known to be intermittent (25)
|
|
✨ Try run (#20205176407) succeeded. |
Previously, the http cache would just grow over the lifetime of the servo instance. Now we use the quick_cache crate to have a cache with proper eviction procedures. We currently weight the entries by the number of responses for the url. The cache size is configurable. Signed-off-by: Narfinger <[email protected]> Signed-off-by: Taym Haddadi <[email protected]>
hopefully improve performance by not blocking async threads. Signed-off-by: Narfinger <[email protected]> Signed-off-by: Taym Haddadi <[email protected]>
Signed-off-by: Taym Haddadi <[email protected]>
Signed-off-by: Taym Haddadi <[email protected]>
Signed-off-by: gterzian <[email protected]> Signed-off-by: Taym Haddadi <[email protected]>
Signed-off-by: Taym Haddadi <[email protected]>
Signed-off-by: Taym Haddadi <[email protected]>
Signed-off-by: Taym Haddadi <[email protected]>
2e1c43c to
26c4e15
Compare
|
@Narfinger I signed off the commits |
|
Just two small improvements to the documentation so that the next person looking at it has an easier time than me :D. |
Signed-off-by: Taym Haddadi <[email protected]>
This uses quick_cache to have a proper cache for http.
Previously, the http cache would just grow over the lifetime of the
servo instance. Now we use the quick_cache crate to have a cache with
proper eviction procedures.
We currently weight the entries by the number of responses for the url.
The cache size is configurable.
Testing: Tested WPT run (https://github.com/Narfinger/servo/actions/runs/19338794789) and websites.