Просмотр исходного кода

feat: add low percentiles to latency test

Sv443 4 месяцев назад
Родитель
Сommit
8d372a5316
1 измененных файлов с 11 добавлено и 6 удалено
  1. 11 6
      src/dev/latency-test.ts

+ 11 - 6
src/dev/latency-test.ts

@@ -1,6 +1,8 @@
 // NOTE:
 // - requires the env vars HTTP_PORT and AUTH_TOKENS (at least 1 token to bypass rate limiting) to be set
 // - requires geniURL to run in a different process (or using the command pnpm run latency-test)
+//
+// - requests are sent sequentially on purpose to avoid rate limiting on genius.com's side
 
 import "dotenv/config";
 import _axios from "axios";
@@ -11,9 +13,9 @@ import queries from "./latency-test-queries.json" with { type: "json" };
 
 const settings = {
   /** Amount of requests to send in total. */
-  amount: 100,
+  amount: 10,
   /** Base URL to send requests to. `{{QUERY}}` will be replaced with a random query from the `latency-test-queries.json` file. */
-  url: `http://127.0.0.1:${process.env.HTTP_PORT}/v2/search/top?q={{QUERY}}`,
+  url: `http://127.0.0.1:${process.env.HTTP_PORT ?? 8074}/v2/search/top?q={{QUERY}}`,
   /** Whether to log all requests to the console. */
   logRequests: true,
 };
@@ -66,10 +68,9 @@ async function run() {
 
   console.log(`\n>>> Latency test finished sending all ${settings.amount} requests after ${((Date.now() - startTs) / 1000).toFixed(2)}s - Results:`);
   console.log();
-  logVal("min", min);
-  logVal("avg", avg, k.bold);
-  logVal("max", max);
-  console.log();
+  logVal("5th%", getPerc(5, times), k.gray);
+  logVal("10th%", getPerc(10, times), k.gray);
+  logVal("25th%", getPerc(25, times), k.gray);
   logVal("80th%", getPerc(80, times));
   logVal("90th%", getPerc(90, times));
   logVal("95th%", getPerc(95, times));
@@ -77,6 +78,10 @@ async function run() {
   logVal("98th%", getPerc(98, times));
   logVal("99th%", getPerc(99, times));
   console.log();
+  logVal("min", min);
+  logVal("avg", avg, k.bold);
+  logVal("max", max);
+  console.log();
 }
 
 run();