@@ -34,12 +34,14 @@ use http_body_util::Full;
34
34
#[ derive( Clone ) ]
35
35
struct ServerConfig {
36
36
bind_address : String ,
37
+ tokio_threads : Option < usize > ,
37
38
}
38
39
39
40
impl ServerConfig {
40
41
fn new ( ) -> Self {
41
42
Self {
42
43
bind_address : String :: from ( "127.0.0.1:3000" ) ,
44
+ tokio_threads : None ,
43
45
}
44
46
}
45
47
}
@@ -78,6 +80,11 @@ impl Server {
78
80
if let Some ( bind_address) = config. get ( magnus:: Symbol :: new ( "bind_address" ) ) {
79
81
server_config. bind_address = String :: try_convert ( bind_address) ?;
80
82
}
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
+
81
88
Ok ( ( ) )
82
89
}
83
90
@@ -163,9 +170,16 @@ impl Server {
163
170
. as_ref ( )
164
171
. ok_or_else ( || MagnusError :: new ( magnus:: exception:: runtime_error ( ) , "Work channel not initialized" ) ) ?
165
172
. 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
169
183
. build ( )
170
184
. map_err ( |e| MagnusError :: new ( magnus:: exception:: runtime_error ( ) , e. to_string ( ) ) ) ?) ;
171
185
@@ -311,6 +325,7 @@ fn init(ruby: &Ruby) -> Result<(), MagnusError> {
311
325
request_class. define_method ( "http_method" , method ! ( Request :: method, 0 ) ) ?;
312
326
request_class. define_method ( "path" , method ! ( Request :: path, 0 ) ) ?;
313
327
request_class. define_method ( "header" , method ! ( Request :: header, 1 ) ) ?;
328
+ request_class. define_method ( "body" , method ! ( Request :: body, 0 ) ) ?;
314
329
request_class. define_method ( "fill_body" , method ! ( Request :: fill_body, 1 ) ) ?;
315
330
request_class. define_method ( "body_size" , method ! ( Request :: body_size, 0 ) ) ?;
316
331
request_class. define_method ( "inspect" , method ! ( Request :: inspect, 0 ) ) ?;
0 commit comments