Skip to content

Commit 688cc58

Browse files
authored
Merge pull request #5 from matrix-org/quenting/eviction
2 parents 46ba3b1 + b5a28fb commit 688cc58

File tree

5 files changed

+238
-38
lines changed

5 files changed

+238
-38
lines changed

server/src/main.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ struct Options {
4141
#[arg(short, long, default_value_t = Duration::from_secs(60).into())]
4242
ttl: humantime::Duration,
4343

44+
/// Maximum number of entries to store
45+
#[arg(short, long, default_value_t = 10000)]
46+
capacity: usize,
47+
4448
/// Maximum payload size, in bytes
4549
#[arg(short, long, default_value = "4KiB")]
4650
max_bytes: ByteSize,
51+
52+
/// Set this flag to test how much memory the server might use with a sessions map fully loaded
53+
#[arg(long)]
54+
mem_check: bool,
4755
}
4856

4957
#[tokio::main]
@@ -59,9 +67,25 @@ async fn main() {
5967
.try_into()
6068
.expect("Max bytes size too large");
6169

70+
let sessions = matrix_http_rendezvous::Sessions::new(ttl, options.capacity);
71+
72+
if options.mem_check {
73+
tracing::info!(
74+
"Filling cache with {capacity} entries of {max_bytes}",
75+
capacity = options.capacity,
76+
max_bytes = options.max_bytes.to_string_as(true)
77+
);
78+
sessions.fill_for_mem_check(max_bytes).await;
79+
tracing::info!("Done filling, waiting 60 seconds");
80+
tokio::time::sleep(Duration::from_secs(60)).await;
81+
return;
82+
}
83+
84+
tokio::spawn(sessions.eviction_task(Duration::from_secs(60)));
85+
6286
let addr = SocketAddr::from((options.address, options.port));
6387

64-
let service = matrix_http_rendezvous::router(&prefix, ttl, max_bytes);
88+
let service = matrix_http_rendezvous::router(&prefix, sessions, max_bytes);
6589

6690
tracing::info!("Listening on http://{addr}");
6791
tracing::info!(

0 commit comments

Comments
 (0)