Skip to content

Commit 3a005fd

Browse files
committed
memory: add memory example
1 parent 5a7f54c commit 3a005fd

File tree

4 files changed

+1312
-0
lines changed

4 files changed

+1312
-0
lines changed

2-memory/benchmark.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict'
2+
3+
const autocannon = require('autocannon');
4+
5+
async function main () {
6+
const result = await autocannon({
7+
url: 'http://localhost:3000',
8+
connections: 10,
9+
duration: 120,
10+
})
11+
console.log(autocannon.printResult(result));
12+
}
13+
14+
main();

2-memory/index.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const express = require('express');
4+
const pkgJson = require('../package.json');
5+
6+
if (!process.env.NSOLID_SAAS && !hasPkgJsonConf()) {
7+
console.error('You forgot to pass NSOLID_SAAS environment variable.');
8+
process.exit(1);
9+
}
10+
11+
const app = express();
12+
13+
app.get('/', (req, res) => {
14+
res.send({ name: name() });
15+
});
16+
17+
app.listen(3000, () => {
18+
console.log('Server is running on port 3000');
19+
console.info('🛈 In a separate terminal run: node benchmark.js');
20+
});
21+
22+
const namesGenerator = require('docker-namesgenerator');
23+
const names = {};
24+
25+
function name () {
26+
let result = namesGenerator();
27+
if (names[result]) {
28+
result += names[result]++;
29+
}
30+
names[result] = 1;
31+
return result;
32+
}
33+
34+
function hasPkgJsonConf() {
35+
return pkgJson.nsolid && pkgJson.nsolid.saas !== '';
36+
}

0 commit comments

Comments
 (0)