Skip to content

Instantly share code, notes, and snippets.

@shortthefomo
Last active July 26, 2023 17:52
Show Gist options
  • Save shortthefomo/3360e4d2df22a11489ab65c1b68a1959 to your computer and use it in GitHub Desktop.
Save shortthefomo/3360e4d2df22a11489ab65c1b68a1959 to your computer and use it in GitHub Desktop.
websocket memory
const WebSocketServer = require('ws').Server
// dissable the perMessageDeflate this causes memory fragmentation!!!!!
const wss = new WebSocketServer({ port: process.env.APP_PORT, perMessageDeflate: false })
wss.on('connection', (ws, req) => {
ws.on('message', (data) => {
// do something
})
ws.on('close', () => {
// log close
})
ws.on('error', (error) => {
console.log('error', error)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment