File tree Expand file tree Collapse file tree 3 files changed +7
-1
lines changed
misc/memory-connection-limits Expand file tree Collapse file tree 3 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,7 @@ impl Behaviour {
115
115
fn check_limit ( & mut self ) -> Result < ( ) , ConnectionDenied > {
116
116
self . refresh_memory_stats_if_needed ( ) ;
117
117
118
- if self . process_physical_memory_bytes >= self . max_allowed_bytes {
118
+ if self . process_physical_memory_bytes > self . max_allowed_bytes {
119
119
return Err ( ConnectionDenied :: new ( MemoryUsageLimitExceeded {
120
120
process_physical_memory_bytes : self . process_physical_memory_bytes ,
121
121
max_allowed_bytes : self . max_allowed_bytes ,
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ use util::*;
31
31
32
32
#[ tokio:: test]
33
33
async fn max_bytes ( ) {
34
+ // These tests use connections as unit to test the memory limit.
35
+ // Each connection consumes approximately 1MB of memory, so we give
36
+ // one connection as buffer for test stability (CONNECTION_LIMIT - 1) on line 35.
34
37
const CONNECTION_LIMIT : usize = 20 ;
35
38
let max_allowed_bytes = ( CONNECTION_LIMIT - 1 ) * 1024 * 1024 ;
36
39
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ async fn max_percentage() {
59
59
60
60
// Adds current mem usage to the limit and update
61
61
let current_mem = memory_stats:: memory_stats ( ) . unwrap ( ) . physical_mem ;
62
+ // These tests use connections as unit to test the memory limit.
63
+ // Each connection consumes approximately 1MB of memory, so we give
64
+ // one connection as buffer for test stability (CONNECTION_LIMIT - 1) on line 35.
62
65
let max_allowed_bytes = current_mem + ( CONNECTION_LIMIT - 1 ) * 1024 * 1024 ;
63
66
network. behaviour_mut ( ) . connection_limits = Behaviour :: with_max_percentage (
64
67
max_allowed_bytes as f64 / system_info. total_memory ( ) as f64 ,
You can’t perform that action at this time.
0 commit comments