From 73bf0b41423931a03e8736890e851d1d7db00099 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 4 Dec 2023 11:41:07 +0000 Subject: [PATCH] inline benchmarks processing to avoid buildMatch calls --- manifest.json | 8 ------- svc/benchmarks.mjs | 52 ---------------------------------------------- svc/scenarios.mjs | 2 ++ 3 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 svc/benchmarks.mjs diff --git a/manifest.json b/manifest.json index 7b0f91b90..1c300c766 100755 --- a/manifest.json +++ b/manifest.json @@ -208,14 +208,6 @@ "exec_mode": "cluster", "instances": 1 }, - { - "script": "svc/benchmarks.mjs", - "watch": true, - "ignore_watch": [".git", "node_modules"], - "group": "backend", - "exec_mode": "cluster", - "instances": 1 - }, { "script": "svc/syncSubs.mjs", "watch": true, diff --git a/svc/benchmarks.mjs b/svc/benchmarks.mjs deleted file mode 100644 index 12dc86a16..000000000 --- a/svc/benchmarks.mjs +++ /dev/null @@ -1,52 +0,0 @@ -// Processes a queue of jobs to benchmarks player hero performance against others -import queue from '../store/queue.mjs'; -import buildMatch from '../store/buildMatch.mjs'; -import utility from '../util/utility.mjs'; -import config from '../config.js'; -import redis from '../store/redis.mjs'; -import { benchmarks } from '../util/benchmarksUtil.mjs'; - -async function doBenchmarks(matchID, cb) { - console.log('[BENCHMARKS] %s', matchID); - try { - const match = await buildMatch(matchID); - if (match.players && utility.isSignificant(match)) { - for (let i = 0; i < match.players.length; i += 1) { - const p = match.players[i]; - // only do if all players have heroes - if (p.hero_id) { - Object.keys(benchmarks).forEach((key) => { - const metric = benchmarks[key](match, p); - if ( - metric !== undefined && - metric !== null && - !Number.isNaN(Number(metric)) - ) { - const rkey = [ - 'benchmarks', - utility.getStartOfBlockMinutes( - config.BENCHMARK_RETENTION_MINUTES, - 0 - ), - key, - p.hero_id, - ].join(':'); - redis.zadd(rkey, metric, match.match_id); - // expire at time two epochs later (after prev/current cycle) - const expiretime = utility.getStartOfBlockMinutes( - config.BENCHMARK_RETENTION_MINUTES, - 2 - ); - redis.expireat(rkey, expiretime); - } - }); - } - } - return cb(); - } - return cb(); - } catch (err) { - return cb(err); - } -} -queue.runQueue('parsedBenchmarksQueue', 1, doBenchmarks); diff --git a/svc/scenarios.mjs b/svc/scenarios.mjs index 3a413501e..48a598e99 100644 --- a/svc/scenarios.mjs +++ b/svc/scenarios.mjs @@ -7,7 +7,9 @@ import db from '../store/db.mjs'; import utility from '../util/utility.mjs'; import su from '../util/scenariosUtil.mjs'; async function processScenarios(matchID, cb) { + console.log('[SCENARIOS] match: %s', matchID); try { + // Using buildMatch is unnecessarily expensive here since it also looks up player names etc. const match = await buildMatch(matchID); if (!su.validateMatchProperties(match)) { console.error(