diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-06-08 12:55:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-08 12:55:33 +0200 |
| commit | 0197f42e6bd77c9bd6f14afd9523c4c252aa099b (patch) | |
| tree | 8ba7aa753cfb702a897a9730e3cb8afca54b75ca /ext/websocket | |
| parent | dd6458b30a4c1ecf4fab1eaffb4563734c5df284 (diff) | |
perf: use sendto syscalls (#19414)
This switches syscall used in HTTP and WS server from "writev"
to "sendto".
"DENO_USE_WRITEV=1" can be used to enable using "writev" syscall.
Doing this for easier testing of various setups.
Diffstat (limited to 'ext/websocket')
| -rw-r--r-- | ext/websocket/Cargo.toml | 1 | ||||
| -rw-r--r-- | ext/websocket/lib.rs | 14 |
2 files changed, 13 insertions, 2 deletions
diff --git a/ext/websocket/Cargo.toml b/ext/websocket/Cargo.toml index 1ac465f69..324a2b1a4 100644 --- a/ext/websocket/Cargo.toml +++ b/ext/websocket/Cargo.toml @@ -21,6 +21,7 @@ deno_tls.workspace = true fastwebsockets = { workspace = true, features = ["upgrade"] } http.workspace = true hyper = { workspace = true, features = ["backports"] } +once_cell.workspace = true serde.workspace = true tokio.workspace = true tokio-rustls.workspace = true diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index af987c1e4..b492be0c0 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -27,6 +27,7 @@ use http::Method; use http::Request; use http::Uri; use hyper::Body; +use once_cell::sync::Lazy; use serde::Serialize; use std::borrow::Cow; use std::cell::Cell; @@ -50,9 +51,18 @@ use fastwebsockets::Frame; use fastwebsockets::OpCode; use fastwebsockets::Role; use fastwebsockets::WebSocket; - mod stream; +static USE_WRITEV: Lazy<bool> = Lazy::new(|| { + let enable = std::env::var("DENO_USE_WRITEV").ok(); + + if let Some(val) = enable { + return !val.is_empty(); + } + + false +}); + #[derive(Clone)] pub struct WsRootStoreProvider(Option<Arc<dyn RootCertStoreProvider>>); @@ -360,7 +370,7 @@ pub fn ws_create_server_stream( ), Role::Server, ); - ws.set_writev(true); + ws.set_writev(*USE_WRITEV); ws.set_auto_close(true); ws.set_auto_pong(true); |
