@@ -39,9 +39,6 @@ pub mod kind;
39
39
const MIN_MEM_LIMIT : usize = 16384 ;
40
40
const MIN_QUEUE_LIMIT : usize = 512 ;
41
41
42
- // maximum possible number of verification threads.
43
- const MAX_VERIFIERS : usize = 8 ;
44
-
45
42
/// Type alias for block queue convenience.
46
43
pub type BlockQueue = VerificationQueue < self :: kind:: Blocks > ;
47
44
@@ -85,7 +82,7 @@ impl Default for VerifierSettings {
85
82
fn default ( ) -> Self {
86
83
VerifierSettings {
87
84
scale_verifiers : false ,
88
- num_verifiers : MAX_VERIFIERS ,
85
+ num_verifiers : :: num_cpus :: get ( ) ,
89
86
}
90
87
}
91
88
}
@@ -231,9 +228,7 @@ impl<K: Kind> VerificationQueue<K> {
231
228
let empty = Arc :: new ( Condvar :: new ( ) ) ;
232
229
let scale_verifiers = config. verifier_settings . scale_verifiers ;
233
230
234
- let num_cpus = :: num_cpus:: get ( ) ;
235
-
236
- let max_verifiers = cmp:: max ( num_cpus, MAX_VERIFIERS ) ;
231
+ let max_verifiers = :: num_cpus:: get ( ) ;
237
232
let default_amount = cmp:: max ( 1 , cmp:: min ( max_verifiers, config. verifier_settings . num_verifiers ) ) ;
238
233
239
234
// if `auto-scaling` is enabled spawn up extra threads as they might be needed
@@ -753,6 +748,13 @@ mod tests {
753
748
BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true )
754
749
}
755
750
751
+ fn get_test_config ( num_verifiers : usize , is_auto_scale : bool ) -> Config {
752
+ let mut config = Config :: default ( ) ;
753
+ config. verifier_settings . num_verifiers = num_verifiers;
754
+ config. verifier_settings . scale_verifiers = is_auto_scale;
755
+ config
756
+ }
757
+
756
758
fn new_unverified ( bytes : Bytes ) -> Unverified {
757
759
Unverified :: from_rlp ( bytes) . expect ( "Should be valid rlp" )
758
760
}
@@ -853,12 +855,11 @@ mod tests {
853
855
854
856
#[ test]
855
857
fn scaling_limits ( ) {
856
- use super :: MAX_VERIFIERS ;
857
-
858
+ let max_verifiers = :: num_cpus:: get ( ) ;
858
859
let queue = get_test_queue ( true ) ;
859
- queue. scale_verifiers ( MAX_VERIFIERS + 1 ) ;
860
+ queue. scale_verifiers ( max_verifiers + 1 ) ;
860
861
861
- assert ! ( queue. num_verifiers( ) < MAX_VERIFIERS + 1 ) ;
862
+ assert ! ( queue. num_verifiers( ) < max_verifiers + 1 ) ;
862
863
863
864
queue. scale_verifiers ( 0 ) ;
864
865
@@ -889,55 +890,48 @@ mod tests {
889
890
}
890
891
891
892
#[ test]
892
- fn worker_threads_honor_specified_num_without_scaling ( ) {
893
+ fn worker_threads_honor_specified_number_without_scaling ( ) {
893
894
let spec = Spec :: new_test ( ) ;
894
895
let engine = spec. engine ;
895
- let mut config = Config :: default ( ) ;
896
- config. verifier_settings . num_verifiers = 3 ;
897
- config. verifier_settings . scale_verifiers = false ;
898
-
896
+ let config = get_test_config ( 1 , false ) ;
899
897
let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
900
898
901
- assert_eq ! ( queue. num_verifiers( ) , 3 ) ;
899
+ assert_eq ! ( queue. num_verifiers( ) , 1 ) ;
902
900
}
903
901
904
902
#[ test]
905
- fn worker_threads_specifyed_to_zero_should_set_to_one ( ) {
903
+ fn worker_threads_specified_to_zero_should_set_to_one ( ) {
906
904
let spec = Spec :: new_test ( ) ;
907
905
let engine = spec. engine ;
908
- let mut config = Config :: default ( ) ;
909
- config. verifier_settings . num_verifiers = 1 ;
910
- config. verifier_settings . scale_verifiers = false ;
911
-
906
+ let config = get_test_config ( 0 , false ) ;
912
907
let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
913
908
914
909
assert_eq ! ( queue. num_verifiers( ) , 1 ) ;
915
910
}
916
911
917
912
#[ test]
918
- fn worker_threads_should_accept_max_eight ( ) {
913
+ fn worker_threads_should_only_accept_max_number_cpus ( ) {
919
914
let spec = Spec :: new_test ( ) ;
920
915
let engine = spec. engine ;
921
- let mut config = Config :: default ( ) ;
922
- config. verifier_settings . num_verifiers = 10000 ;
923
- config. verifier_settings . scale_verifiers = false ;
924
-
916
+ let config = get_test_config ( 10_000 , false ) ;
925
917
let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
918
+ let num_cpus = :: num_cpus:: get ( ) ;
926
919
927
- assert_eq ! ( queue. num_verifiers( ) , 8 ) ;
920
+ assert_eq ! ( queue. num_verifiers( ) , num_cpus ) ;
928
921
}
929
922
930
923
#[ test]
931
924
fn worker_threads_scaling_with_specifed_num_of_workers ( ) {
932
- let spec = Spec :: new_test ( ) ;
933
- let engine = spec. engine ;
934
- let mut config = Config :: default ( ) ;
935
- config. verifier_settings . num_verifiers = 5 ;
936
- config. verifier_settings . scale_verifiers = true ;
937
-
938
- let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
939
- queue. scale_verifiers ( 8 ) ;
940
-
941
- assert_eq ! ( queue. num_verifiers( ) , 8 ) ;
925
+ let num_cpus = :: num_cpus:: get ( ) ;
926
+ // only run the test with at least 2 CPUs
927
+ if num_cpus > 1 {
928
+ let spec = Spec :: new_test ( ) ;
929
+ let engine = spec. engine ;
930
+ let config = get_test_config ( num_cpus - 1 , true ) ;
931
+ let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
932
+ queue. scale_verifiers ( num_cpus) ;
933
+
934
+ assert_eq ! ( queue. num_verifiers( ) , num_cpus) ;
935
+ }
942
936
}
943
937
}
0 commit comments