From 9f9fcd9963e91f9f6da95cfc48aa51ee424d5861 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Sun, 9 Jun 2024 23:45:38 +0700 Subject: [PATCH] UBERF-7197: Fix high cpu load (#5761) Signed-off-by: Andrey Sobolev --- server/core/src/server/storage.ts | 4 ++-- server/ws/src/server_http.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/core/src/server/storage.ts b/server/core/src/server/storage.ts index f8f1c1eaa1..d4e32898f7 100644 --- a/server/core/src/server/storage.ts +++ b/server/core/src/server/storage.ts @@ -14,6 +14,7 @@ // limitations under the License. // +import { Analytics } from '@hcengineering/analytics' import core, { ClassifierKind, DOMAIN_MODEL, @@ -74,7 +75,6 @@ import type { TriggerControl } from '../types' import { SessionContextImpl, createBroadcastEvent } from '../utils' -import { Analytics } from '@hcengineering/analytics' export class TServerStorage implements ServerStorage { private readonly fulltext: FullTextIndex @@ -749,7 +749,7 @@ export class TServerStorage implements ServerStorage { await this.broadcastCtx([{ derived: result }, ...applyCtx.derived]) }) } - setImmediate(() => { + setTimeout(() => { void asyncTriggerProcessor() }) } diff --git a/server/ws/src/server_http.ts b/server/ws/src/server_http.ts index 2ff771a822..8043ae180b 100644 --- a/server/ws/src/server_http.ts +++ b/server/ws/src/server_http.ts @@ -412,11 +412,11 @@ function createWebsocketClientSocket ( ctx.measure('send-data', smsg.length) await new Promise((resolve, reject) => { const doSend = (): void => { - if (ws.readyState !== ws.OPEN && !cs.isClosed) { + if (ws.readyState !== ws.OPEN || cs.isClosed) { return } if (ws.bufferedAmount > 16 * 1024) { - setImmediate(doSend) + setTimeout(doSend) return } ws.send(smsg, { binary: true, compress: compression }, (err) => {