File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -33,9 +33,9 @@ async fn run() -> io::Result<()> {
3333 let addr = ( "127.0.0.1" , 8080 ) ;
3434 info ! ( "starting server on port: {}" , & addr. 0 ) ;
3535
36- // Bind socket address and start worker(s). By default, the server uses the number of available
37- // logical CPU cores as the worker count. For this reason, the closure passed to bind needs
38- // to return a service *factory*; so it can be created once per worker.
36+ // Bind socket address and start worker(s). By default, the server uses the number of physical
37+ // CPU cores as the worker count. For this reason, the closure passed to bind needs to return
38+ // a service *factory*; so it can be created once per worker.
3939 Server :: build ( )
4040 . bind ( "echo" , addr, move || {
4141 let count = Arc :: clone ( & count) ;
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ impl ServerBuilder {
4040 let ( cmd_tx, cmd_rx) = unbounded_channel ( ) ;
4141
4242 ServerBuilder {
43- threads : num_cpus:: get ( ) ,
43+ threads : num_cpus:: get_physical ( ) ,
4444 token : 0 ,
4545 factories : Vec :: new ( ) ,
4646 sockets : Vec :: new ( ) ,
@@ -55,8 +55,11 @@ impl ServerBuilder {
5555
5656 /// Set number of workers to start.
5757 ///
58- /// By default server uses number of available logical CPU as workers count. Workers must be
59- /// greater than 0.
58+ /// `num` must be greater than 0.
59+ ///
60+ /// The default worker count is the number of physical CPU cores available. If your benchmark
61+ /// testing indicates that simultaneous multi-threading is beneficial to your app, you can use
62+ /// the [`num_cpus`] crate to acquire the _logical_ core count instead.
6063 pub fn workers ( mut self , num : usize ) -> Self {
6164 assert_ne ! ( num, 0 , "workers must be greater than 0" ) ;
6265 self . threads = num;
Original file line number Diff line number Diff line change @@ -250,7 +250,7 @@ pub(crate) struct ServerWorkerConfig {
250250impl Default for ServerWorkerConfig {
251251 fn default ( ) -> Self {
252252 // 512 is the default max blocking thread count of tokio runtime.
253- let max_blocking_threads = std:: cmp:: max ( 512 / num_cpus:: get ( ) , 1 ) ;
253+ let max_blocking_threads = std:: cmp:: max ( 512 / num_cpus:: get_physical ( ) , 1 ) ;
254254 Self {
255255 shutdown_timeout : Duration :: from_secs ( 30 ) ,
256256 max_blocking_threads,
You can’t perform that action at this time.
0 commit comments