mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Holding onto the compressor and not recycling the interbal byte slice was causing havoc with GC.
This needs to be improved but this at least should allow the GC to cleanup more effectively. Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
@@ -115,7 +115,6 @@ type websocket struct {
|
||||
nocompfrag bool // No fragment for compressed frames
|
||||
maskread bool
|
||||
maskwrite bool
|
||||
compressor *flate.Writer
|
||||
cookieJwt string
|
||||
clientIP string
|
||||
}
|
||||
@@ -1295,15 +1294,8 @@ func (c *client) wsCollapsePtoNB() (net.Buffers, int64) {
|
||||
if mfs > 0 && c.ws.nocompfrag {
|
||||
mfs = 0
|
||||
}
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
cp := c.ws.compressor
|
||||
if cp == nil {
|
||||
c.ws.compressor, _ = flate.NewWriter(buf, flate.BestSpeed)
|
||||
cp = c.ws.compressor
|
||||
} else {
|
||||
cp.Reset(buf)
|
||||
}
|
||||
buf := bytes.NewBuffer(nbPoolGet(usz))
|
||||
cp, _ := flate.NewWriter(buf, flate.BestSpeed)
|
||||
var csz int
|
||||
for _, b := range nb {
|
||||
cp.Write(b)
|
||||
@@ -1352,6 +1344,7 @@ func (c *client) wsCollapsePtoNB() (net.Buffers, int64) {
|
||||
}
|
||||
csz = len(h) + ol
|
||||
}
|
||||
nbPoolPut(b) // No longer needed as we copied from above.
|
||||
// Add to pb the compressed data size (including headers), but
|
||||
// remove the original uncompressed data size that was added
|
||||
// during the queueing.
|
||||
|
||||
Reference in New Issue
Block a user