Skip to content

Commit

Permalink
feat: benchmarks against fastify (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerioageno authored Mar 5, 2024
1 parent b671f98 commit bcf6694
Show file tree
Hide file tree
Showing 35 changed files with 1,018 additions and 374 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Cargo.lock
client2/
.vscode/

client/dist
dist
process.yml
tarpaulin*
tarpaulin*
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ path = "examples/axum.rs"
[[example]]
name = "multi"
path = "examples/multi-thread.rs"

[[example]]
name = "webpack"
path = "examples/webpack-react/server.rs"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ It use an embedded version of the v8 javascript engine (<a href="https://github.

Currently it works with Webpack bundler v5.65.0.

> Check <a href="https://github.com/Valerioageno/ssr-rs/blob/main/benches">here</a> the benchmark results.
## Getting started

Add this to your `Cargo.toml`:
Expand Down
60 changes: 58 additions & 2 deletions benches/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
Custom HTTP benchmarks are performed using https://github.com/wg/wrk
# Benchmarks

?? Give a try to https://github.com/tsliwowicz/go-wrk
> Benchmarks have been performed using [wrk](https://github.com/wg/wrk)
> Benches refers to ssr_rs v0.3.0
The main crate goal is to be blazingly fast (as the rest of the rust ecosystem).
Following the outcome of the same application built and run by `actix-rs + ssr_rs` and by `node` with a fastify server.

The source code is in the <a href="https://github.com/Valerioageno/ssr-rs/blob/main/examples/webpack-react">examples/webpack-react</a> folder.

## Actix-rs + ssr_rs

```bash
$ cd examples/webpack-react
$ pnpm i && pnpm build:ssr
$ cargo run --example webpack
```

```bash
❯ wrk -t12 -c400 -d30s http://localhost:8080
Running 30s test @ http://localhost:8080
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 2.26ms 5.11ms 277.87ms 94.32%
Req/Sec 22.27k 3.02k 31.52k 85.39%
8011933 requests in 30.10s, 5.01GB read
Requests/sec: 266177.68
Transfer/sec: 170.33MB
```

## Node + fastify

```bash
$ cd examples/webpack-react
$ pnpm i && pnpm build:server
$ node dist/server/bundle.cjs
```

```bash
❯ wrk -t12 -c400 -d30s http://localhost:3000
Running 30s test @ http://localhost:3000
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 24.04ms 105.19ms 1.99s 98.28%
Req/Sec 2.72k 519.60 11.72k 95.72%
954264 requests in 30.06s, 662.52MB read
Socket errors: connect 0, read 0, write 0, timeout 48
Requests/sec: 31740.30
Transfer/sec: 22.04MB
```

My computer setup:

CPU: Intel Core i5 13600KF

Memory: DDR5 32Gb 3000MHz CL36 Intel XMP

Benches ran on a WLS machine with Ubuntu installed
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 34 additions & 17 deletions client/package.json → examples/webpack-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,44 @@
"type": "module",
"dependencies": {
"@loadable/component": "^5.15.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/loadable__component": "^5.13.4",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"fastify": "^4.26.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"ts-loader": "^8.1.0",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "parcel",
"test": "jest",
"build:all": "webpack --config ./webpack.client.build.js --progress && webpack --config ./webpack.ssr.js --progress",
"build:client": "webpack --config ./webpack.client.build.js --progress",
"build:ssr": "webpack --config ./webpack.ssr.js --progress"
"build:ssr": "webpack --config ./webpack.ssr.js --progress",
"build:server": "webpack --config ./webpack.server.build.js --progress"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "jsdom",
"moduleFileExtensions": ["ts", "tsx", "js"],
"setupFilesAfterEnv": ["<rootDir>/src/setupTests.ts"],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"setupFilesAfterEnv": [
"<rootDir>/src/setupTests.ts"
],
"moduleNameMapper": {
".+\\.css$": "<rootDir>/src/styleMock.ts",
".+\\.svg$": "<rootDir>/src/styleMock.ts"
},
"testMatch": ["**/*.(test|spec).(ts|tsx|js)"]
"testMatch": [
"**/*.(test|spec).(ts|tsx|js)"
]
},
"eslintConfig": {
"extends": ["react-app", "react-app/jest"]
"extends": [
"react-app",
"react-app/jest"
]
},
"targets": {
"client": {
Expand All @@ -49,21 +53,34 @@
}
},
"browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"],
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"ts-jest": "^27.1.1",
"jest": "^27.4.5",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.12",
"@types/loadable__component": "^5.13.9",
"@types/node": "^20.11.24",
"@types/react": "^18.2.63",
"@types/react-dom": "^18.2.20",
"clean-webpack-plugin": "^4.0.0-alpha.0",
"css-loader": "^5.2.2",
"file-loader": "^6.2.0",
"jest": "^27.4.5",
"mini-css-extract-plugin": "^1.5.0",
"parcel": "^2.0.1",
"ts-jest": "^27.1.1",
"typescript": "^5.3.3",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
},
Expand Down
Loading

0 comments on commit bcf6694

Please sign in to comment.