From 76000f8fa11dde2f67efdb22a87c4644ea49f9eb Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 30 Jan 2021 19:58:15 +0100 Subject: :sparkles: Util --- src/test/rethink_benchmark.ts | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/test/rethink_benchmark.ts (limited to 'src/test/rethink_benchmark.ts') diff --git a/src/test/rethink_benchmark.ts b/src/test/rethink_benchmark.ts new file mode 100644 index 00000000..74623e06 --- /dev/null +++ b/src/test/rethink_benchmark.ts @@ -0,0 +1,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" })); + }); + } + })(); +} -- cgit 1.5.1