Skip to content

Commit 32ac380

Browse files
authored
Merge pull request #146 from lmilleri/actix-web-ds
Http server: configurable num of worker threads
2 parents 93b9f4b + d71a6ab commit 32ac380

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

integration-tests/src/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ impl TestHarness {
202202
certificate: None,
203203
insecure_http: true,
204204
payload_request_size: 2,
205+
worker_count: Some(4),
206+
205207
},
206208
admin: AdminConfig {
207209
auth_public_key: None,

kbs/docs/config.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ The following sections list the KBS properties which can be set through the conf
1919

2020
The following properties can be set under the `[http_server]` section.
2121

22-
| Property | Type | Description | Required | Default |
23-
|------------------------|--------------|--------------------------------------------------|----------|----------------------|
24-
| `sockets` | String array | One or more sockets to listen on. | No | `["127.0.0.1:8080"]` |
25-
| `insecure_http` | Boolean | Don't use TLS for the KBS HTTP endpoint. | No | `false` |
26-
| `private_key` | String | Path to a private key file to be used for HTTPS. | No | None |
27-
| `certificate` | String | Path to a certificate file to be used for HTTPS. | No | None |
28-
| `payload_request_size` | Integer | Request payload size in mega bytes. | No | 2 |
22+
| Property | Type | Description | Required | Default |
23+
|------------------------|--------------|--------------------------------------------------|----------|--------------------------|
24+
| `sockets` | String array | One or more sockets to listen on. | No | `["127.0.0.1:8080"]` |
25+
| `insecure_http` | Boolean | Don't use TLS for the KBS HTTP endpoint. | No | `false` |
26+
| `private_key` | String | Path to a private key file to be used for HTTPS. | No | None |
27+
| `certificate` | String | Path to a certificate file to be used for HTTPS. | No | None |
28+
| `payload_request_size` | Integer | Request payload size in mega bytes. | No | 2 |
29+
| `worker_count` | Integer | Number of HTTP actix worker threads | No | Num of logical CPU cores |
2930

3031
### Attestation Token Configuration
3132

kbs/src/api_server.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl ApiServer {
114114
let http_config = self.config.http_server.clone();
115115

116116
#[allow(clippy::redundant_closure)]
117-
let http_server = HttpServer::new({
117+
let mut http_server = HttpServer::new({
118118
move || {
119119
let api_server = self.clone();
120120
App::new()
@@ -137,6 +137,10 @@ impl ApiServer {
137137
}
138138
});
139139

140+
if let Some(worker_count) = http_config.worker_count {
141+
http_server = http_server.workers(worker_count);
142+
}
143+
140144
if !http_config.insecure_http {
141145
let tls_server = http_server
142146
.bind_openssl(

kbs/src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ pub struct HttpServerConfig {
3434

3535
/// Request payload size in MB
3636
pub payload_request_size: u32,
37+
38+
/// Number of worker threads for the actix-web server.
39+
/// If not specified, defaults to the number of logical CPU cores.
40+
pub worker_count: Option<usize>,
3741
}
3842

3943
impl Default for HttpServerConfig {
@@ -44,6 +48,7 @@ impl Default for HttpServerConfig {
4448
certificate: None,
4549
insecure_http: DEFAULT_INSECURE_HTTP,
4650
payload_request_size: DEFAULT_PAYLOAD_REQUEST_SIZE,
51+
worker_count: None,
4752
}
4853
}
4954
}
@@ -165,6 +170,7 @@ mod tests {
165170
certificate: Some("/etc/kbs-cert.pem".into()),
166171
insecure_http: false,
167172
payload_request_size: DEFAULT_PAYLOAD_REQUEST_SIZE,
173+
worker_count: None,
168174
},
169175
admin: AdminConfig {
170176
auth_public_key: Some(PathBuf::from("/etc/kbs-admin.pub")),
@@ -214,6 +220,7 @@ mod tests {
214220
certificate: None,
215221
insecure_http: DEFAULT_INSECURE_HTTP,
216222
payload_request_size: DEFAULT_PAYLOAD_REQUEST_SIZE,
223+
worker_count: None,
217224
},
218225
admin: AdminConfig {
219226
auth_public_key: None,
@@ -251,6 +258,7 @@ mod tests {
251258
certificate: Some("/etc/kbs-cert.pem".into()),
252259
insecure_http: false,
253260
payload_request_size: DEFAULT_PAYLOAD_REQUEST_SIZE,
261+
worker_count: None,
254262
},
255263
admin: AdminConfig {
256264
auth_public_key: Some(PathBuf::from("/etc/kbs-admin.pub")),
@@ -289,6 +297,7 @@ mod tests {
289297
certificate: None,
290298
insecure_http: true,
291299
payload_request_size: DEFAULT_PAYLOAD_REQUEST_SIZE,
300+
worker_count: None,
292301
},
293302
admin: AdminConfig {
294303
auth_public_key: Some(PathBuf::from("/opt/confidential-containers/kbs/user-keys/public.pub")),
@@ -330,6 +339,7 @@ mod tests {
330339
certificate: None,
331340
insecure_http: true,
332341
payload_request_size: DEFAULT_PAYLOAD_REQUEST_SIZE,
342+
worker_count: None,
333343
},
334344
admin: AdminConfig {
335345
auth_public_key: Some("/kbs/kbs.pem".into()),
@@ -365,6 +375,7 @@ mod tests {
365375
certificate: None,
366376
insecure_http: true,
367377
payload_request_size: DEFAULT_PAYLOAD_REQUEST_SIZE,
378+
worker_count: None,
368379
},
369380
admin: AdminConfig {
370381
auth_public_key: Some("/kbs/kbs.pem".into()),

0 commit comments

Comments
 (0)