From 4da046b78f2bbace02c70bfb9d0d074e5ff5b286 Mon Sep 17 00:00:00 2001 From: Imam Fahrur Rofi <92277627+masfahru@users.noreply.github.com> Date: Mon, 18 Sep 2023 22:07:51 +0700 Subject: [PATCH 1/5] [uWebsockets.js] Use Node 20 (#8426) --- .../uwebsockets.js/uwebsockets.js-postgres.dockerfile | 2 +- frameworks/JavaScript/uwebsockets.js/uwebsockets.js.dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/JavaScript/uwebsockets.js/uwebsockets.js-postgres.dockerfile b/frameworks/JavaScript/uwebsockets.js/uwebsockets.js-postgres.dockerfile index 94bb989e7cf..ba7d0eee5f6 100644 --- a/frameworks/JavaScript/uwebsockets.js/uwebsockets.js-postgres.dockerfile +++ b/frameworks/JavaScript/uwebsockets.js/uwebsockets.js-postgres.dockerfile @@ -1,4 +1,4 @@ -FROM node:18-slim +FROM node:20-slim COPY ./ ./ diff --git a/frameworks/JavaScript/uwebsockets.js/uwebsockets.js.dockerfile b/frameworks/JavaScript/uwebsockets.js/uwebsockets.js.dockerfile index bcb51d668bc..4262ad19953 100644 --- a/frameworks/JavaScript/uwebsockets.js/uwebsockets.js.dockerfile +++ b/frameworks/JavaScript/uwebsockets.js/uwebsockets.js.dockerfile @@ -1,4 +1,4 @@ -FROM node:18-slim +FROM node:20-slim COPY ./ ./ From e30b3724fd86b165857c9c501fd1666d99465238 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 18 Sep 2023 23:08:19 +0800 Subject: [PATCH 2/5] [xitca-web] update wasmtime. (#8419) * [xitca-web]update wasmtime. * simplify router constructor. --- frameworks/Rust/xitca-web/.cargo/config.toml | 2 +- frameworks/Rust/xitca-web/Cargo.lock | 56 +++++++++---------- frameworks/Rust/xitca-web/Cargo.toml | 16 +++--- frameworks/Rust/xitca-web/rust-toolchain.toml | 2 +- frameworks/Rust/xitca-web/src/main.rs | 6 +- .../Rust/xitca-web/xitca-web-wasm.dockerfile | 20 +++++-- 6 files changed, 55 insertions(+), 47 deletions(-) diff --git a/frameworks/Rust/xitca-web/.cargo/config.toml b/frameworks/Rust/xitca-web/.cargo/config.toml index c3a0d915a90..bca4c6c1b26 100644 --- a/frameworks/Rust/xitca-web/.cargo/config.toml +++ b/frameworks/Rust/xitca-web/.cargo/config.toml @@ -2,5 +2,5 @@ rustflags = ["-C", "target-cpu=native"] incremental = false -[target.wasm32-wasi] +[target.wasm32-wasi-preview1-threads] rustflags = ["-C", "target-feature=+simd128", "--cfg", "tokio_unstable"] diff --git a/frameworks/Rust/xitca-web/Cargo.lock b/frameworks/Rust/xitca-web/Cargo.lock index ac25b29f505..28dc57413d9 100644 --- a/frameworks/Rust/xitca-web/Cargo.lock +++ b/frameworks/Rust/xitca-web/Cargo.lock @@ -49,9 +49,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.3" +version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" +checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" [[package]] name = "bitflags" @@ -76,9 +76,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" @@ -259,9 +259,9 @@ checksum = "9028f49264629065d057f340a86acb84867925865f73bbf8d47b4d149a7e88b8" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "libmimalloc-sys" @@ -399,9 +399,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -530,9 +530,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2" dependencies = [ "itoa", "ryu", @@ -580,9 +580,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" dependencies = [ "libc", "windows-sys", @@ -607,9 +607,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "2.0.31" +version = "2.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" +checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" dependencies = [ "proc-macro2", "quote", @@ -643,7 +643,7 @@ dependencies = [ "num_cpus", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.3", + "socket2 0.5.4", "windows-sys", ] @@ -693,9 +693,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" @@ -809,7 +809,7 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "xitca-http" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" dependencies = [ "futures-core", "http", @@ -817,7 +817,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.3", + "socket2 0.5.4", "tokio", "tokio-uring", "tracing", @@ -830,7 +830,7 @@ dependencies = [ [[package]] name = "xitca-io" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" dependencies = [ "bytes", "tokio", @@ -841,7 +841,7 @@ dependencies = [ [[package]] name = "xitca-postgres" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" dependencies = [ "fallible-iterator", "percent-encoding", @@ -857,7 +857,7 @@ dependencies = [ [[package]] name = "xitca-router" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" dependencies = [ "xitca-unsafe-collection", ] @@ -865,9 +865,9 @@ dependencies = [ [[package]] name = "xitca-server" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" dependencies = [ - "socket2 0.5.3", + "socket2 0.5.4", "tokio", "tokio-uring", "tracing", @@ -879,12 +879,12 @@ dependencies = [ [[package]] name = "xitca-service" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" [[package]] name = "xitca-unsafe-collection" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" dependencies = [ "bytes", ] @@ -907,13 +907,13 @@ dependencies = [ "xitca-server", "xitca-service", "xitca-unsafe-collection", - "xitca-web 0.1.0 (git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c)", + "xitca-web 0.1.0 (git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9)", ] [[package]] name = "xitca-web" version = "0.1.0" -source = "git+https://github.com/HFQR/xitca-web.git?rev=1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c#1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" +source = "git+https://github.com/HFQR/xitca-web.git?rev=66a20d5fae8303918e0972798e85f55d1a5f97b9#66a20d5fae8303918e0972798e85f55d1a5f97b9" dependencies = [ "futures-core", "pin-project-lite", diff --git a/frameworks/Rust/xitca-web/Cargo.toml b/frameworks/Rust/xitca-web/Cargo.toml index 51aa9601c98..e571d236b6d 100644 --- a/frameworks/Rust/xitca-web/Cargo.toml +++ b/frameworks/Rust/xitca-web/Cargo.toml @@ -68,13 +68,13 @@ codegen-units = 1 panic = "abort" [patch.crates-io] -xitca-http = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } -xitca-io = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } -xitca-postgres = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } -xitca-router = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } -xitca-server = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } -xitca-service = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } -xitca-unsafe-collection = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } -xitca-web = { git = "https://github.com/HFQR/xitca-web.git", rev = "1a4e4e5917c1edc95de5f6fe38c6aabdc1bde66c" } +xitca-http = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } +xitca-io = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } +xitca-postgres = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } +xitca-router = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } +xitca-server = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } +xitca-service = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } +xitca-unsafe-collection = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } +xitca-web = { git = "https://github.com/HFQR/xitca-web.git", rev = "66a20d5fae8303918e0972798e85f55d1a5f97b9" } mio = { git = "https://github.com/fakeshadow/mio.git", rev = "eb67f6794edba8bc2e973ddef32e066b41ff812a" } diff --git a/frameworks/Rust/xitca-web/rust-toolchain.toml b/frameworks/Rust/xitca-web/rust-toolchain.toml index 6907ae28bf7..31929824cff 100644 --- a/frameworks/Rust/xitca-web/rust-toolchain.toml +++ b/frameworks/Rust/xitca-web/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2023-06-28" +channel = "nightly-2023-09-13" diff --git a/frameworks/Rust/xitca-web/src/main.rs b/frameworks/Rust/xitca-web/src/main.rs index 4fca1962ab8..2297f8a30b9 100755 --- a/frameworks/Rust/xitca-web/src/main.rs +++ b/frameworks/Rust/xitca-web/src/main.rs @@ -19,9 +19,9 @@ use xitca_http::{ IntoResponse, RequestExt, }, util::service::{ - context::{object::ContextObjectConstructor, Context, ContextBuilder}, + context::{Context, ContextBuilder}, route::get, - Router, + router::Router, }, HttpServiceBuilder, }; @@ -48,7 +48,7 @@ fn main() -> io::Result<()> { }) }) .service( - Router::with_custom_object::() + Router::new() .insert("/plaintext", get(fn_service(plain_text))) .insert("/json", get(fn_service(json))) .insert("/db", get(fn_service(db))) diff --git a/frameworks/Rust/xitca-web/xitca-web-wasm.dockerfile b/frameworks/Rust/xitca-web/xitca-web-wasm.dockerfile index e18e19c7fb3..c44aa9cf8dc 100644 --- a/frameworks/Rust/xitca-web/xitca-web-wasm.dockerfile +++ b/frameworks/Rust/xitca-web/xitca-web-wasm.dockerfile @@ -1,18 +1,25 @@ +ARG WASMTIME_VERSION=12.0.1 +ARG WASM_TARGET=wasm32-wasi-preview1-threads + FROM rust:1.67 AS compile -ARG WASMTIME_VERSION=11.0.1 +ARG WASMTIME_VERSION +ARG WASM_TARGET WORKDIR /tmp COPY / ./ RUN curl -LSs "https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/wasmtime-v${WASMTIME_VERSION}-$(uname -m)-linux.tar.xz" | \ tar --strip-components=1 -Jx && \ -rustup target add wasm32-wasi && \ -cargo build --bin xitca-web-wasm --features serde,web --release --target wasm32-wasi +rustup target add ${WASM_TARGET} && \ +cargo build --bin xitca-web-wasm --features serde,web --release --target ${WASM_TARGET} + FROM ubuntu:22.04 +ARG WASM_TARGET + COPY --from=compile \ -/tmp/target/wasm32-wasi/release/xitca-web-wasm.wasm \ +/tmp/target/${WASM_TARGET}/release/xitca-web-wasm.wasm \ /tmp/wasmtime \ /opt/xitca-web-wasm/ EXPOSE 8080 @@ -20,8 +27,9 @@ ARG BENCHMARK_ENV ARG TFB_TEST_DATABASE ARG TFB_TEST_NAME -CMD /opt/xitca-web-wasm/wasmtime compile /opt/xitca-web-wasm/xitca-web-wasm.wasm && \ -/opt/xitca-web-wasm/wasmtime run xitca-web-wasm.cwasm \ +CMD /opt/xitca-web-wasm/wasmtime run /opt/xitca-web-wasm/xitca-web-wasm.wasm \ +--wasm-features=threads \ +--wasi-modules experimental-wasi-threads \ --allow-precompiled \ --env FD_COUNT=3 \ --tcplisten 0.0.0.0:8080 From b53c0737edb30d492d34770f07fa4c76fea54543 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Mon, 18 Sep 2023 23:08:37 +0800 Subject: [PATCH 3/5] [salvo] Upgrade to version 0.55.x (#8417) * [salvo] Upgrade to version 0.55.x * [salvo] drop connect after use --- frameworks/Rust/salvo/Cargo.toml | 2 +- frameworks/Rust/salvo/src/db_pg_pool.rs | 2 +- frameworks/Rust/salvo/src/main_diesel.rs | 4 ++++ frameworks/Rust/salvo/src/main_pg_pool.rs | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frameworks/Rust/salvo/Cargo.toml b/frameworks/Rust/salvo/Cargo.toml index 0a52c15d15c..82b6107eb70 100644 --- a/frameworks/Rust/salvo/Cargo.toml +++ b/frameworks/Rust/salvo/Cargo.toml @@ -49,7 +49,7 @@ markup = "0.13" mongodb = { version = "2.4.0", features = ["zstd-compression", "snappy-compression", "zlib-compression"] } once_cell = "1" rand = { version = "0.8", features = ["min_const_gen", "small_rng"] } -salvo = { version = "0.54", default-features = false, features = ["anyhow", "http1", "affix"] } +salvo = { version = "0.55", default-features = false, features = ["anyhow", "http1", "affix"] } serde = { version = "1", features = ["derive"] } serde_json = "1" # smallvec = "1" diff --git a/frameworks/Rust/salvo/src/db_pg_pool.rs b/frameworks/Rust/salvo/src/db_pg_pool.rs index 560c9245ee1..bc1f546e922 100644 --- a/frameworks/Rust/salvo/src/db_pg_pool.rs +++ b/frameworks/Rust/salvo/src/db_pg_pool.rs @@ -32,7 +32,7 @@ pub async fn update_world(client: &Client, update: &Statement, random_id: i32, w Ok(rows_modified) } -pub async fn fetch_all_fortunes(client: Client, select: &Statement) -> Result, Error> { +pub async fn fetch_all_fortunes(client: &Client, select: &Statement) -> Result, Error> { let rows: Vec = client.query(select, &[]).await.unwrap(); let mut fortunes: Vec = Vec::with_capacity(rows.capacity()); diff --git a/frameworks/Rust/salvo/src/main_diesel.rs b/frameworks/Rust/salvo/src/main_diesel.rs index ab7d343b96e..063b814e191 100644 --- a/frameworks/Rust/salvo/src/main_diesel.rs +++ b/frameworks/Rust/salvo/src/main_diesel.rs @@ -54,6 +54,7 @@ async fn world_row(res: &mut Response) -> Result<(), Error> { let random_id = rng.gen_range(1..10_001); let mut conn = connect()?; let world = world::table.find(random_id).first::(&mut conn)?; + drop(conn); let data = serde_json::to_vec(&world).unwrap(); let headers = res.headers_mut(); @@ -75,6 +76,7 @@ async fn queries(req: &mut Request, res: &mut Response) -> Result<(), Error> { let w = world::table.find(id).get_result::(&mut conn)?; worlds.push(w); } + drop(conn); let data = serde_json::to_vec(&worlds)?; let headers = res.headers_mut(); @@ -107,6 +109,7 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> { } Ok(()) })?; + drop(conn); let data = serde_json::to_vec(&worlds)?; let headers = res.headers_mut(); @@ -120,6 +123,7 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> { async fn fortunes(res: &mut Response) -> Result<(), Error> { let mut conn = connect()?; let mut items = fortune::table.get_results::(&mut conn)?; + drop(conn); items.push(Fortune { id: 0, message: "Additional fortune added at request time.".to_string(), diff --git a/frameworks/Rust/salvo/src/main_pg_pool.rs b/frameworks/Rust/salvo/src/main_pg_pool.rs index b71e960a90c..75078c42ff1 100644 --- a/frameworks/Rust/salvo/src/main_pg_pool.rs +++ b/frameworks/Rust/salvo/src/main_pg_pool.rs @@ -41,6 +41,7 @@ async fn world_row(res: &mut Response) -> Result<(), Error> { let client = pool().get().await?; let select = prepare_fetch_world_by_id_statement(&client).await; let world = fetch_world_by_id(&client, random_id, &select).await?; + drop(client); let data = serde_json::to_vec(&world).unwrap(); let headers = res.headers_mut(); @@ -65,6 +66,7 @@ async fn queries(req: &mut Request, res: &mut Response) -> Result<(), Error> { future_worlds.push(fetch_world_by_id(&client, w_id, &select)); } let worlds: Vec = future_worlds.try_collect().await?; + drop(client); let data = serde_json::to_vec(&worlds)?; let headers = res.headers_mut(); @@ -100,6 +102,7 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> { future_world_updates.push(update_world(&client, &update, random_id, w_id)); } let _world_updates: Vec = future_world_updates.try_collect().await?; + drop(client); let data = serde_json::to_vec(&worlds)?; let headers = res.headers_mut(); @@ -113,7 +116,8 @@ async fn updates(req: &mut Request, res: &mut Response) -> Result<(), Error> { async fn fortunes(res: &mut Response) -> Result<(), Error> { let client = pool().get().await?; let select = prepare_fetch_all_fortunes_statement(&client).await; - let mut items = fetch_all_fortunes(client, &select).await?; + let mut items = fetch_all_fortunes(&client, &select).await?; + drop(client); items.push(Fortune { id: 0, message: "Additional fortune added at request time.".to_string(), From 42aecaef530c066d22978de3158a4a4b1ef56e5c Mon Sep 17 00:00:00 2001 From: Marcelo Barbosa Date: Tue, 19 Sep 2023 17:01:52 -0300 Subject: [PATCH 4/5] feat: add Bun runtime using TypeScript (#8416) --- frameworks/TypeScript/bun/README.md | 22 +++++++++++++++++++ .../TypeScript/bun/benchmark_config.json | 20 +++++++++++++++++ frameworks/TypeScript/bun/bun.dockerfile | 13 +++++++++++ frameworks/TypeScript/bun/config.toml | 15 +++++++++++++ frameworks/TypeScript/bun/src/index.ts | 21 ++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 frameworks/TypeScript/bun/README.md create mode 100644 frameworks/TypeScript/bun/benchmark_config.json create mode 100644 frameworks/TypeScript/bun/bun.dockerfile create mode 100644 frameworks/TypeScript/bun/config.toml create mode 100644 frameworks/TypeScript/bun/src/index.ts diff --git a/frameworks/TypeScript/bun/README.md b/frameworks/TypeScript/bun/README.md new file mode 100644 index 00000000000..2bf901cd406 --- /dev/null +++ b/frameworks/TypeScript/bun/README.md @@ -0,0 +1,22 @@ +# [Bun](https://bun.sh/) - A fast all-in-one JavaScript runtime + +## Description + +Bun is an all-in-one toolkit for JavaScript and TypeScript apps. It ships as a single executable +called `bun`​. + +At its core is the Bun runtime, a fast JavaScript runtime designed as a drop-in replacement for +Node.js. It's written in Zig and powered by JavaScriptCore under the hood, dramatically reducing +startup times and memory usage. + +- [Bun Docs](https://bun.sh/docs) + +## Test URLs + +### Test 1: JSON Encoding + + http://localhost:8080/json + +### Test 2: Plaintext + + http://localhost:8080/plaintext diff --git a/frameworks/TypeScript/bun/benchmark_config.json b/frameworks/TypeScript/bun/benchmark_config.json new file mode 100644 index 00000000000..d4c85cadc84 --- /dev/null +++ b/frameworks/TypeScript/bun/benchmark_config.json @@ -0,0 +1,20 @@ +{ + "framework": "bun", + "tests": [{ + "default": { + "json_url": "/json", + "plaintext_url": "/plaintext", + "port": 8080, + "approach": "Realistic", + "classification": "Platform", + "language": "TypeScript", + "flavor": "bun", + "platform": "bun", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "bun", + "versus": "nodejs" + } + }] +} diff --git a/frameworks/TypeScript/bun/bun.dockerfile b/frameworks/TypeScript/bun/bun.dockerfile new file mode 100644 index 00000000000..0814762abe3 --- /dev/null +++ b/frameworks/TypeScript/bun/bun.dockerfile @@ -0,0 +1,13 @@ +FROM oven/bun:1.0 + +EXPOSE 8080 + +WORKDIR /app + +USER bun + +COPY ./src . + +ENV NODE_ENV=production + +CMD ["bun", "index.ts"] diff --git a/frameworks/TypeScript/bun/config.toml b/frameworks/TypeScript/bun/config.toml new file mode 100644 index 00000000000..6d2201c788f --- /dev/null +++ b/frameworks/TypeScript/bun/config.toml @@ -0,0 +1,15 @@ +[framework] +name = "bun" + +[main] +urls.plaintext = "/plaintext" +urls.json = "/json" +approach = "Realistic" +classification = "Platform" +database_os = "Linux" +database = "None" +os = "Linux" +orm = "Raw" +platform = "bun" +webserver = "None" +versus = "nodejs" diff --git a/frameworks/TypeScript/bun/src/index.ts b/frameworks/TypeScript/bun/src/index.ts new file mode 100644 index 00000000000..be38493ff73 --- /dev/null +++ b/frameworks/TypeScript/bun/src/index.ts @@ -0,0 +1,21 @@ +const HELLO_WORLD_STR = "Hello, World!"; +const options: ResponseInit = { headers: { "Server": "Bun" } }; + +const server = Bun.serve({ + port: 8080, + fetch(req: Request) { + const { pathname } = new URL(req.url); + + if (pathname === "/json") { + return Response.json({ message: HELLO_WORLD_STR }, options); + } + + if (pathname === "/plaintext") { + return new Response(HELLO_WORLD_STR, options); + } + + return new Response("", { status: 404 }) + }, +}); + +console.log(`Listening on localhost:${server.port}`); From 63b04519a4d1f94deb0083a460ef2359e4b3dd60 Mon Sep 17 00:00:00 2001 From: Ishtmeet Singh Date: Wed, 20 Sep 2023 01:33:51 +0530 Subject: [PATCH 5/5] Add velocy, a minimal javascript framework (#8403) * add velocy, Node.js framework * add more info on readme * bump velocy: 0.0.9 -> 0.0.12 * fixes the dockers issue of lower case naming * removes the `.vagrant` directory * Update dockerfile to fix the CI issue. * add JSON + remove global strings/config --- frameworks/JavaScript/velocy/.gitignore | 1 + frameworks/JavaScript/velocy/README.md | 4 ++ frameworks/JavaScript/velocy/app.js | 46 +++++++++++++++++++ .../JavaScript/velocy/benchmark_config.json | 26 +++++++++++ frameworks/JavaScript/velocy/config.toml | 14 ++++++ frameworks/JavaScript/velocy/package.json | 5 ++ .../JavaScript/velocy/velocy.dockerfile | 6 +++ 7 files changed, 102 insertions(+) create mode 100644 frameworks/JavaScript/velocy/.gitignore create mode 100644 frameworks/JavaScript/velocy/README.md create mode 100644 frameworks/JavaScript/velocy/app.js create mode 100644 frameworks/JavaScript/velocy/benchmark_config.json create mode 100644 frameworks/JavaScript/velocy/config.toml create mode 100644 frameworks/JavaScript/velocy/package.json create mode 100644 frameworks/JavaScript/velocy/velocy.dockerfile diff --git a/frameworks/JavaScript/velocy/.gitignore b/frameworks/JavaScript/velocy/.gitignore new file mode 100644 index 00000000000..40b878db5b1 --- /dev/null +++ b/frameworks/JavaScript/velocy/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/frameworks/JavaScript/velocy/README.md b/frameworks/JavaScript/velocy/README.md new file mode 100644 index 00000000000..d4111a24950 --- /dev/null +++ b/frameworks/JavaScript/velocy/README.md @@ -0,0 +1,4 @@ +# Velocy +A minimal high performance web framework for Node.js. The goal and design of Velocy is to be a high performance web framework without installing any dependencies at all! It is a part of an [open source book](https://github.com/ishtms/learn-nodejs-hard-way) that I am writing. + +Github repo - [Velocy](https://github.com/ishtms/velocy) diff --git a/frameworks/JavaScript/velocy/app.js b/frameworks/JavaScript/velocy/app.js new file mode 100644 index 00000000000..199882f6648 --- /dev/null +++ b/frameworks/JavaScript/velocy/app.js @@ -0,0 +1,46 @@ +const cluster = require("node:cluster"); +const os = require("node:os"); +const process = require("node:process"); +const { SimpleRouter, createServer } = require("velocy"); + +if (cluster.isPrimary) { + console.log(`Primary ${process.pid} is running`); + + const numCPUs = os.cpus().length; + for (let i = 0; i < numCPUs; i++) { + cluster.fork(); + } + + cluster.on("exit", (worker) => { + console.log(`worker ${worker.process.pid} died`); + process.exit(1); + }); +} else { + const router = new SimpleRouter(); + + router.get("/plaintext", (req, res) => { + let p = "Hello, World!"; + res.writeHead(200, { + "content-type": "text/plain", + "content-length": p.length, + Server: "Velocy", + }); + res.end(p); + }); + + router.get("/json", (req, res) => { + let p = JSON.stringify({ message: "Hello, World!" }); + + res.writeHead(200, { + "content-type": "application/json", + "content-length": p.length, + Server: "Velocy", + }); + + res.end(p); + }); + + createServer(router).listen(8080); + + console.log(`Worker ${process.pid} started`); +} diff --git a/frameworks/JavaScript/velocy/benchmark_config.json b/frameworks/JavaScript/velocy/benchmark_config.json new file mode 100644 index 00000000000..edaffe29b59 --- /dev/null +++ b/frameworks/JavaScript/velocy/benchmark_config.json @@ -0,0 +1,26 @@ +{ + "framework": "velocy", + "tests": [ + { + "default": { + "plaintext_url": "/plaintext", + "json_url": "/json", + "port": 8080, + "approach": "Realistic", + "classification": "Micro", + "database": "None", + "framework": "velocy", + "language": "JavaScript", + "flavor": "None", + "orm": "None", + "platform": "nodejs", + "webserver": "None", + "os": "Linux", + "database_os": "None", + "display_name": "velocy", + "notes": "", + "versus": "nodejs" + } + } + ] +} diff --git a/frameworks/JavaScript/velocy/config.toml b/frameworks/JavaScript/velocy/config.toml new file mode 100644 index 00000000000..80af2a8b2f8 --- /dev/null +++ b/frameworks/JavaScript/velocy/config.toml @@ -0,0 +1,14 @@ +[framework] +name = "velocy" + +[main] +urls.plaintext = "/plaintext" +approach = "Realistic" +classification = "Micro" +database = "None" +database_os = "None" +os = "Linux" +orm = "None" +platform = "nodejs" +webserver = "None" +versus = "nodejs" \ No newline at end of file diff --git a/frameworks/JavaScript/velocy/package.json b/frameworks/JavaScript/velocy/package.json new file mode 100644 index 00000000000..a51441b5c26 --- /dev/null +++ b/frameworks/JavaScript/velocy/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "velocy": "0.0.13" + } +} diff --git a/frameworks/JavaScript/velocy/velocy.dockerfile b/frameworks/JavaScript/velocy/velocy.dockerfile new file mode 100644 index 00000000000..4f8efede62b --- /dev/null +++ b/frameworks/JavaScript/velocy/velocy.dockerfile @@ -0,0 +1,6 @@ +FROM node:20-slim +WORKDIR /usr/app +COPY ./ /usr/app +RUN npm install +EXPOSE 8080 +CMD ["node", "app.js"]