1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

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.
This commit is contained in:
Bartek Iwańczuk 2023-06-08 12:55:33 +02:00
parent beae8f6826
commit d7c56153a6
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
4 changed files with 18 additions and 6 deletions

1
Cargo.lock generated
View file

@ -1412,6 +1412,7 @@ dependencies = [
"fastwebsockets", "fastwebsockets",
"http", "http",
"hyper 0.14.26", "hyper 0.14.26",
"once_cell",
"serde", "serde",
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",

View file

@ -73,13 +73,13 @@ type Request = hyper1::Request<Incoming>;
type Response = hyper1::Response<ResponseBytes>; type Response = hyper1::Response<ResponseBytes>;
static USE_WRITEV: Lazy<bool> = Lazy::new(|| { static USE_WRITEV: Lazy<bool> = Lazy::new(|| {
let disable_writev = std::env::var("DENO_HYPER_USE_WRITEV").ok(); let enable = std::env::var("DENO_USE_WRITEV").ok();
if let Some(val) = disable_writev { if let Some(val) = enable {
return val != "0"; return !val.is_empty();
} }
true false
}); });
/// All HTTP/2 connections start with this byte string. /// All HTTP/2 connections start with this byte string.

View file

@ -21,6 +21,7 @@ deno_tls.workspace = true
fastwebsockets = { workspace = true, features = ["upgrade"] } fastwebsockets = { workspace = true, features = ["upgrade"] }
http.workspace = true http.workspace = true
hyper = { workspace = true, features = ["backports"] } hyper = { workspace = true, features = ["backports"] }
once_cell.workspace = true
serde.workspace = true serde.workspace = true
tokio.workspace = true tokio.workspace = true
tokio-rustls.workspace = true tokio-rustls.workspace = true

View file

@ -27,6 +27,7 @@ use http::Method;
use http::Request; use http::Request;
use http::Uri; use http::Uri;
use hyper::Body; use hyper::Body;
use once_cell::sync::Lazy;
use serde::Serialize; use serde::Serialize;
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::Cell; use std::cell::Cell;
@ -50,9 +51,18 @@ use fastwebsockets::Frame;
use fastwebsockets::OpCode; use fastwebsockets::OpCode;
use fastwebsockets::Role; use fastwebsockets::Role;
use fastwebsockets::WebSocket; use fastwebsockets::WebSocket;
mod stream; 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)] #[derive(Clone)]
pub struct WsRootStoreProvider(Option<Arc<dyn RootCertStoreProvider>>); pub struct WsRootStoreProvider(Option<Arc<dyn RootCertStoreProvider>>);
@ -360,7 +370,7 @@ pub fn ws_create_server_stream(
), ),
Role::Server, Role::Server,
); );
ws.set_writev(true); ws.set_writev(*USE_WRITEV);
ws.set_auto_close(true); ws.set_auto_close(true);
ws.set_auto_pong(true); ws.set_auto_pong(true);