File tree Expand file tree Collapse file tree 4 files changed +52
-4
lines changed Expand file tree Collapse file tree 4 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -112,3 +112,8 @@ those.
112
112
Due to implementation details, this value may not be strictly adhered to. Defaults to 10.
113
113
- ` GRAPH_LOG_POI_EVENTS ` : Logs Proof of Indexing events deterministically.
114
114
This may be useful for debugging.
115
+ - ` GRAPH_LOAD_WINDOW_SIZE ` , ` GRAPH_LOAD_BIN_SIZE ` : Load can be
116
+ automatically throttled if load measurements over a time period of
117
+ ` GRAPH_LOAD_WINDOW_SIZE ` seconds exceed a threshold. Measurements within
118
+ each window are binned into bins of ` GRAPH_LOAD_BIN_SIZE ` seconds. The
119
+ variables default to 300s and 1s
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use std::collections::HashMap;
4
4
use std:: sync:: { Arc , RwLock } ;
5
5
use std:: time:: { Duration , Instant } ;
6
6
7
- use crate :: util:: stats:: MovingStats ;
7
+ use crate :: util:: stats:: { MovingStats , BIN_SIZE , WINDOW_SIZE } ;
8
8
9
9
pub struct QueryEffort {
10
10
inner : Arc < RwLock < QueryEffortInner > > ,
@@ -19,6 +19,14 @@ struct QueryEffortInner {
19
19
total : MovingStats ,
20
20
}
21
21
22
+ /// Create a `QueryEffort` that uses the window and bin sizes configured in
23
+ /// the environment
24
+ impl Default for QueryEffort {
25
+ fn default ( ) -> Self {
26
+ Self :: new ( * WINDOW_SIZE , * BIN_SIZE )
27
+ }
28
+ }
29
+
22
30
impl QueryEffort {
23
31
pub fn new ( window_size : Duration , bin_size : Duration ) -> Self {
24
32
Self {
Original file line number Diff line number Diff line change 1
1
use std:: collections:: VecDeque ;
2
+ use std:: env;
3
+ use std:: str:: FromStr ;
2
4
use std:: time:: { Duration , Instant } ;
3
5
6
+ use lazy_static:: lazy_static;
7
+
8
+ lazy_static ! {
9
+ pub static ref WINDOW_SIZE : Duration = {
10
+ let window_size = env:: var( "GRAPH_LOAD_WINDOW_SIZE" )
11
+ . ok( )
12
+ . map( |s| {
13
+ u64 :: from_str( & s) . unwrap_or_else( |_| {
14
+ panic!( "GRAPH_LOAD_WINDOW_SIZE must be a number, but is `{}`" , s)
15
+ } )
16
+ } )
17
+ . unwrap_or( 300 ) ;
18
+ Duration :: from_secs( window_size)
19
+ } ;
20
+ pub static ref BIN_SIZE : Duration = {
21
+ let bin_size = env:: var( "GRAPH_LOAD_BIN_SIZE" )
22
+ . ok( )
23
+ . map( |s| {
24
+ u64 :: from_str( & s) . unwrap_or_else( |_| {
25
+ panic!( "GRAPH_LOAD_BIN_SIZE must be a number but is `{}`" , s)
26
+ } )
27
+ } )
28
+ . unwrap_or( 1 ) ;
29
+ Duration :: from_secs( bin_size)
30
+ } ;
31
+ }
32
+
4
33
/// One bin of durations. The bin starts at time `start`, and we've added `count`
5
34
/// entries to it whose durations add up to `duration`
6
35
struct Bin {
@@ -61,6 +90,14 @@ pub struct MovingStats {
61
90
total : Bin ,
62
91
}
63
92
93
+ /// Create `MovingStats` that use the window and bin sizes configured in
94
+ /// the environment
95
+ impl Default for MovingStats {
96
+ fn default ( ) -> Self {
97
+ Self :: new ( * WINDOW_SIZE , * BIN_SIZE )
98
+ }
99
+ }
100
+
64
101
impl MovingStats {
65
102
pub fn new ( window_size : Duration , bin_size : Duration ) -> Self {
66
103
let capacity = if bin_size. as_millis ( ) > 0 {
Original file line number Diff line number Diff line change @@ -49,8 +49,6 @@ lazy_static! {
49
49
. map( |s| u32 :: from_str( & s)
50
50
. unwrap_or_else( |_| panic!( "failed to parse env var GRAPH_GRAPHQL_MAX_FIRST" ) ) )
51
51
. unwrap_or( 1000 ) ;
52
- static ref WINDOW_SIZE : Duration = Duration :: from_secs( 300 ) ;
53
- static ref BIN_SIZE : Duration = Duration :: from_secs( 1 ) ;
54
52
}
55
53
56
54
impl < S > GraphQlRunner < S >
67
65
logger : logger. new ( o ! ( "component" => "GraphQlRunner" ) ) ,
68
66
store,
69
67
expensive,
70
- effort : Arc :: new ( QueryEffort :: new ( * WINDOW_SIZE , * BIN_SIZE ) ) ,
68
+ effort : Arc :: new ( QueryEffort :: default ( ) ) ,
71
69
}
72
70
}
73
71
You can’t perform that action at this time.
0 commit comments