/
run-simulations.mjs
90 lines (83 loc) · 4.7 KB
/
run-simulations.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import fs from 'fs';
import path from 'path';
import { spawn } from 'child_process';
const CONCURRENCY = 3;
const __dirname = path.resolve();
const matrix =
// Compression / Density
[ { "window": 100, "delay": 120, numberOfClients: 5000, compression: 1000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 2500 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 5000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 10000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 11000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 12000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 13000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 14000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 15000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 16000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 17000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 18000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 19000 }
, { "window": 100, "delay": 120, numberOfClients: 5000, compression: 20000 }
// Settlement Delay
, { "window": 100, "delay": 30, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 60, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 90, numberOfClients: 5000, compression: 20000 }
// , { "window": 100, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 150, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 180, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 210, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 240, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 270, numberOfClients: 5000, compression: 20000 }
, { "window": 100, "delay": 300, numberOfClients: 5000, compression: 20000 }
// Payment Window
, { "window": 50, "delay": 120, numberOfClients: 5000, compression: 20000 }
// , { "window": 100, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 200, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 300, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 400, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 500, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 600, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 700, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 800, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 900, "delay": 120, numberOfClients: 5000, compression: 20000 }
, { "window": 1000, "delay": 120, numberOfClients: 5000, compression: 20000 }
// Number of Clients
, { "window": 100, "delay": 120, numberOfClients: 1000, compression: 20000 }
, { "window": 100, "delay": 120, numberOfClients: 1500, compression: 20000 }
, { "window": 100, "delay": 120, numberOfClients: 2000, compression: 20000 }
, { "window": 100, "delay": 120, numberOfClients: 2500, compression: 20000 }
, { "window": 100, "delay": 120, numberOfClients: 3000, compression: 20000 }
, { "window": 100, "delay": 120, numberOfClients: 3500, compression: 20000 }
, { "window": 100, "delay": 120, numberOfClients: 4000, compression: 20000 }
, { "window": 100, "delay": 120, numberOfClients: 4500, compression: 20000 }
// , { "window": 100, "delay": 120, numberOfClients: 5000, compression: 20000 }
]
let cursor = 0;
let pipeline = [];
for (let i = 0; i < CONCURRENCY; i += 1) {
pipeline.push(schedule())
}
await Promise.all(pipeline);
async function schedule() {
if (matrix[cursor]) {
const { window, delay, numberOfClients, compression } = matrix[cursor];
console.log(`Running simulation ${JSON.stringify(matrix[cursor])}`);
cursor += 1;
const filename = `events-clients:${numberOfClients}-compression:${compression}`;
const writer = fs.createWriteStream(path.join(__dirname, "..", "..", `${filename}-window:${window}-delay:${delay}`));
const pipeline = spawn("hydra-tail-simulation", [ "run"
, "--payment-window", window
, "--settlement-delay", delay
, path.join(__dirname, "datasets", `${filename}.csv`)
])
const promise = new Promise((resolve) => {
pipeline.stdout.on('data', chunk => writer.write(chunk));
pipeline.on('close', () => {
writer.end();
resolve()
});
});
return promise.then(schedule)
}
}