@@ -34,12 +34,14 @@ use http_body_util::Full;
3434#[ derive( Clone ) ]
3535struct ServerConfig {
3636 bind_address : String ,
37+ tokio_threads : Option < usize > ,
3738}
3839
3940impl ServerConfig {
4041 fn new ( ) -> Self {
4142 Self {
4243 bind_address : String :: from ( "127.0.0.1:3000" ) ,
44+ tokio_threads : None ,
4345 }
4446 }
4547}
@@ -78,6 +80,11 @@ impl Server {
7880 if let Some ( bind_address) = config. get ( magnus:: Symbol :: new ( "bind_address" ) ) {
7981 server_config. bind_address = String :: try_convert ( bind_address) ?;
8082 }
83+
84+ if let Some ( tokio_threads) = config. get ( magnus:: Symbol :: new ( "tokio_threads" ) ) {
85+ server_config. tokio_threads = Some ( usize:: try_convert ( tokio_threads) ?) ;
86+ }
87+
8188 Ok ( ( ) )
8289 }
8390
@@ -163,9 +170,16 @@ impl Server {
163170 . as_ref ( )
164171 . ok_or_else ( || MagnusError :: new ( magnus:: exception:: runtime_error ( ) , "Work channel not initialized" ) ) ?
165172 . clone ( ) ;
166-
167- let rt = Arc :: new ( tokio:: runtime:: Builder :: new_multi_thread ( )
168- . enable_all ( )
173+
174+ let mut rt_builder = tokio:: runtime:: Builder :: new_multi_thread ( ) ;
175+
176+ rt_builder. enable_all ( ) ;
177+
178+ if let Some ( tokio_threads) = config. tokio_threads {
179+ rt_builder. worker_threads ( tokio_threads) ;
180+ }
181+
182+ let rt = Arc :: new ( rt_builder
169183 . build ( )
170184 . map_err ( |e| MagnusError :: new ( magnus:: exception:: runtime_error ( ) , e. to_string ( ) ) ) ?) ;
171185
@@ -311,6 +325,7 @@ fn init(ruby: &Ruby) -> Result<(), MagnusError> {
311325 request_class. define_method ( "http_method" , method ! ( Request :: method, 0 ) ) ?;
312326 request_class. define_method ( "path" , method ! ( Request :: path, 0 ) ) ?;
313327 request_class. define_method ( "header" , method ! ( Request :: header, 1 ) ) ?;
328+ request_class. define_method ( "body" , method ! ( Request :: body, 0 ) ) ?;
314329 request_class. define_method ( "fill_body" , method ! ( Request :: fill_body, 1 ) ) ?;
315330 request_class. define_method ( "body_size" , method ! ( Request :: body_size, 0 ) ) ?;
316331 request_class. define_method ( "inspect" , method ! ( Request :: inspect, 0 ) ) ?;
0 commit comments