mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
optimizations and more deadlock fixes
This commit is contained in:
parent
be340c0f82
commit
ac39d82a53
8 changed files with 253 additions and 49 deletions
|
@ -11,7 +11,7 @@ wasm-bindgen --weak-refs --target no-modules --no-modules-global epoxy --out-dir
|
|||
echo "[ws] bindgen finished"
|
||||
|
||||
mv out/epoxy_client_bg.wasm out/epoxy_client_unoptimized.wasm
|
||||
time wasm-opt -O4 out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
||||
time wasm-opt -Oz --vacuum --dce out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
||||
echo "[ws] optimized"
|
||||
|
||||
AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js")
|
||||
|
|
125
client/demo.js
125
client/demo.js
|
@ -4,16 +4,21 @@
|
|||
"color:red;font-size:3rem;font-weight:bold"
|
||||
);
|
||||
|
||||
const should_feature_test = (new URL(window.location.href)).searchParams.has("feature_test");
|
||||
const should_parallel_test = (new URL(window.location.href)).searchParams.has("parallel_test");
|
||||
const should_perf_test = (new URL(window.location.href)).searchParams.has("perf_test");
|
||||
const should_ws_test = (new URL(window.location.href)).searchParams.has("ws_test");
|
||||
const params = (new URL(window.location.href)).searchParams;
|
||||
|
||||
const should_feature_test = params.has("feature_test");
|
||||
const should_multiparallel_test = params.has("multi_parallel_test");
|
||||
const should_parallel_test = params.has("parallel_test");
|
||||
const should_multiperf_test = params.has("multi_perf_test");
|
||||
const should_perf_test = params.has("perf_test");
|
||||
const should_ws_test = params.has("ws_test");
|
||||
|
||||
const log = (str) => {
|
||||
let el = document.createElement("div");
|
||||
el.innerText = str;
|
||||
document.getElementById("logs").appendChild(el);
|
||||
console.warn(str);
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
}
|
||||
|
||||
let { EpoxyClient } = await epoxy();
|
||||
|
@ -24,6 +29,19 @@
|
|||
const tconn1 = performance.now();
|
||||
log(`conn establish took ${tconn1 - tconn0} ms or ${(tconn1 - tconn0) / 1000} s`);
|
||||
|
||||
const test_mux = async (url) => {
|
||||
const t0 = performance.now();
|
||||
await epoxy_client.fetch(url);
|
||||
const t1 = performance.now();
|
||||
return t1 - t0;
|
||||
};
|
||||
|
||||
const test_native = async (url) => {
|
||||
const t0 = performance.now();
|
||||
await fetch(url, { cache: "no-store" });
|
||||
const t1 = performance.now();
|
||||
return t1 - t0;
|
||||
};
|
||||
|
||||
if (should_feature_test) {
|
||||
for (const url of [
|
||||
|
@ -37,55 +55,78 @@
|
|||
console.warn(url, resp, Object.fromEntries(resp.headers));
|
||||
console.warn(await resp.text());
|
||||
}
|
||||
} else if (should_multiparallel_test) {
|
||||
const num_tests = 10;
|
||||
let total_mux_minus_native = 0;
|
||||
for (const _ of Array(num_tests).keys()) {
|
||||
let total_mux = 0;
|
||||
await Promise.all([...Array(num_tests).keys()].map(async i => {
|
||||
log(`running mux test ${i}`);
|
||||
return await test_mux("https://httpbin.org/get");
|
||||
})).then((vals) => { total_mux = vals.reduce((acc, x) => acc + x, 0) });
|
||||
total_mux = total_mux / num_tests;
|
||||
|
||||
let total_native = 0;
|
||||
await Promise.all([...Array(num_tests).keys()].map(async i => {
|
||||
log(`running native test ${i}`);
|
||||
return await test_native("https://httpbin.org/get");
|
||||
})).then((vals) => { total_native = vals.reduce((acc, x) => acc + x, 0) });
|
||||
total_native = total_native / num_tests;
|
||||
|
||||
log(`avg mux (${num_tests}) took ${total_mux} ms or ${total_mux / 1000} s`);
|
||||
log(`avg native (${num_tests}) took ${total_native} ms or ${total_native / 1000} s`);
|
||||
log(`avg mux - avg native (${num_tests}): ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||
total_mux_minus_native += total_mux - total_native;
|
||||
}
|
||||
total_mux_minus_native = total_mux_minus_native / num_tests;
|
||||
log(`total mux - native (${num_tests} tests of ${num_tests} reqs): ${total_mux_minus_native} ms or ${total_mux_minus_native / 1000} s`);
|
||||
} else if (should_parallel_test) {
|
||||
const test_mux = async (url) => {
|
||||
const t0 = performance.now();
|
||||
await epoxy_client.fetch(url);
|
||||
const t1 = performance.now();
|
||||
return t1 - t0;
|
||||
};
|
||||
|
||||
const test_native = async (url) => {
|
||||
const t0 = performance.now();
|
||||
await fetch(url);
|
||||
const t1 = performance.now();
|
||||
return t1 - t0;
|
||||
};
|
||||
|
||||
const num_tests = 10;
|
||||
|
||||
let total_mux = 0;
|
||||
await Promise.all([...Array(num_tests).keys()].map(async i=>{
|
||||
await Promise.all([...Array(num_tests).keys()].map(async i => {
|
||||
log(`running mux test ${i}`);
|
||||
return await test_mux("https://httpbin.org/get");
|
||||
})).then((vals)=>{total_mux = vals.reduce((acc, x) => acc + x, 0)});
|
||||
})).then((vals) => { total_mux = vals.reduce((acc, x) => acc + x, 0) });
|
||||
total_mux = total_mux / num_tests;
|
||||
|
||||
let total_native = 0;
|
||||
await Promise.all([...Array(num_tests).keys()].map(async i=>{
|
||||
await Promise.all([...Array(num_tests).keys()].map(async i => {
|
||||
log(`running native test ${i}`);
|
||||
return await test_native("https://httpbin.org/get");
|
||||
})).then((vals)=>{total_native = vals.reduce((acc, x) => acc + x, 0)});
|
||||
})).then((vals) => { total_native = vals.reduce((acc, x) => acc + x, 0) });
|
||||
total_native = total_native / num_tests;
|
||||
|
||||
log(`avg mux (10) took ${total_mux} ms or ${total_mux / 1000} s`);
|
||||
log(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`);
|
||||
log(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||
log(`avg mux (${num_tests}) took ${total_mux} ms or ${total_mux / 1000} s`);
|
||||
log(`avg native (${num_tests}) took ${total_native} ms or ${total_native / 1000} s`);
|
||||
log(`avg mux - avg native (${num_tests}): ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||
} else if (should_multiperf_test) {
|
||||
const num_tests = 10;
|
||||
let total_mux_minus_native = 0;
|
||||
for (const _ of Array(num_tests).keys()) {
|
||||
let total_mux = 0;
|
||||
for (const i of Array(num_tests).keys()) {
|
||||
log(`running mux test ${i}`);
|
||||
total_mux += await test_mux("https://httpbin.org/get");
|
||||
}
|
||||
total_mux = total_mux / num_tests;
|
||||
|
||||
let total_native = 0;
|
||||
for (const i of Array(num_tests).keys()) {
|
||||
log(`running native test ${i}`);
|
||||
total_native += await test_native("https://httpbin.org/get");
|
||||
}
|
||||
total_native = total_native / num_tests;
|
||||
|
||||
log(`avg mux (${num_tests}) took ${total_mux} ms or ${total_mux / 1000} s`);
|
||||
log(`avg native (${num_tests}) took ${total_native} ms or ${total_native / 1000} s`);
|
||||
log(`avg mux - avg native (${num_tests}): ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||
total_mux_minus_native += total_mux - total_native;
|
||||
}
|
||||
total_mux_minus_native = total_mux_minus_native / num_tests;
|
||||
log(`total mux - native (${num_tests} tests of ${num_tests} reqs): ${total_mux_minus_native} ms or ${total_mux_minus_native / 1000} s`);
|
||||
|
||||
} else if (should_perf_test) {
|
||||
const test_mux = async (url) => {
|
||||
const t0 = performance.now();
|
||||
await epoxy_client.fetch(url);
|
||||
const t1 = performance.now();
|
||||
return t1 - t0;
|
||||
};
|
||||
|
||||
const test_native = async (url) => {
|
||||
const t0 = performance.now();
|
||||
await fetch(url);
|
||||
const t1 = performance.now();
|
||||
return t1 - t0;
|
||||
};
|
||||
|
||||
const num_tests = 10;
|
||||
|
||||
let total_mux = 0;
|
||||
|
@ -102,9 +143,9 @@
|
|||
}
|
||||
total_native = total_native / num_tests;
|
||||
|
||||
log(`avg mux (10) took ${total_mux} ms or ${total_mux / 1000} s`);
|
||||
log(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`);
|
||||
log(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||
log(`avg mux (${num_tests}) took ${total_mux} ms or ${total_mux / 1000} s`);
|
||||
log(`avg native (${num_tests}) took ${total_native} ms or ${total_native / 1000} s`);
|
||||
log(`avg mux - avg native (${num_tests}): ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||
} else if (should_ws_test) {
|
||||
let ws = await epoxy_client.connect_ws(
|
||||
() => console.log("opened"),
|
||||
|
|
|
@ -73,10 +73,12 @@ async fn send_req(
|
|||
None
|
||||
};
|
||||
|
||||
debug!("sending req");
|
||||
let res = req_sender
|
||||
.send_request(req)
|
||||
.await
|
||||
.replace_err("Failed to send request");
|
||||
debug!("recieved res");
|
||||
match res {
|
||||
Ok(res) => {
|
||||
if utils::is_redirect(res.status().as_u16())
|
||||
|
@ -176,6 +178,7 @@ impl EpoxyClient {
|
|||
async fn get_http_io(&self, url: &Uri) -> Result<EpxStream, JsError> {
|
||||
let url_host = url.host().replace_err("URL must have a host")?;
|
||||
let url_port = utils::get_url_port(url)?;
|
||||
debug!("making channel");
|
||||
let channel = self
|
||||
.mux
|
||||
.client_new_stream(StreamType::Tcp, url_host.to_string(), url_port)
|
||||
|
@ -187,6 +190,7 @@ impl EpoxyClient {
|
|||
if utils::get_is_secure(url)? {
|
||||
let cloned_uri = url_host.to_string().clone();
|
||||
let connector = TlsConnector::from(self.rustls_config.clone());
|
||||
debug!("connecting channel");
|
||||
let io = connector
|
||||
.connect(
|
||||
cloned_uri
|
||||
|
@ -196,8 +200,11 @@ impl EpoxyClient {
|
|||
)
|
||||
.await
|
||||
.replace_err("Failed to perform TLS handshake")?;
|
||||
debug!("connected channel");
|
||||
Ok(EpxStream::Left(io))
|
||||
} else {
|
||||
debug!("connecting channel");
|
||||
debug!("connected channel");
|
||||
Ok(EpxStream::Right(channel))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue