From 51dd435fd781fe50c77c543295f3c4980fc449bf Mon Sep 17 00:00:00 2001 From: acarbonetto Date: Mon, 25 Sep 2023 15:10:47 -0700 Subject: [PATCH] Move duplicated logic in benchmark JS scripts to a single file, and convert to TypeScript. (#456) removed duplicated logic and refactored to typescript Signed-off-by: acarbonetto --- benchmarks/install_and_test.sh | 8 +++- benchmarks/utilities/fill_db.js | 73 --------------------------------- 2 files changed, 7 insertions(+), 74 deletions(-) delete mode 100644 benchmarks/utilities/fill_db.js diff --git a/benchmarks/install_and_test.sh b/benchmarks/install_and_test.sh index a6db3c0e51..ba44e3323a 100755 --- a/benchmarks/install_and_test.sh +++ b/benchmarks/install_and_test.sh @@ -231,7 +231,11 @@ do ;; -is-cluster) clusterFlag="--clusterModeEnabled" - ;; + ;; + -port) + portFlag="--port "$2 + shift + ;; esac shift done @@ -276,6 +280,8 @@ do fi done + + flushDB if [ $writeResultsCSV == 1 ]; diff --git a/benchmarks/utilities/fill_db.js b/benchmarks/utilities/fill_db.js deleted file mode 100644 index 85c656c030..0000000000 --- a/benchmarks/utilities/fill_db.js +++ /dev/null @@ -1,73 +0,0 @@ -import commandLineArgs from "command-line-args"; -import { createClient, createCluster } from "redis"; - -const SIZE_SET_KEYSPACE = 3000000; // 3 million - -const PORT = 6379; -function getAddress(host, tls, port) { - const protocol = tls ? "rediss" : "redis"; - return `${protocol}://${host}:${port ?? PORT}`; -} - -function generate_value(size) { - return "0".repeat(size); -} - -function createRedisClient(host, isCluster, tls, port) { - return isCluster - ? createCluster({ - rootNodes: [{ socket: { host, port: port ?? PORT, tls } }], - defaults: { - socket: { - tls, - }, - }, - useReplicas: true, - }) - : createClient({ - url: getAddress(host, tls, port), - }); -} - -async function fill_database(data_size, host, isCluster, tls, port) { - const client = await createRedisClient(host, isCluster, tls, port); - const data = generate_value(data_size); - await client.connect(); - - const CONCURRENT_SETS = 1000; - var sets = Array.from(Array(CONCURRENT_SETS).keys()).map(async (index) => { - for (let i = 0; i < SIZE_SET_KEYSPACE / CONCURRENT_SETS; ++i) { - var key = (index * CONCURRENT_SETS + index).toString(); - await client.set(key, data); - } - }); - - await Promise.all(sets); - await client.quit(); -} - -const optionDefinitions = [ - { name: "dataSize", type: String }, - { name: "host", type: String }, - { name: "tls", type: Boolean }, - { name: "clusterModeEnabled", type: Boolean }, - { name: "port", type: Number }, -]; -const receivedOptions = commandLineArgs(optionDefinitions); - -Promise.resolve() - .then(async () => { - console.log( - `Filling ${receivedOptions.host} with data size ${receivedOptions.dataSize}` - ); - await fill_database( - receivedOptions.dataSize, - receivedOptions.host, - receivedOptions.clusterModeEnabled, - receivedOptions.tls, - receivedOptions.port - ); - }) - .then(() => { - process.exit(0); - });