@@ -39,9 +39,6 @@ pub mod kind;
3939const MIN_MEM_LIMIT : usize = 16384 ;
4040const MIN_QUEUE_LIMIT : usize = 512 ;
4141
42- // maximum possible number of verification threads.
43- const MAX_VERIFIERS : usize = 8 ;
44-
4542/// Type alias for block queue convenience.
4643pub type BlockQueue = VerificationQueue < self :: kind:: Blocks > ;
4744
@@ -85,7 +82,7 @@ impl Default for VerifierSettings {
8582 fn default ( ) -> Self {
8683 VerifierSettings {
8784 scale_verifiers : false ,
88- num_verifiers : MAX_VERIFIERS ,
85+ num_verifiers : :: num_cpus :: get ( ) ,
8986 }
9087 }
9188}
@@ -231,9 +228,7 @@ impl<K: Kind> VerificationQueue<K> {
231228 let empty = Arc :: new ( Condvar :: new ( ) ) ;
232229 let scale_verifiers = config. verifier_settings . scale_verifiers ;
233230
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 ( ) ;
237232 let default_amount = cmp:: max ( 1 , cmp:: min ( max_verifiers, config. verifier_settings . num_verifiers ) ) ;
238233
239234 // if `auto-scaling` is enabled spawn up extra threads as they might be needed
@@ -753,6 +748,13 @@ mod tests {
753748 BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true )
754749 }
755750
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+
756758 fn new_unverified ( bytes : Bytes ) -> Unverified {
757759 Unverified :: from_rlp ( bytes) . expect ( "Should be valid rlp" )
758760 }
@@ -853,12 +855,11 @@ mod tests {
853855
854856 #[ test]
855857 fn scaling_limits ( ) {
856- use super :: MAX_VERIFIERS ;
857-
858+ let max_verifiers = :: num_cpus:: get ( ) ;
858859 let queue = get_test_queue ( true ) ;
859- queue. scale_verifiers ( MAX_VERIFIERS + 1 ) ;
860+ queue. scale_verifiers ( max_verifiers + 1 ) ;
860861
861- assert ! ( queue. num_verifiers( ) < MAX_VERIFIERS + 1 ) ;
862+ assert ! ( queue. num_verifiers( ) < max_verifiers + 1 ) ;
862863
863864 queue. scale_verifiers ( 0 ) ;
864865
@@ -889,55 +890,48 @@ mod tests {
889890 }
890891
891892 #[ test]
892- fn worker_threads_honor_specified_num_without_scaling ( ) {
893+ fn worker_threads_honor_specified_number_without_scaling ( ) {
893894 let spec = Spec :: new_test ( ) ;
894895 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 ) ;
899897 let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
900898
901- assert_eq ! ( queue. num_verifiers( ) , 3 ) ;
899+ assert_eq ! ( queue. num_verifiers( ) , 1 ) ;
902900 }
903901
904902 #[ test]
905- fn worker_threads_specifyed_to_zero_should_set_to_one ( ) {
903+ fn worker_threads_specified_to_zero_should_set_to_one ( ) {
906904 let spec = Spec :: new_test ( ) ;
907905 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 ) ;
912907 let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
913908
914909 assert_eq ! ( queue. num_verifiers( ) , 1 ) ;
915910 }
916911
917912 #[ test]
918- fn worker_threads_should_accept_max_eight ( ) {
913+ fn worker_threads_should_only_accept_max_number_cpus ( ) {
919914 let spec = Spec :: new_test ( ) ;
920915 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 ) ;
925917 let queue = BlockQueue :: new ( config, engine, IoChannel :: disconnected ( ) , true ) ;
918+ let num_cpus = :: num_cpus:: get ( ) ;
926919
927- assert_eq ! ( queue. num_verifiers( ) , 8 ) ;
920+ assert_eq ! ( queue. num_verifiers( ) , num_cpus ) ;
928921 }
929922
930923 #[ test]
931924 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+ }
942936 }
943937}
0 commit comments