summary refs log tree commit diff
path: root/src/test/rethink_benchmark.ts
blob: 74623e06f3226a12ce6734c197b6e0069f1c4118 (plain) (blame)
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
// @ts-nocheck
import { r } from "rethinkdb-ts";
import faker from "faker";
import cluster from "cluster";
import { performance } from "perf_hooks";

console.log("starting");

if (cluster.isMaster) {
	for (var i = 0; i < 1; i++) {
		cluster.fork();
	}
	console.log("all nodes started");
}

if (cluster.isWorker) {
	const inserts = [];

	for (let i = 0; i < 100; i++) {
		inserts.push({
			color: faker.commerce.color(),
			department: faker.commerce.department(),
			price: faker.commerce.price(),
			product: faker.commerce.product(),
			productAdjective: faker.commerce.productAdjective(),
			productName: faker.commerce.productName(),
			productMaterial: faker.commerce.productMaterial(),
			productDescription: faker.commerce.productDescription(),
		});
	}

	async function main(connection) {
		const start = performance.now();
		await r
			.db("test")
			.table("test")
			.nth(Math.floor(Math.random() * 300000))
			.run(connection);
		const end = performance.now();
		// console.log(end - start);

		// await main(connection);
		setTimeout(main.bind(null, connection));
	}

	(async () => {
		const threads = 30;

		for (var i = 0; i < threads; i++) {
			setTimeout(async () => {
				main(await r.connect({ port: 28015, host: "192.168.178.122" }));
			});
		}
	})();
}