-
Notifications
You must be signed in to change notification settings - Fork 1
/
writer.ts
59 lines (48 loc) · 1.3 KB
/
writer.ts
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
import KafkaGoSaur from "../mod.ts";
import { KafkaWriterConfig } from "../writer.ts";
import { SASLMechanism } from "../security/sasl.ts";
import { bench, runBenchmarks } from "./deps.ts";
import { broker, password, topic, username } from "./config.ts";
const nrOfRuns = 10;
const nrOfMessages = 100000;
const msgBatchSize = 10000;
const msgSize = 1024;
const writerConfig: KafkaWriterConfig = {
address: broker,
topic,
sasl: {
mechanism: SASLMechanism.PLAIN,
username,
password,
},
tls: {
insecureSkipVerify: true,
},
};
const kafkaGoSaur = new KafkaGoSaur();
const writer = await kafkaGoSaur.createWriter(writerConfig);
const value = new Uint8Array(msgSize);
crypto.getRandomValues(value);
bench({
name: `writeMessages#${nrOfMessages}`,
runs: nrOfRuns,
async func(b): Promise<void> {
b.start();
for (let i = 0; i < nrOfMessages / msgBatchSize; i++) {
const msgs = [];
for (let j = 0; j < msgBatchSize; j++) {
msgs.push({ value });
}
await writer.writeMessages(msgs);
}
b.stop();
},
});
const benchmarkRunResults = await runBenchmarks();
console.log(benchmarkRunResults);
console.log(
`[kafkagosaur] writeMessages msgs/s: ${
nrOfMessages / (benchmarkRunResults.results[0].measuredRunsAvgMs / 1000)
}`,
);
await writer.close();