-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.mjs
62 lines (53 loc) · 1.44 KB
/
index.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
"use strict";
import { Consumer } from "./src/consumer.mjs";
import { Producer } from "./src/producer.mjs";
const transporter = process.env.TRANSPORTER || "Fake";
const serializer = process.env.SERIALIZER || "JSON";
const discoverer = process.env.DISCOVERER || "Local";
let duration = process.env.DURATION || null;
if (duration != null) {
duration = Number(duration);
}
let mode = process.env.MODE;
if (mode != "consumer" && mode != "producer") {
mode = null;
}
let nodeID = process.env.NODE_ID;
console.log("Performance tester");
console.log("==================");
console.log("");
console.log(" Transporter:", transporter);
console.log(" Serializer:", serializer);
console.log(" Discoverer:", discoverer);
if (duration) console.log(" Test duration:", duration, "seconds");
if (mode) console.log(" Mode:", mode);
if (nodeID) console.log(" Node ID:", nodeID);
console.log("");
let consumer, producer;
if (!mode || mode == "producer") {
producer = new Producer({
transporter,
serializer,
registry: {
discoverer
},
nodeID: !mode ? `producer-${nodeID || process.pid}` : nodeID,
mode,
duration
});
}
if (!mode || mode == "consumer") {
consumer = new Consumer({
transporter,
serializer,
discoverer,
nodeID: !mode ? `consumer-${nodeID || process.pid}` : nodeID,
mode,
duration
});
}
async function start() {
if (consumer) await consumer.start();
if (producer) await producer.start();
}
start().catch(err => console.error(err));