File tree 3 files changed +22
-12
lines changed
3 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ data:
211
211
212
212
[[tiers]]
213
213
name = "1"
214
- max_connections = 1
214
+ max_connections = 2
215
215
[[tiers.rates]]
216
216
interval = "1s"
217
217
limit = 1024
Original file line number Diff line number Diff line change @@ -106,21 +106,30 @@ pub struct Consumer {
106
106
active_connections : usize ,
107
107
}
108
108
impl Consumer {
109
- pub async fn inc_connections ( & mut self , state : Arc < State > ) {
110
- self . active_connections += 1 ;
109
+ pub async fn inc_connections ( & self , state : Arc < State > ) {
111
110
state
112
111
. consumers
113
112
. write ( )
114
113
. await
115
- . insert ( self . key . clone ( ) , self . clone ( ) ) ;
114
+ . entry ( self . key . clone ( ) )
115
+ . and_modify ( |consumer| consumer. active_connections += 1 ) ;
116
116
}
117
117
pub async fn dec_connections ( & mut self , state : Arc < State > ) {
118
- self . active_connections -= 1 ;
119
118
state
120
119
. consumers
121
120
. write ( )
122
121
. await
123
- . insert ( self . key . clone ( ) , self . clone ( ) ) ;
122
+ . entry ( self . key . clone ( ) )
123
+ . and_modify ( |consumer| consumer. active_connections -= 1 ) ;
124
+ }
125
+ pub async fn get_active_connections ( & self , state : Arc < State > ) -> usize {
126
+ state
127
+ . consumers
128
+ . read ( )
129
+ . await
130
+ . get ( & self . key )
131
+ . map ( |consumer| consumer. active_connections )
132
+ . unwrap_or_default ( )
124
133
}
125
134
}
126
135
impl Display for Consumer {
Original file line number Diff line number Diff line change @@ -94,18 +94,19 @@ impl ProxyApp {
94
94
95
95
match event {
96
96
DuplexEvent :: ClientRead ( 0 ) | DuplexEvent :: InstanceRead ( 0 ) => {
97
- info ! (
98
- consumer = ctx. consumer. to_string( ) ,
99
- active_connections = ctx. consumer. active_connections,
100
- "client disconnected"
101
- ) ;
102
-
103
97
ctx. consumer . dec_connections ( self . state . clone ( ) ) . await ;
104
98
state. metrics . dec_total_connections (
105
99
& ctx. consumer ,
106
100
& ctx. namespace ,
107
101
& ctx. instance ,
108
102
) ;
103
+
104
+ let active_connections =
105
+ ctx. consumer . get_active_connections ( state. clone ( ) ) . await ;
106
+ info ! (
107
+ consumer = ctx. consumer. to_string( ) ,
108
+ active_connections, "client disconnected"
109
+ ) ;
109
110
return Ok ( ( ) ) ;
110
111
}
111
112
DuplexEvent :: ClientRead ( bytes) => {
You can’t perform that action at this time.
0 commit comments