TSK-1500: Enable compression by default (#3177)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-05-15 11:41:33 +07:00 committed by GitHub
parent 6423d1beeb
commit c41cc022c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 21 deletions

View File

@ -159,7 +159,7 @@ export async function configurePlatform() {
// Use binary response transfer for faster performance and small transfer sizes. // Use binary response transfer for faster performance and small transfer sizes.
setMetadata(client.metadata.UseBinaryProtocol, true) setMetadata(client.metadata.UseBinaryProtocol, true)
// Disable for now, since it causes performance issues on linux/docker/kubernetes boxes for now. // 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') setMetadata(workbench.metadata.PlatformTitle, 'Platform')
} }

View File

@ -1 +1 @@
{ "major": 0, "minor": 6, "patch": 93 } { "major": 0, "minor": 6, "patch": 95 }

View File

@ -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 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 const url = process.env.MONGO_URL
if (url === undefined) { if (url === undefined) {
console.error('please provide mongodb url') console.error('please provide mongodb url')
@ -92,7 +94,8 @@ const shutdown = start(url, {
serverFactory, serverFactory,
indexParallel: 2, indexParallel: 2,
indexProcessing: 500, indexProcessing: 500,
productId: '' productId: '',
enableCompression
}) })
const close = (): void => { const close = (): void => {

View File

@ -186,6 +186,8 @@ export function start (
indexProcessing: number // 1000 indexProcessing: number // 1000
indexParallel: number // 2 indexParallel: number // 2
enableCompression?: boolean
} }
): () => Promise<void> { ): () => Promise<void> {
addLocation(serverAttachmentId, () => import('@hcengineering/server-attachment-resources')) addLocation(serverAttachmentId, () => import('@hcengineering/server-attachment-resources'))
@ -336,6 +338,7 @@ export function start (
sessionFactory, sessionFactory,
port: opt.port, port: opt.port,
productId: opt.productId, productId: opt.productId,
serverFactory: opt.serverFactory serverFactory: opt.serverFactory,
enableCompression: opt.enableCompression
}) })
} }

View File

@ -155,7 +155,8 @@ export function start (
// fallback to standard filter function // fallback to standard filter function
return compression.filter(req, res) return compression.filter(req, res)
} },
level: 6
}) })
) )
app.use(cors()) app.use(cors())

View File

@ -508,6 +508,7 @@ export function start (
sessionFactory: (token: Token, pipeline: Pipeline, broadcast: BroadcastCall) => Session sessionFactory: (token: Token, pipeline: Pipeline, broadcast: BroadcastCall) => Session
productId: string productId: string
serverFactory: ServerFactory serverFactory: ServerFactory
enableCompression?: boolean
} }
): () => Promise<void> { ): () => Promise<void> {
const sessions = new TSessionManager(ctx, opt.sessionFactory) const sessions = new TSessionManager(ctx, opt.sessionFactory)
@ -517,6 +518,7 @@ export function start (
ctx, ctx,
opt.pipelineFactory, opt.pipelineFactory,
opt.port, opt.port,
opt.productId opt.productId,
opt.enableCompression ?? true
) )
} }

View File

@ -33,25 +33,28 @@ export function startHttpServer (
ctx: MeasureContext, ctx: MeasureContext,
pipelineFactory: PipelineFactory, pipelineFactory: PipelineFactory,
port: number, port: number,
productId: string productId: string,
enableCompression: boolean
): () => Promise<void> { ): () => Promise<void> {
if (LOGGING_ENABLED) console.log(`starting server on port ${port} ...`) if (LOGGING_ENABLED) console.log(`starting server on port ${port} ...`)
const wss = new WebSocketServer({ const wss = new WebSocketServer({
noServer: true, noServer: true,
perMessageDeflate: false, perMessageDeflate: enableCompression
// perMessageDeflate: { ? {
// zlibDeflateOptions: { zlibDeflateOptions: {
// // See zlib defaults. // See zlib defaults.
// chunkSize: 16 * 1024, chunkSize: 16 * 1024,
// level: 6 level: 6
// }, },
// zlibInflateOptions: { zlibInflateOptions: {
// chunkSize: 16 * 1024, chunkSize: 16 * 1024,
// level: 6 level: 6
// }, },
// threshold: 1024 // Size (in bytes) below which messages, should not be compressed if context takeover is disabled. threshold: 1024, // Size (in bytes) below which messages, should not be compressed if context takeover is disabled.
// }, concurrencyLimit: 100
}
: false,
skipUTF8Validation: true skipUTF8Validation: true
}) })
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises

View File

@ -164,5 +164,6 @@ export type ServerFactory = (
ctx: MeasureContext, ctx: MeasureContext,
pipelineFactory: PipelineFactory, pipelineFactory: PipelineFactory,
port: number, port: number,
productId: string productId: string,
enableCompression: boolean
) => () => Promise<void> ) => () => Promise<void>