Skip to content

Commit a56bc7e

Browse files
[JavaScript] Add Mesh (#8816)
* [JavaScript] Add Mesh * chore: use mongodb@3 * fix: headers
1 parent 30ab632 commit a56bc7e

File tree

13 files changed

+751
-0
lines changed

13 files changed

+751
-0
lines changed

frameworks/JavaScript/mesh/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Mesh Benchmarking Test
2+
3+
This is the [`Mesh`](https://github.com/ionited/mesh) portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
4+
5+
Information about Mesh can be found at https://github.com/ionited/mesh
6+
7+
## Database Drivers
8+
9+
There are individual handlers for each DB approach. The logic for each of them are found here:
10+
11+
* [MySQL](drivers/mysql.js)
12+
* [MongoDB](drivers/mongodb.js)
13+
* [PostgreSQL](drivers/postgres.js)
14+
15+
There are **no database endpoints** or drivers attached by default.<br>
16+
To initialize the application with one of these, run any _one_ of the following commands:
17+
18+
```sh
19+
$ DATABASE=mysql node app.js
20+
$ DATABASE=mongodb node app.js
21+
$ DATABASE=postgres node app.js
22+
```
23+
24+
## Test Endpoints
25+
26+
> Visit the test requirements [here](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview)
27+
28+
```sh
29+
$ curl localhost:8080/json
30+
$ curl localhost:8080/plaintext
31+
32+
# The following are only available w/ DATABASE
33+
34+
$ curl localhost:8080/db
35+
$ curl localhost:8080/fortunes
36+
37+
$ curl localhost:8080/updates?queries=
38+
$ curl localhost:8080/updates?queries=2
39+
$ curl localhost:8080/updates?queries=1000
40+
$ curl localhost:8080/updates?queries=foo
41+
$ curl localhost:8080/updates?queries=0
42+
43+
$ curl localhost:8080/queries?queries=
44+
$ curl localhost:8080/queries?queries=2
45+
$ curl localhost:8080/queries?queries=1000
46+
$ curl localhost:8080/queries?queries=foo
47+
$ curl localhost:8080/queries?queries=0
48+
```

frameworks/JavaScript/mesh/app.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const cluster = require("cluster");
2+
const numCPUs = require("os").cpus().length;
3+
4+
if (cluster.isPrimary) {
5+
console.log(`Primary ${process.pid} is running`);
6+
7+
// Fork workers.
8+
for (let i = 0; i < numCPUs; i++) {
9+
cluster.fork();
10+
}
11+
12+
cluster.on('exit', (worker, code, signal) => {
13+
console.log(`worker ${worker.process.pid} died`);
14+
});
15+
} else {
16+
// worker task
17+
require("./server");
18+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"framework": "mesh",
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/json",
7+
"plaintext_url": "/plaintext",
8+
"port": 8080,
9+
"approach": "Realistic",
10+
"classification": "Platform",
11+
"database": "None",
12+
"framework": "mesh",
13+
"language": "JavaScript",
14+
"flavor": "NodeJS",
15+
"orm": "Raw",
16+
"platform": "nodejs",
17+
"webserver": "None",
18+
"os": "Linux",
19+
"database_os": "Linux",
20+
"display_name": "Mesh",
21+
"notes": "",
22+
"versus": "nodejs"
23+
},
24+
"mysql": {
25+
"dockerfile": "mesh-mysql.dockerfile",
26+
"db_url": "/db",
27+
"query_url": "/queries?queries=",
28+
"fortune_url": "/fortunes",
29+
"update_url": "/updates?queries=",
30+
"port": 8080,
31+
"approach": "Realistic",
32+
"classification": "Platform",
33+
"database": "MySQL",
34+
"framework": "mesh",
35+
"language": "JavaScript",
36+
"flavor": "NodeJS",
37+
"orm": "Raw",
38+
"platform": "nodejs",
39+
"webserver": "None",
40+
"os": "Linux",
41+
"database_os": "Linux",
42+
"display_name": "Mesh",
43+
"notes": "",
44+
"versus": "nodejs"
45+
},
46+
"postgres": {
47+
"dockerfile": "mesh-postgres.dockerfile",
48+
"db_url": "/db",
49+
"query_url": "/queries?queries=",
50+
"fortune_url": "/fortunes",
51+
"update_url": "/updates?queries=",
52+
"port": 8080,
53+
"approach": "Realistic",
54+
"classification": "Platform",
55+
"database": "Postgres",
56+
"framework": "mesh",
57+
"language": "JavaScript",
58+
"flavor": "NodeJS",
59+
"orm": "Raw",
60+
"platform": "None",
61+
"webserver": "None",
62+
"os": "Linux",
63+
"database_os": "Linux",
64+
"display_name": "Mesh",
65+
"notes": "",
66+
"versus": "nodejs"
67+
},
68+
"mongodb": {
69+
"dockerfile": "mesh-mongodb.dockerfile",
70+
"db_url": "/db",
71+
"query_url": "/queries?queries=",
72+
"fortune_url": "/fortunes",
73+
"update_url": "/updates?queries=",
74+
"port": 8080,
75+
"approach": "Realistic",
76+
"classification": "Platform",
77+
"database": "MongoDB",
78+
"framework": "mesh",
79+
"language": "JavaScript",
80+
"flavor": "NodeJS",
81+
"orm": "Raw",
82+
"platform": "None",
83+
"webserver": "None",
84+
"os": "Linux",
85+
"database_os": "Linux",
86+
"display_name": "Mesh",
87+
"notes": "",
88+
"versus": "nodejs"
89+
}
90+
}
91+
]
92+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { MongoClient } = require('mongodb');
2+
3+
let World, Fortune;
4+
const projection = { _id:0 };
5+
6+
MongoClient.connect('mongodb://tfb-database:27017', { useNewUrlParser:true }, (err, ctx) => {
7+
const DB = ctx.db('hello_world');
8+
Fortune = DB.collection('fortune');
9+
World = DB.collection('world');
10+
});
11+
12+
exports.fortunes = () => Fortune.find({}, { projection }).toArray();
13+
14+
exports.find = id => World.findOne({ id }, { projection });
15+
16+
exports.update = obj => World.replaceOne({ id:obj.id }, obj);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { createConnection } = require('mysql');
2+
3+
const connection = createConnection({
4+
host: 'tfb-database',
5+
user: 'benchmarkdbuser',
6+
password: 'benchmarkdbpass',
7+
database: 'hello_world'
8+
});
9+
10+
connection.connect();
11+
12+
function query(text, values) {
13+
return new Promise((res, rej) => {
14+
connection.query(text, values || [], (err, results) => {
15+
return err ? rej(err) : res(results);
16+
});
17+
});
18+
}
19+
20+
exports.fortunes = () => query('SELECT * FROM fortune');
21+
22+
exports.find = id => query('SELECT * FROM world WHERE id = ?', [id]).then(arr => arr[0]);
23+
24+
exports.update = obj => query('UPDATE world SET randomNumber = ? WHERE id = ?', [obj.randomNumber, obj.id]);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { Client } = require('pg');
2+
3+
const client = new Client({
4+
host: 'tfb-database',
5+
user: 'benchmarkdbuser',
6+
password: 'benchmarkdbpass',
7+
database: 'hello_world'
8+
});
9+
10+
client.connect();
11+
12+
function query(text, values) {
13+
return client.query(text, values || []).then(r => r.rows);
14+
}
15+
16+
exports.fortunes = () => query('SELECT * FROM fortune');
17+
18+
exports.find = id => query('SELECT * FROM world WHERE id = $1', [id]).then(arr => arr[0]);
19+
20+
exports.update = obj => query('UPDATE world SET randomNumber = $1 WHERE id = $2', [obj.randomNumber, obj.id]);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:20-slim
2+
3+
COPY ./ ./
4+
5+
RUN npm install
6+
7+
ENV NODE_ENV production
8+
ENV DATABASE mongodb
9+
10+
EXPOSE 8080
11+
12+
CMD ["node", "app.js"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:20-slim
2+
3+
COPY ./ ./
4+
5+
RUN npm install
6+
7+
ENV NODE_ENV production
8+
ENV DATABASE mysql
9+
10+
EXPOSE 8080
11+
12+
CMD ["node", "app.js"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:20-slim
2+
3+
COPY ./ ./
4+
5+
RUN npm install
6+
7+
ENV NODE_ENV production
8+
ENV DATABASE postgres
9+
10+
EXPOSE 8080
11+
12+
CMD ["node", "app.js"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:20-slim
2+
3+
COPY ./ ./
4+
5+
RUN npm install
6+
7+
ENV NODE_ENV production
8+
9+
EXPOSE 8080
10+
11+
CMD ["node", "app.js"]

0 commit comments

Comments
 (0)