File tree 2 files changed +14
-4
lines changed
crates/shadowsocks-service/src/local/loadbalancing
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -824,9 +824,9 @@ impl PingChecker {
824
824
} ;
825
825
826
826
let ( score, stat_data) = match self . check_delay ( ) . await {
827
- Ok ( d) => server_score. push_score ( Score :: Latency ( d) ) . await ,
827
+ Ok ( d) => server_score. push_score_fetch_statistic ( Score :: Latency ( d) ) . await ,
828
828
// Penalty
829
- Err ( ..) => server_score. push_score ( Score :: Errored ) . await ,
829
+ Err ( ..) => server_score. push_score_fetch_statistic ( Score :: Errored ) . await ,
830
830
} ;
831
831
832
832
if stat_data. fail_rate > 0.5 {
Original file line number Diff line number Diff line change @@ -40,7 +40,17 @@ impl ServerScore {
40
40
}
41
41
42
42
/// Append a `Score` into statistic and recalculate score of the server
43
- pub async fn push_score ( & self , score : Score ) -> ( u32 , ServerStatData ) {
43
+ pub async fn push_score ( & self , score : Score ) -> u32 {
44
+ let updated_score = {
45
+ let mut stat = self . stat_data . lock ( ) . await ;
46
+ stat. push_score ( score)
47
+ } ;
48
+ self . score . store ( updated_score, Ordering :: Release ) ;
49
+ updated_score
50
+ }
51
+
52
+ /// Append a `Score` into statistic and recalculate score of the server
53
+ pub async fn push_score_fetch_statistic ( & self , score : Score ) -> ( u32 , ServerStatData ) {
44
54
let ( updated_score, data) = {
45
55
let mut stat = self . stat_data . lock ( ) . await ;
46
56
( stat. push_score ( score) , stat. data ( ) . clone ( ) )
@@ -50,7 +60,7 @@ impl ServerScore {
50
60
}
51
61
52
62
/// Report request failure of this server, which will eventually records an `Errored` score
53
- pub async fn report_failure ( & self ) -> ( u32 , ServerStatData ) {
63
+ pub async fn report_failure ( & self ) -> u32 {
54
64
self . push_score ( Score :: Errored ) . await
55
65
}
56
66
You can’t perform that action at this time.
0 commit comments