Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Sep 20, 2023
2 parents 42e804f + 63b0451 commit 8fe93d1
Show file tree
Hide file tree
Showing 24 changed files with 261 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-slim
FROM node:20-slim

COPY ./ ./

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-slim
FROM node:20-slim

COPY ./ ./

Expand Down
1 change: 1 addition & 0 deletions frameworks/JavaScript/velocy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
4 changes: 4 additions & 0 deletions frameworks/JavaScript/velocy/README.md
Original file line number Diff line number Diff line change
@@ -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)
46 changes: 46 additions & 0 deletions frameworks/JavaScript/velocy/app.js
Original file line number Diff line number Diff line change
@@ -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`);
}
26 changes: 26 additions & 0 deletions frameworks/JavaScript/velocy/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
14 changes: 14 additions & 0 deletions frameworks/JavaScript/velocy/config.toml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions frameworks/JavaScript/velocy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"velocy": "0.0.13"
}
}
6 changes: 6 additions & 0 deletions frameworks/JavaScript/velocy/velocy.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:20-slim
WORKDIR /usr/app
COPY ./ /usr/app
RUN npm install
EXPOSE 8080
CMD ["node", "app.js"]
2 changes: 1 addition & 1 deletion frameworks/Rust/salvo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Rust/salvo/src/db_pg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Fortune>, Error> {
pub async fn fetch_all_fortunes(client: &Client, select: &Statement) -> Result<Vec<Fortune>, Error> {
let rows: Vec<Row> = client.query(select, &[]).await.unwrap();

let mut fortunes: Vec<Fortune> = Vec::with_capacity(rows.capacity());
Expand Down
4 changes: 4 additions & 0 deletions frameworks/Rust/salvo/src/main_diesel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<World>(&mut conn)?;
drop(conn);

let data = serde_json::to_vec(&world).unwrap();
let headers = res.headers_mut();
Expand All @@ -75,6 +76,7 @@ async fn queries(req: &mut Request, res: &mut Response) -> Result<(), Error> {
let w = world::table.find(id).get_result::<World>(&mut conn)?;
worlds.push(w);
}
drop(conn);

let data = serde_json::to_vec(&worlds)?;
let headers = res.headers_mut();
Expand Down Expand Up @@ -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();
Expand All @@ -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::<Fortune>(&mut conn)?;
drop(conn);
items.push(Fortune {
id: 0,
message: "Additional fortune added at request time.".to_string(),
Expand Down
6 changes: 5 additions & 1 deletion frameworks/Rust/salvo/src/main_pg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<World> = future_worlds.try_collect().await?;
drop(client);

let data = serde_json::to_vec(&worlds)?;
let headers = res.headers_mut();
Expand Down Expand Up @@ -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<u64> = future_world_updates.try_collect().await?;
drop(client);

let data = serde_json::to_vec(&worlds)?;
let headers = res.headers_mut();
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Rust/xitca-web/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading

0 comments on commit 8fe93d1

Please sign in to comment.