From 73d6f07971045aa0731bc5c0430b168de31d670f Mon Sep 17 00:00:00 2001 From: Leo Kewitz Date: Tue, 27 Feb 2024 11:07:47 +0100 Subject: [PATCH] refact: monitor mutex lock time using statsd (#9874) --- server/lib/mutex.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/lib/mutex.ts b/server/lib/mutex.ts index 634fe6d49ea..16e7007102e 100644 --- a/server/lib/mutex.ts +++ b/server/lib/mutex.ts @@ -2,6 +2,7 @@ import debugLib from 'debug'; import logger from './logger'; import { createRedisClient, RedisInstanceType } from './redis'; +import { utils } from './statsd'; import { sleep } from './utils'; const debug = debugLib('mutex'); @@ -22,6 +23,7 @@ export async function lockUntilResolved( const start = Date.now(); const _key = `lock:${key}`; + const stopWatch = utils.stopwatch(`mutex.lockUntilResolved.${_key}`); const lock = () => redis.set(_key, 1, { NX: true, PX: unlockTimeoutMs }); let lockAcquired = await lock(); @@ -38,6 +40,7 @@ export async function lockUntilResolved( debug(`Acquired lock ${_key}`); return until().finally(async () => { await redis.del(_key); + stopWatch(); debug(`Released lock ${_key}`); }); }