Skip to content

Commit a358c6c

Browse files
committed
fs: add benchmark for stat-intensive scenario
1 parent 57f3e7e commit a358c6c

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

tools/api-tester/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ All commands below should be run from the root directory of puter.
4545
4646
### Shorthands
4747
48-
- Run unit tests only:
48+
- Run all tests (unit tests and benchmarks):
49+
50+
```bash
51+
node ./tools/api-tester/apitest.js --config=./tools/api-tester/config.yml
52+
```
53+
54+
- Run all unit tests:
4955
5056
```bash
5157
node ./tools/api-tester/apitest.js --config=./tools/api-tester/config.yml --unit
5258
```
5359
54-
- Run benchmarks only:
60+
- Run all benchmarks:
5561
5662
```bash
5763
node ./tools/api-tester/apitest.js --config=./tools/api-tester/config.yml --bench
@@ -63,6 +69,12 @@ All commands below should be run from the root directory of puter.
6369
node ./tools/api-tester/apitest.js --config=./tools/api-tester/config.yml --unit --suite=mkdir
6470
```
6571
72+
- Filter benchmarks by name:
73+
74+
```bash
75+
node ./tools/api-tester/apitest.js --config=./tools/api-tester/config.yml --bench --suite=stat_intensive_1
76+
```
77+
6678
- Stop on first failure:
6779
6880
```bash

tools/api-tester/apitest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const main = async () => {
100100
for ( const result of benchmark_results ) {
101101
if ( seen.has(result.name) ) continue;
102102
seen.add(result.name);
103-
console.log(result.name + ' - ' + result.description);
103+
console.log(result.name + ': ' + result.description);
104104
}
105105
}
106106

@@ -146,7 +146,7 @@ async function test({ mountpoint }) {
146146
if ( unit ) {
147147
await registry.run_all_tests(suiteName);
148148
} else if ( bench ) {
149-
await registry.run_all_benches();
149+
await registry.run_all_benches(suiteName);
150150
} else {
151151
await registry.run_all();
152152
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = registry => {
2-
registry.add_bench('write-intensive-1', require('./write_intensive_1.js'));
2+
registry.add_bench('write_intensive_1', require('./write_intensive_1.js'));
3+
registry.add_bench('stat_intensive_1', require('./stat_intensive_1.js'));
34
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const chai = require('chai');
2+
chai.use(require('chai-as-promised'))
3+
const expect = chai.expect;
4+
5+
module.exports = {
6+
name: 'stat intensive 1',
7+
description: 'create 10 directories and 100 subdirectories in each, then stat them intensively',
8+
do: async t => {
9+
console.log('stat intensive 1');
10+
11+
const dir_count = 10;
12+
const subdir_count = 100;
13+
14+
// key: uuid
15+
// value: path
16+
const dirs = {};
17+
18+
for (let i = 0; i < dir_count; i++) {
19+
await t.mkdir(`dir_${i}`);
20+
for (let j = 0; j < subdir_count; j++) {
21+
const subdir = await t.mkdir(`dir_${i}/subdir_${j}`);
22+
dirs[subdir.uid] = subdir.path;
23+
}
24+
}
25+
26+
for (let i = 0; i < 10; i++) {
27+
for (const [uuid, path] of Object.entries(dirs)) {
28+
const stat = await t.stat_uuid(uuid);
29+
expect(stat.is_dir).equal(true);
30+
expect(stat.path).equal(path);
31+
}
32+
}
33+
}
34+
};

tools/api-tester/lib/TestRegistry.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,22 @@ module.exports = class TestRegistry {
4545
// copilot was able to write everything below this line
4646
// and I think that's pretty cool
4747

48-
async run_all_benches () {
48+
async run_all_benches (suiteName) {
49+
// check if "suiteName" is valid
50+
if (suiteName && !Object.keys(this.benches).includes(suiteName)) {
51+
throw new Error(`Suite not found: ${suiteName}, valid suites are: ${Object.keys(this.benches).join(', ')}`);
52+
}
53+
4954
for ( const [id, bench_definition] of Object.entries(this.benches) ) {
55+
if (suiteName && id !== suiteName) {
56+
continue;
57+
}
58+
5059
console.log(`running bench: ${id}`);
60+
61+
// reset the working directory
62+
await this.t.init_working_directory();
63+
5164
await this.t.runBenchmark(bench_definition);
5265
}
5366
}

tools/api-tester/lib/TestSDK.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ module.exports = class TestSDK {
9090
this.nameStack.join(` \x1B[36;1m->\x1B[0m `);
9191
process.stdout.write(strid + ' ... \n');
9292

93+
this.resetCwd();
94+
9395
this.nameStack.push(benchDefinition.name);
9496
const start = Date.now();
9597
try {
@@ -271,6 +273,13 @@ module.exports = class TestSDK {
271273
const res = await this.post('stat', { ...params, path });
272274
return res.data;
273275
}
276+
this.stat_uuid = async (uuid, params) => {
277+
// for stat(uuid) api:
278+
// - use "uid" for "uuid"
279+
// - there have to be a "subject" field which is the same as "uid"
280+
const res = await this.post('stat', { ...params, uid: uuid, subject: uuid });
281+
return res.data;
282+
}
274283
this.statu = async (uid, params) => {
275284
const res = await this.post('stat', { ...params, uid });
276285
return res.data;

0 commit comments

Comments
 (0)