summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-01-04 16:14:19 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-01-04 16:14:19 +0100
commita5c57b93630a19609eaf7ff7af9cf66083661e04 (patch)
tree63cf993984e797e062cb25c0771b20cf31cd2504 /src/test
parentMerge branch 'master' of https://github.com/Trenite/discord-server-opensource (diff)
downloadserver-a5c57b93630a19609eaf7ff7af9cf66083661e04.tar.xz
:sparkles: update to use new lambert-server
Diffstat (limited to '')
-rw-r--r--src/test.ts10
-rw-r--r--src/test/db_benchmark.ts55
2 files changed, 55 insertions, 10 deletions
diff --git a/src/test.ts b/src/test.ts
deleted file mode 100644

index 8dc237d9..00000000 --- a/src/test.ts +++ /dev/null
@@ -1,10 +0,0 @@ -import { r } from "rethinkdb-ts"; - -async function main() { - await r.connectPool(); - - const result = await r.db("test").tableCreate("authors").run(); - console.log(result); -} - -main(); diff --git a/src/test/db_benchmark.ts b/src/test/db_benchmark.ts new file mode 100644
index 00000000..74623e06 --- /dev/null +++ b/src/test/db_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" })); + }); + } + })(); +}