@@ -41,9 +41,17 @@ struct Options {
41
41
#[ arg( short, long, default_value_t = Duration :: from_secs( 60 ) . into( ) ) ]
42
42
ttl : humantime:: Duration ,
43
43
44
+ /// Maximum number of entries to store
45
+ #[ arg( short, long, default_value_t = 10000 ) ]
46
+ capacity : usize ,
47
+
44
48
/// Maximum payload size, in bytes
45
49
#[ arg( short, long, default_value = "4KiB" ) ]
46
50
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 ,
47
55
}
48
56
49
57
#[ tokio:: main]
@@ -59,9 +67,25 @@ async fn main() {
59
67
. try_into ( )
60
68
. expect ( "Max bytes size too large" ) ;
61
69
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
+
62
86
let addr = SocketAddr :: from ( ( options. address , options. port ) ) ;
63
87
64
- let service = matrix_http_rendezvous:: router ( & prefix, ttl , max_bytes) ;
88
+ let service = matrix_http_rendezvous:: router ( & prefix, sessions , max_bytes) ;
65
89
66
90
tracing:: info!( "Listening on http://{addr}" ) ;
67
91
tracing:: info!(
0 commit comments