Repository navigation
S3FIFO Cache - #2865
S3FIFO Cache#2865Tunglies wants to merge 8 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2865 +/- ##
==========================================
+ Coverage 92.72% 92.79% +0.07%
==========================================
Files 98 98
Lines 21849 22049 +200
Branches 618 627 +9
==========================================
+ Hits 20259 20461 +202
Misses 1449 1449
+ Partials 141 139 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f60324a to
f9bd0c3
Compare
|
Fix the initial migrate to S3FIFO, now it is fully match the designed's behavior. See Designed behavior in Outdate Benchmark: DetailsWith Benchmark handshakes TLSv1_3 Rsa2048 TLS13_AES_256_GCM_SHA384 client server-auth no-resume 7544.33 handshakes/s
handshakes TLSv1_3 Rsa2048 TLS13_AES_256_GCM_SHA384 server server-auth no-resume 1737.17 handshakes/s
handshakes-unbuffered TLSv1_3 Rsa2048 TLS13_AES_256_GCM_SHA384 client server-auth no-resume 7541.12 handshakes/s
handshakes-unbuffered TLSv1_3 Rsa2048 TLS13_AES_256_GCM_SHA384 server server-auth no-resume 1734.94 handshakes/s
handshakes TLSv1_3 EcdsaP256 TLS13_AES_256_GCM_SHA384 client server-auth no-resume 4655.45 handshakes/s
handshakes TLSv1_3 EcdsaP256 TLS13_AES_256_GCM_SHA384 server server-auth no-resume 10229.22 handshakes/s
handshakes-unbuffered TLSv1_3 EcdsaP256 TLS13_AES_256_GCM_SHA384 client server-auth no-resume 4660.05 handshakes/s
handshakes-unbuffered TLSv1_3 EcdsaP256 TLS13_AES_256_GCM_SHA384 server server-auth no-resume 10181.91 handshakes/s
handshakes TLSv1_3 Ed25519 TLS13_AES_256_GCM_SHA384 client server-auth no-resume 5997.39 handshakes/s
handshakes TLSv1_3 Ed25519 TLS13_AES_256_GCM_SHA384 server server-auth no-resume 11479.40 handshakes/s
handshakes-unbuffered TLSv1_3 Ed25519 TLS13_AES_256_GCM_SHA384 client server-auth no-resume 6053.82 handshakes/s
handshakes-unbuffered TLSv1_3 Ed25519 TLS13_AES_256_GCM_SHA384 server server-auth no-resume 11587.77 handshakes/s |
djc
left a comment
There was a problem hiding this comment.
Very interesting work!
Would suggest keeping the LimitedCache name (and interface, to the extent possible) and module and only changing its internals.
Would also be useful to add some design documentation on what it is implementing, maybe with references to the S3-FIFO paper or another implementation that you referenced in building this.
Have you profiled memory usage differences in old vs new implementation?
I'm going to approve this for now so that the benchmark bot will run.
Benchmark resultsInstruction countsSignificant differencesClick to expand
Other differencesClick to expand
Wall-timeSignificant differencesThere are no significant wall-time differences Other differencesClick to expand
Memory usageKey:
Significant differencesClick to expand
Additional informationCheckout details:
|
|
So interestingly, memory usage is much better but mostly only small benefits for performance, and only on the client... |
|
Basline /usr/bin/env gtime -f %M target/release/rustls-bench memory TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 100
5472
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 1000
14848
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 5000
54544
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS13_AES_256_GCM_SHA384 100
7312
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS13_AES_256_GCM_SHA384 1000
21184
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS13_AES_256_GCM_SHA384 5000
83296PR /usr/bin/env gtime -f %M target/release/rustls-bench memory TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 100
5424
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 1000
14688
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 5000
54512
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS13_AES_256_GCM_SHA384 100
7248
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS13_AES_256_GCM_SHA384 1000
21280
/usr/bin/env gtime -f %M target/release/rustls-bench memory TLS13_AES_256_GCM_SHA384 5000
83280Designed follow the Paper FIFO queues are all you need for cache eviction in Other implementation reference: https://github.com/wfraser/s3fifo and https://github.com/YjyJeff/s3fifo |
I only do have one machine and with boost CPU. The benchmark locally follow by Would you like to benchmark locally? And see if performance actually improved. My environment can not disable CPU boost. |
8056b9d to
7800579
Compare
|
Wrote some debug for checking capacity and len. Basline(Dequeue) in branch here and S3fifo in branch here With The Dequeue Map capacity increasing quickly to almost 4 times than setting(128) to ...
LimitedCache observer: map capacity: 426, map len: 127, oldest capacity: 128, oldest len: 127and map capacity decreasing while the progress till to be done ...
LimitedCache observer: map capacity: 369, map len: 127, oldest capacity: 128, oldest len: 127
// DoneThe S3fifo also increasing capacity quickly but with less stress(capacity) ...
Cache Observer:
Map: len = 128, cap = 229
Small: len = 256, cap = 384
Main: len = 0, cap = 116
Ghost: len = 58, cap = 58...
Cache Observer:
Map: len = 128, cap = 146
Small: len = 255, cap = 384
Main: len = 0, cap = 116
Ghost: len = 58, cap = 58
// DoneRoughly look over, has around 10% difference on max capacity, maybe the memory improvements is from here? On the performance side, noticed that // Never has any print out
if main_len != 0 {
println!("Cache Observer:");
println!(" Map: len = {}, cap = {}", map_len, map_cap);
println!(" Small: len = {}, cap = {}", small_len, small_cap);
println!(" Main: len = {}, cap = {}", main_len, main_cap);
println!(" Ghost: len = {}, cap = {}", ghost_len, ghost_cap);
}My implementation may have flaws, or the the benchmark not suitable for s3fifo implementation. I prefer it is due to my implementation. Still need works on it. CC @djc |
|
Write a signle program for test S3fifo Detailsuse rand_distr::{Distribution, Zipf};
use rustls::limited_cache::LimitedCache;
use std::time::Instant;
fn main() {
let capacity = 400;
let mut cache = LimitedCache::new(capacity);
let mut rng = rand::rng();
let zipf = Zipf::new(1000.0, 1.03).unwrap();
println!("Starting Zipf distribution test with performance metrics...");
let total_start = Instant::now();
let mut last_checkpoint = Instant::now();
let mut total_hits = 0;
for i in 1..=20000 {
let key = zipf.sample(&mut rng) as u64;
if let Some(_) = cache.get(&key) {
total_hits += 1;
} else {
cache.insert(key, vec![0u8; 10]);
}
if i % 1000 == 0 {
let elapsed = last_checkpoint.elapsed();
let avg_op_time = elapsed.as_nanos() / 1000;
println!("--- Step {} ---", i);
println!("Latency: {} ns/op", avg_op_time);
cache.observer();
last_checkpoint = Instant::now();
println!();
}
}
let total_duration = total_start.elapsed();
let hit_rate = (total_hits as f64 / 20000.0) * 100.0;
println!("========================================");
println!("Test Completed!");
println!("Total Duration: {:.2?}", total_duration);
println!(
"Average Throughput: {:.2} ops/sec",
20000.0 / total_duration.as_secs_f64()
);
println!("Overall Hit Rate: {:.2}%", hit_rate);
println!("========================================");
}--- Step 20000 ---
Latency: 270 ns/op
Cache Observer:
Map: len = 400, cap = 791
Small: len = 39, cap = 40
Main: len = 361, cap = 720
Ghost: len = 400, cap = 400
========================================
Test Completed!
Total Duration: 5.56ms
Average Throughput: 3596556.30 ops/sec
Overall Hit Rate: 83.99%
========================================It shows the implementation works as expected, rustls-bench did not cover the s3fifo use case. Forget the messy commits, rebase them at eventually. |
e968dd7 to
b9037f1
Compare
181789b to
4d09b73
Compare
|
Hey @djc, I have made some changes for better code coverage. Would you like to trigger the benchmark bot again? And see what's come up with. Also, we might need a additional benchmark use case for workload to see difference bewtween baseline and S3fifo implementation. |
547906d to
d6c5f41
Compare
|
Hey @djc, any plan to going forward? Or see if https://cachemon.github.io/SIEVE-website/ could helps. |
|
This is on my plate, sorry for the delay and I will try to get to it soon. |
|
Feel free to reach out, I'll handle the conflicts later. |
d6c5f41 to
9715522
Compare
d10c31f to
65d965b
Compare
…llvm-lines Copies
…timestamps to eliminate HashSet and VecDeque overhead
65d965b to
a3e55e0
Compare
|
There you go. @ctz |
|
I think it would be better to implement a data structure which is designed for the particular load that the tls1.3 cache experiences rather that adopting some general-purpose data structure. As have been mentioned in #1200 (comment), the complexity of 3 fifo doesn't give much of the profit here. |
|
Still any plan to forward? Or else I would like to close this PR on my own. |
Related: #1503, #1200
Thea ideal to implement cache in s3fifo was initial mentioned by @djc in #1200 (comment)
I can not compile for this repo to run additional benchmark, dependency is kind of messy.
Outdate benchmark:
Details
Would like to share some of benchmark on my machine. M1Pro 10c 32G
> rustls-bench handshake TLS13_AES_256_GCM_SHA38Basline 257e511
PR
Additional work would like to be
.lock()to.try_lock()(? early return None not wait to a value may changed the expected behaviorMutex<Cache<T>>to[Mutex<Cache<T>>]for better lock contention optimizationHappy to receive any feedback so I(we) can move this forward