Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bench/ci.js → .github/bench/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const DEFAULT_SCENARIOS = ["static", "dynamic", "opt"];
const DEFAULT_CONNECTIONS = 200;
const DEFAULT_DURATION = "10s";
const DEFAULT_TIMEOUT = "2s";
const DEFAULT_OUTPUT_DIR = "bench/results";
const DEFAULT_OUTPUT_DIR = ".github/bench/results";
const DEFAULT_HTTP_NATIVE_RUNTIME = "bun";
const DEFAULT_BOMBARDIER_BIN = resolveBombardierBin();
const SUPPORTED_HTTP_NATIVE_RUNTIMES = new Set(["bun", "node"]);
Expand Down Expand Up @@ -155,7 +155,7 @@ function parseArgs(argv) {
}

function printUsage() {
console.log("Usage: bun bench/ci.js [options]");
console.log("Usage: bun .github/bench/ci.js [options]");
console.log("");
console.log("Options:");
console.log(` --engines=http-native,bun Comma-separated list. Default: ${DEFAULT_ENGINES.join(",")}`);
Expand Down Expand Up @@ -327,15 +327,15 @@ async function runBenchmarkCase(testCase, options) {
function spawnServer(testCase, options) {
if (testCase.engine === "bun" || testCase.engine === "http-native" || testCase.engine === "old") {
const runtime = testCase.engine === "bun" ? "bun" : options.httpNativeRuntime;
return spawn(runtime, ["bench/target.js", testCase.engine, testCase.scenario, String(testCase.port)], {
return spawn(runtime, [".github/bench/target.js", testCase.engine, testCase.scenario, String(testCase.port)], {
cwd: process.cwd(),
detached: process.platform !== "win32",
stdio: ["ignore", "pipe", "pipe"],
});
}

if (testCase.engine === "fiber") {
const cwd = resolve(process.cwd(), "bench/fiber-server");
const cwd = resolve(process.cwd(), ".github/bench/fiber-server");
if (!existsSync(resolve(cwd, "go.mod"))) {
throw new Error(`Missing Fiber benchmark target at ${cwd}`);
}
Expand All @@ -348,7 +348,7 @@ function spawnServer(testCase, options) {
}

if (testCase.engine === "zig") {
const cwd = resolve(process.cwd(), "bench/zig-httpz");
const cwd = resolve(process.cwd(), ".github/bench/zig-httpz");
if (!existsSync(cwd)) {
throw new Error(`Missing Zig benchmark target at ${cwd}`);
}
Expand All @@ -362,8 +362,8 @@ function spawnServer(testCase, options) {
if (testCase.engine === "xitca" || testCase.engine === "monoio") {
const manifestPath =
testCase.engine === "xitca"
? resolve(process.cwd(), "bench/xitca-server/Cargo.toml")
: resolve(process.cwd(), "bench/monoio-server/Cargo.toml");
? resolve(process.cwd(), ".github/bench/xitca-server/Cargo.toml")
: resolve(process.cwd(), ".github/bench/monoio-server/Cargo.toml");

if (!existsSync(manifestPath)) {
throw new Error(`Missing Rust benchmark target at ${manifestPath}`);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions bench/run.js → .github/bench/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const port = Number(portArg ?? 3001);
const httpNativeRuntime = runtimeArg ?? "bun";

function printUsage() {
console.log("Usage: bun bench/run.js <engine> <scenario> <port> [httpNativeRuntime]");
console.log("Usage: bun .github/bench/run.js <engine> <scenario> <port> [httpNativeRuntime]");
console.log("Engines: http-native | bun | fiber | xitca | monoio | zig");
console.log("Scenarios: static | dynamic | opt");
console.log("httpNativeRuntime: bun | node (only applies to http-native and old)");
console.log("");
console.log("Example:");
console.log(" bun bench/run.js http-native static 3001 bun");
console.log(" bun bench/run.js http-native static 3001 node");
console.log(" bun .github/bench/run.js http-native static 3001 bun");
console.log(" bun .github/bench/run.js http-native static 3001 node");
console.log(" bombardier -c 200 -d 10s http://127.0.0.1:3001/");
}

Expand Down Expand Up @@ -59,8 +59,8 @@ async function main() {
"--release",
"--manifest-path",
engine === "xitca"
? "bench/xitca-server/Cargo.toml"
: "bench/monoio-server/Cargo.toml",
? ".github/bench/xitca-server/Cargo.toml"
: ".github/bench/monoio-server/Cargo.toml",
"--",
scenario,
String(port),
Expand All @@ -75,16 +75,16 @@ async function main() {
"zig",
["build", "run", "-Doptimize=ReleaseFast", "--", scenario, String(port)],
{
cwd: `${process.cwd()}/bench/zig-httpz`,
cwd: `${process.cwd()}/.github/bench/zig-httpz`,
stdio: ["ignore", "pipe", "inherit"],
},
)
: engine === "fiber"
? spawn("go", ["run", "./bench/fiber-server", scenario, String(port)], {
? spawn("go", ["run", "./.github/bench/fiber-server", scenario, String(port)], {
cwd: process.cwd(),
stdio: ["ignore", "pipe", "inherit"],
})
: spawn(targetRuntime, ["bench/target.js", engine, scenario, String(port)], {
: spawn(targetRuntime, [".github/bench/target.js", engine, scenario, String(port)], {
cwd: process.cwd(),
stdio: ["ignore", "pipe", "inherit"],
});
Expand Down
4 changes: 2 additions & 2 deletions bench/target.js → .github/bench/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from "node:path";
process.env.HTTP_NATIVE_NODE_PATH ??= resolve(process.cwd(), "http-native.release.node");
process.env.HTTP_NATIVE_NATIVE_PATH ??= process.env.HTTP_NATIVE_NODE_PATH;

const { createApp: createHttpNativeApp } = await import("../src/index.js");
const { createApp: createHttpNativeApp } = await import("../../src/index.js");

const [, , engine, scenario, portArg] = process.argv;
const port = Number(portArg ?? 0);
Expand Down Expand Up @@ -160,7 +160,7 @@ if (engine === "bun") {
} else if (engine === "http-native") {
await startFrameworkServer(createHttpNativeApp, "http-native", scenario);
} else if (engine === "old") {
const { createApp: createOldApp } = await import("../old/src/index.js");
const { createApp: createOldApp } = await import("../../old/src/index.js");
await startFrameworkServer(createOldApp, "old", scenario);
} else {
throw new Error(`Unsupported benchmark engine: ${engine}`);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bench/test-http.js → .github/bench/test-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from "node:path";

process.env.HTTP_NATIVE_NODE_PATH ??= resolve(process.cwd(), "http-native.release.node");

const { createApp } = await import("../src/index.js");
const { createApp } = await import("../../src/index.js");

const db = {
async getUser(id) {
Expand Down
2 changes: 1 addition & 1 deletion bench/test.js → .github/bench/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";

import { createApp } from "../src/index.js";
import { createApp } from "../../src/index.js";

const db = {
async getUser(id) {
Expand Down
12 changes: 6 additions & 6 deletions .github/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Each folder contains a self-contained example you can run with `bun`:
bun run build

# Then run any example
bun examples/basic/server.js
bun examples/cors/server.js
bun examples/middleware/server.js
bun examples/rest-api/server.js
bun examples/validation/server.js
bun examples/error-handling/server.js
bun .github/examples/basic/server.js
bun .github/examples/cors/server.js
bun .github/examples/middleware/server.js
bun .github/examples/rest-api/server.js
bun .github/examples/validation/server.js
bun .github/examples/error-handling/server.js
```

## Examples
Expand Down
18 changes: 18 additions & 0 deletions .github/tests/test-hot-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createApp } from "../../src/index.js";

const app = createApp();

/** [Auto generated by http-native]
* [http-native optimization] static-fast-path
* This route is served by the static fast path and avoids generic bridge dispatch.
*/
/** [Auto generated by http-native]
* [http-native optimization] static-fast-path
* This route is served by the static fast path and avoids generic bridge dispatch.
*/
app.get("/", (req, res) => {
res.json({ hello: "world", time: Date.now() });
});

const server = await app.listen({ port: 3000 });
console.log("Server running at " + server.url);
4 changes: 2 additions & 2 deletions test/test.js → .github/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import assert from "node:assert/strict";
import { Buffer } from "node:buffer";
import net from "node:net";

import httpServerConfig from "../src/http-server.config.js";
import { createApp } from "../src/index.js";
import httpServerConfig from "../../src/http-server.config.js";
import { createApp } from "../../src/index.js";

const stablePayload = {
ok: true,
Expand Down
29 changes: 14 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,15 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
rust-native/target
key: ${{ runner.os }}-cargo-${{ hashFiles('rust-native/Cargo.lock', 'rust-native/Cargo.toml') }}
target
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock', 'Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Install dependencies
run: bun install

- name: Build Rust native module
working-directory: rust-native
run: |
cargo build --release
echo "Rust native module built successfully"
Expand All @@ -104,48 +103,48 @@ jobs:

- name: Create output directories
run: |
mkdir -p bench/results/bun
mkdir -p bench/results/node
mkdir -p .github/bench/results/bun
mkdir -p .github/bench/results/node

- name: Run benchmarks (http-native on Bun + selected engines)
run: |
bun bench/ci.js \
bun .github/bench/ci.js \
--engines="${{ inputs.engines || 'http-native,bun' }}" \
--scenarios="${{ inputs.scenarios || 'static,dynamic,opt' }}" \
--connections="${{ inputs.connections || '200' }}" \
--duration="${{ inputs.duration || '10s' }}" \
--timeout="${{ inputs.timeout || '2s' }}" \
--http-native-runtime="bun" \
--output-dir="bench/results/bun"
--output-dir=".github/bench/results/bun"

- name: Run benchmarks (http-native on Node)
run: |
bun bench/ci.js \
bun .github/bench/ci.js \
--engines="http-native" \
--scenarios="${{ inputs.scenarios || 'static,dynamic,opt' }}" \
--connections="${{ inputs.connections || '200' }}" \
--duration="${{ inputs.duration || '10s' }}" \
--timeout="${{ inputs.timeout || '2s' }}" \
--http-native-runtime="node" \
--output-dir="bench/results/node"
--output-dir=".github/bench/results/node"

- name: Display results
if: always()
run: |
echo "=== Bun Runtime Results ==="
cat bench/results/bun/summary.md 2>/dev/null || echo "No Bun results"
cat .github/bench/results/bun/summary.md 2>/dev/null || echo "No Bun results"
echo ""
echo "=== Node Runtime Results ==="
cat bench/results/node/summary.md 2>/dev/null || echo "No Node results"
cat .github/bench/results/node/summary.md 2>/dev/null || echo "No Node results"

- name: Upload benchmark artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
bench/results/bun/results.json
bench/results/bun/summary.md
bench/results/node/results.json
bench/results/node/summary.md
.github/bench/results/bun/results.json
.github/bench/results/bun/summary.md
.github/bench/results/node/results.json
.github/bench/results/node/summary.md
if-no-files-found: ignore
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
node_modules/
target/
rust-native/target/
old/native/target/
.DS_Store
http-native.node
http-native.debug.node
Expand All @@ -13,5 +11,5 @@ old/
#opt/
.zig-cache
zig-httpz
bench/results/
.github/bench/results/
testing/
File renamed without changes.
1 change: 1 addition & 0 deletions rust-native/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[lib]
crate-type = ["cdylib"]
path = "rsrc/src/lib.rs"

[dependencies]
anyhow = "1.0"
Expand Down
File renamed without changes.
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@
"scripts": {
"build": "bun scripts/build-native.mjs",
"build:release": "bun scripts/build-native.mjs --release",
"dev:hot": "HTTP_NATIVE_HOT_RELOAD=1 bun test/app.ts",
"dev:hot": "HTTP_NATIVE_HOT_RELOAD=1 bun .github/tests/app.ts",
"dev": "bun src/hot.js",
"test": "bun run build && bun test/test.js",
"bench": "bun run build:release && bun bench/run.js",
"bench:http-native:static": "bun run build:release && bun bench/run.js http-native static 3001",
"bench:http-native:bun:static": "bun run build:release && bun bench/run.js http-native static 3001 bun",
"bench:http-native:node:static": "bun run build:release && bun bench/run.js http-native static 3001 node",
"bench:bun:static": "bun bench/run.js bun static 3000",
"bench:fiber:static": "bun bench/run.js fiber static 3009",
"bench:xitca:static": "bun bench/run.js xitca static 3003",
"bench:monoio:static": "bun bench/run.js monoio static 3004",
"bench:zig:static": "bun bench/run.js zig static 3005",
"bench:http-native:dynamic": "bun run build:release && bun bench/run.js http-native dynamic 3011",
"bench:http-native:bun:dynamic": "bun run build:release && bun bench/run.js http-native dynamic 3011 bun",
"bench:http-native:node:dynamic": "bun run build:release && bun bench/run.js http-native dynamic 3011 node",
"bench:bun:dynamic": "bun bench/run.js bun dynamic 3010",
"bench:fiber:dynamic": "bun bench/run.js fiber dynamic 3019",
"bench:xitca:dynamic": "bun bench/run.js xitca dynamic 3013",
"bench:monoio:dynamic": "bun bench/run.js monoio dynamic 3014",
"bench:zig:dynamic": "bun bench/run.js zig dynamic 3015",
"bench:http-native:opt": "bun run build:release && bun bench/run.js http-native opt 3021",
"bench:http-native:bun:opt": "bun run build:release && bun bench/run.js http-native opt 3021 bun",
"bench:http-native:node:opt": "bun run build:release && bun bench/run.js http-native opt 3021 node",
"bench:bun:opt": "bun bench/run.js bun opt 3020",
"bench:fiber:opt": "bun bench/run.js fiber opt 3029",
"bench:xitca:opt": "bun bench/run.js xitca opt 3023",
"bench:monoio:opt": "bun bench/run.js monoio opt 3024",
"bench:zig:opt": "bun bench/run.js zig opt 3025"
"test": "bun run build && bun .github/tests/test.js",
"bench": "bun run build:release && bun .github/bench/run.js",
"bench:http-native:static": "bun run build:release && bun .github/bench/run.js http-native static 3001",
"bench:http-native:bun:static": "bun run build:release && bun .github/bench/run.js http-native static 3001 bun",
"bench:http-native:node:static": "bun run build:release && bun .github/bench/run.js http-native static 3001 node",
"bench:bun:static": "bun .github/bench/run.js bun static 3000",
"bench:fiber:static": "bun .github/bench/run.js fiber static 3009",
"bench:xitca:static": "bun .github/bench/run.js xitca static 3003",
"bench:monoio:static": "bun .github/bench/run.js monoio static 3004",
"bench:zig:static": "bun .github/bench/run.js zig static 3005",
"bench:http-native:dynamic": "bun run build:release && bun .github/bench/run.js http-native dynamic 3011",
"bench:http-native:bun:dynamic": "bun run build:release && bun .github/bench/run.js http-native dynamic 3011 bun",
"bench:http-native:node:dynamic": "bun run build:release && bun .github/bench/run.js http-native dynamic 3011 node",
"bench:bun:dynamic": "bun .github/bench/run.js bun dynamic 3010",
"bench:fiber:dynamic": "bun .github/bench/run.js fiber dynamic 3019",
"bench:xitca:dynamic": "bun .github/bench/run.js xitca dynamic 3013",
"bench:monoio:dynamic": "bun .github/bench/run.js monoio dynamic 3014",
"bench:zig:dynamic": "bun .github/bench/run.js zig dynamic 3015",
"bench:http-native:opt": "bun run build:release && bun .github/bench/run.js http-native opt 3021",
"bench:http-native:bun:opt": "bun run build:release && bun .github/bench/run.js http-native opt 3021 bun",
"bench:http-native:node:opt": "bun run build:release && bun .github/bench/run.js http-native opt 3021 node",
"bench:bun:opt": "bun .github/bench/run.js bun opt 3020",
"bench:fiber:opt": "bun .github/bench/run.js fiber opt 3029",
"bench:xitca:opt": "bun .github/bench/run.js xitca opt 3023",
"bench:monoio:opt": "bun .github/bench/run.js monoio opt 3024",
"bench:zig:opt": "bun .github/bench/run.js zig opt 3025"
},
"dependencies": {
"@http-native/core": "^0.0.1"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions rust-native/build.log

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/build-native.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const cargoArgs = ["build"];
if (release) {
cargoArgs.push("--release");
}
cargoArgs.push("--manifest-path", "rust-native/Cargo.toml");
cargoArgs.push("--manifest-path", "Cargo.toml");

const result = Bun.spawnSync({
cmd: ["cargo", ...cargoArgs],
Expand All @@ -32,7 +32,7 @@ const platformArtifact =
? "http_native_napi.dll"
: "libhttp_native_napi.so";

const source = resolve(`rust-native/target/${profile}/${platformArtifact}`);
const source = resolve(`target/${profile}/${platformArtifact}`);
const profileTarget = resolve(`http-native.${profile}.node`);
const defaultTarget = resolve("http-native.node");

Expand Down
Loading
Loading