From c41cc022c563ffd919f58514881e99df11c87114 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Mon, 15 May 2023 11:41:33 +0700 Subject: [PATCH] TSK-1500: Enable compression by default (#3177) Signed-off-by: Andrey Sobolev --- dev/prod/src/platform.ts | 2 +- models/all/src/version.json | 2 +- pods/server/src/__start.ts | 5 ++++- pods/server/src/server.ts | 5 ++++- server/front/src/index.ts | 3 ++- server/ws/src/server.ts | 4 +++- server/ws/src/server_http.ts | 31 +++++++++++++++++-------------- server/ws/src/types.ts | 3 ++- 8 files changed, 34 insertions(+), 21 deletions(-) diff --git a/dev/prod/src/platform.ts b/dev/prod/src/platform.ts index dfdee941bb..27edb8053c 100644 --- a/dev/prod/src/platform.ts +++ b/dev/prod/src/platform.ts @@ -159,7 +159,7 @@ export async function configurePlatform() { // Use binary response transfer for faster performance and small transfer sizes. setMetadata(client.metadata.UseBinaryProtocol, true) // Disable for now, since it causes performance issues on linux/docker/kubernetes boxes for now. - setMetadata(client.metadata.UseProtocolCompression, false) + setMetadata(client.metadata.UseProtocolCompression, true) setMetadata(workbench.metadata.PlatformTitle, 'Platform') } diff --git a/models/all/src/version.json b/models/all/src/version.json index 5d440a31cd..96f2c7f7a4 100644 --- a/models/all/src/version.json +++ b/models/all/src/version.json @@ -1 +1 @@ -{ "major": 0, "minor": 6, "patch": 93 } +{ "major": 0, "minor": 6, "patch": 95 } diff --git a/pods/server/src/__start.ts b/pods/server/src/__start.ts index 466002774f..26b90e4676 100644 --- a/pods/server/src/__start.ts +++ b/pods/server/src/__start.ts @@ -25,6 +25,8 @@ const serverPort = parseInt(process.env.SERVER_PORT ?? '3333') const serverFactory = serverFactories[(process.env.SERVER_PROVIDER as string) ?? 'ws'] ?? serverFactories.ws +const enableCompression = (process.env.ENABLE_COMPRESSION ?? 'true') === 'true' + const url = process.env.MONGO_URL if (url === undefined) { console.error('please provide mongodb url') @@ -92,7 +94,8 @@ const shutdown = start(url, { serverFactory, indexParallel: 2, indexProcessing: 500, - productId: '' + productId: '', + enableCompression }) const close = (): void => { diff --git a/pods/server/src/server.ts b/pods/server/src/server.ts index a184e664bd..9b0c740dc0 100644 --- a/pods/server/src/server.ts +++ b/pods/server/src/server.ts @@ -186,6 +186,8 @@ export function start ( indexProcessing: number // 1000 indexParallel: number // 2 + + enableCompression?: boolean } ): () => Promise { addLocation(serverAttachmentId, () => import('@hcengineering/server-attachment-resources')) @@ -336,6 +338,7 @@ export function start ( sessionFactory, port: opt.port, productId: opt.productId, - serverFactory: opt.serverFactory + serverFactory: opt.serverFactory, + enableCompression: opt.enableCompression }) } diff --git a/server/front/src/index.ts b/server/front/src/index.ts index 984a09bd7a..dd75528d3d 100644 --- a/server/front/src/index.ts +++ b/server/front/src/index.ts @@ -155,7 +155,8 @@ export function start ( // fallback to standard filter function return compression.filter(req, res) - } + }, + level: 6 }) ) app.use(cors()) diff --git a/server/ws/src/server.ts b/server/ws/src/server.ts index c61d0b6ec1..61061ace5f 100644 --- a/server/ws/src/server.ts +++ b/server/ws/src/server.ts @@ -508,6 +508,7 @@ export function start ( sessionFactory: (token: Token, pipeline: Pipeline, broadcast: BroadcastCall) => Session productId: string serverFactory: ServerFactory + enableCompression?: boolean } ): () => Promise { const sessions = new TSessionManager(ctx, opt.sessionFactory) @@ -517,6 +518,7 @@ export function start ( ctx, opt.pipelineFactory, opt.port, - opt.productId + opt.productId, + opt.enableCompression ?? true ) } diff --git a/server/ws/src/server_http.ts b/server/ws/src/server_http.ts index dfe91f2b4a..68f3f1e1e0 100644 --- a/server/ws/src/server_http.ts +++ b/server/ws/src/server_http.ts @@ -33,25 +33,28 @@ export function startHttpServer ( ctx: MeasureContext, pipelineFactory: PipelineFactory, port: number, - productId: string + productId: string, + enableCompression: boolean ): () => Promise { if (LOGGING_ENABLED) console.log(`starting server on port ${port} ...`) const wss = new WebSocketServer({ noServer: true, - perMessageDeflate: false, - // perMessageDeflate: { - // zlibDeflateOptions: { - // // See zlib defaults. - // chunkSize: 16 * 1024, - // level: 6 - // }, - // zlibInflateOptions: { - // chunkSize: 16 * 1024, - // level: 6 - // }, - // threshold: 1024 // Size (in bytes) below which messages, should not be compressed if context takeover is disabled. - // }, + perMessageDeflate: enableCompression + ? { + zlibDeflateOptions: { + // See zlib defaults. + chunkSize: 16 * 1024, + level: 6 + }, + zlibInflateOptions: { + chunkSize: 16 * 1024, + level: 6 + }, + threshold: 1024, // Size (in bytes) below which messages, should not be compressed if context takeover is disabled. + concurrencyLimit: 100 + } + : false, skipUTF8Validation: true }) // eslint-disable-next-line @typescript-eslint/no-misused-promises diff --git a/server/ws/src/types.ts b/server/ws/src/types.ts index bccf99b2fc..0619303ee0 100644 --- a/server/ws/src/types.ts +++ b/server/ws/src/types.ts @@ -164,5 +164,6 @@ export type ServerFactory = ( ctx: MeasureContext, pipelineFactory: PipelineFactory, port: number, - productId: string + productId: string, + enableCompression: boolean ) => () => Promise