Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/file-server/btrfs/test/filesystem-stress.test.ts
1543 views
1
import { before, after, fs } from "./setup";
2
3
beforeAll(before);
4
5
const DEBUG = false;
6
const log = DEBUG ? console.log : (..._args) => {};
7
8
describe("stress operations with subvolumes", () => {
9
const count1 = 10;
10
it(`create ${count1} subvolumes in serial`, async () => {
11
const t = Date.now();
12
for (let i = 0; i < count1; i++) {
13
await fs.subvolumes.get(`${i}`);
14
}
15
log(
16
`created ${Math.round((count1 / (Date.now() - t)) * 1000)} subvolumes per second serial`,
17
);
18
});
19
20
it("list them and confirm", async () => {
21
const v = await fs.subvolumes.list();
22
expect(v.length).toBe(count1);
23
});
24
25
let count2 = 10;
26
it(`create ${count2} subvolumes in parallel`, async () => {
27
const v: any[] = [];
28
const t = Date.now();
29
for (let i = 0; i < count2; i++) {
30
v.push(fs.subvolumes.get(`p-${i}`));
31
}
32
await Promise.all(v);
33
log(
34
`created ${Math.round((count2 / (Date.now() - t)) * 1000)} subvolumes per second in parallel`,
35
);
36
});
37
38
it("list them and confirm", async () => {
39
const v = await fs.subvolumes.list();
40
expect(v.length).toBe(count1 + count2);
41
});
42
43
it("write a file to each volume", async () => {
44
for (const name of await fs.subvolumes.list()) {
45
const vol = await fs.subvolumes.get(name);
46
await vol.fs.writeFile("a.txt", "hi");
47
}
48
});
49
50
it("clone the first group in serial", async () => {
51
const t = Date.now();
52
for (let i = 0; i < count1; i++) {
53
await fs.subvolumes.clone(`${i}`, `clone-of-${i}`);
54
}
55
log(
56
`cloned ${Math.round((count1 / (Date.now() - t)) * 1000)} subvolumes per second serial`,
57
);
58
});
59
60
it("clone the second group in parallel", async () => {
61
const t = Date.now();
62
const v: any[] = [];
63
for (let i = 0; i < count2; i++) {
64
v.push(fs.subvolumes.clone(`p-${i}`, `clone-of-p-${i}`));
65
}
66
await Promise.all(v);
67
log(
68
`cloned ${Math.round((count2 / (Date.now() - t)) * 1000)} subvolumes per second parallel`,
69
);
70
});
71
72
it("delete the first batch serial", async () => {
73
const t = Date.now();
74
for (let i = 0; i < count1; i++) {
75
await fs.subvolumes.delete(`${i}`);
76
}
77
log(
78
`deleted ${Math.round((count1 / (Date.now() - t)) * 1000)} subvolumes per second serial`,
79
);
80
});
81
82
it("delete the second batch in parallel", async () => {
83
const v: any[] = [];
84
const t = Date.now();
85
for (let i = 0; i < count2; i++) {
86
v.push(fs.subvolumes.delete(`p-${i}`));
87
}
88
await Promise.all(v);
89
log(
90
`deleted ${Math.round((count2 / (Date.now() - t)) * 1000)} subvolumes per second in parallel`,
91
);
92
});
93
});
94
95
afterAll(after);
96
97