Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/file-server/btrfs/test/subvolume-stress.test.ts
1543 views
1
import { before, after, fs } from "./setup";
2
import { mkdir, writeFile } from "fs/promises";
3
import { join } from "path";
4
import { type Subvolume } from "../subvolume";
5
6
const DEBUG = false;
7
const log = DEBUG ? console.log : (..._args) => {};
8
9
const numSnapshots = 25;
10
const numFiles = 1000;
11
12
beforeAll(before);
13
14
describe(`stress test creating ${numSnapshots} snapshots`, () => {
15
let vol: Subvolume;
16
it("creates a volume and write a file to it", async () => {
17
vol = await fs.subvolumes.get("stress");
18
});
19
20
it(`create file and snapshot the volume ${numSnapshots} times`, async () => {
21
const snaps: string[] = [];
22
const start = Date.now();
23
for (let i = 0; i < numSnapshots; i++) {
24
await writeFile(join(vol.path, `${i}.txt`), "world");
25
await vol.snapshots.create(`snap${i}`);
26
snaps.push(`snap${i}`);
27
}
28
log(
29
`created ${Math.round((numSnapshots / (Date.now() - start)) * 1000)} snapshots per second in serial`,
30
);
31
snaps.sort();
32
expect((await vol.snapshots.ls()).map(({ name }) => name).sort()).toEqual(
33
snaps.sort(),
34
);
35
});
36
37
it(`delete our ${numSnapshots} snapshots`, async () => {
38
for (let i = 0; i < numSnapshots; i++) {
39
await vol.snapshots.delete(`snap${i}`);
40
}
41
expect(await vol.snapshots.ls()).toEqual([]);
42
});
43
});
44
45
describe(`create ${numFiles} files`, () => {
46
let vol: Subvolume;
47
it("creates a volume", async () => {
48
vol = await fs.subvolumes.get("many-files");
49
});
50
51
it(`creates ${numFiles} files`, async () => {
52
const names: string[] = [];
53
const start = Date.now();
54
for (let i = 0; i < numFiles; i++) {
55
await writeFile(join(vol.path, `${i}`), "world");
56
names.push(`${i}`);
57
}
58
log(
59
`created ${Math.round((numFiles / (Date.now() - start)) * 1000)} files per second in serial`,
60
);
61
const v = await vol.fs.ls("");
62
const w = v.map(({ name }) => name);
63
expect(w.sort()).toEqual(names.sort());
64
});
65
66
it(`creates ${numFiles} files in parallel`, async () => {
67
await mkdir(join(vol.path, "p"));
68
const names: string[] = [];
69
const start = Date.now();
70
const z: any[] = [];
71
for (let i = 0; i < numFiles; i++) {
72
z.push(writeFile(join(vol.path, `p/${i}`), "world"));
73
names.push(`${i}`);
74
}
75
await Promise.all(z);
76
log(
77
`created ${Math.round((numFiles / (Date.now() - start)) * 1000)} files per second in parallel`,
78
);
79
const t0 = Date.now();
80
const v = await vol.fs.ls("p");
81
log("get listing of files took", Date.now() - t0, "ms");
82
const w = v.map(({ name }) => name);
83
expect(w.sort()).toEqual(names.sort());
84
});
85
});
86
87
afterAll(after);
88
89