@@ -313,7 +313,7 @@ function decreaseBufferPool () {
313313 // Balance between increasing and decreasing the bufferPool
314314 if ( counter === 1 || notDecreased > counter * 2 ) {
315315 // Decrease the bufferPool by 16kb by removing the first 16kb of the current pool
316- bufferPool = bufferPool . slice ( 16 * 1024 , bufferPool . length )
316+ bufferPool = bufferPool . slice ( Math . floor ( bufferPool . length / 10 ) , bufferPool . length )
317317 } else {
318318 notDecreased ++
319319 counter --
@@ -338,12 +338,17 @@ function concatBuffer (parser, length) {
338338 length -= parser . offset
339339 if ( bufferPool . length < length + bufferOffset ) {
340340 // Increase the bufferPool size by three times the current needed length
341- bufferPool = new Buffer ( length * 3 + bufferOffset )
341+ var multiplier = 3
342+ if ( bufferOffset > 1024 * 1024 * 200 ) {
343+ bufferOffset = 1024 * 1024 * 50
344+ multiplier = 2
345+ }
346+ bufferPool = new Buffer ( length * multiplier + bufferOffset )
342347 bufferOffset = 0
343348 counter ++
344349 pos = 0
345350 if ( interval === null ) {
346- interval = setInterval ( decreaseBufferPool , 30 )
351+ interval = setInterval ( decreaseBufferPool , 50 )
347352 }
348353 }
349354 list [ 0 ] . copy ( bufferPool , pos , parser . offset , list [ 0 ] . length )
@@ -369,10 +374,10 @@ JavascriptRedisParser.prototype.execute = function (buffer) {
369374 } else if ( this . bigStrSize === 0 ) {
370375 var oldLength = this . buffer . length
371376 var remainingLength = oldLength - this . offset
372- var bufferPool = new Buffer ( remainingLength + buffer . length )
373- this . buffer . copy ( bufferPool , 0 , this . offset , oldLength )
374- buffer . copy ( bufferPool , remainingLength , 0 , buffer . length )
375- this . buffer = bufferPool
377+ var newBuffer = new Buffer ( remainingLength + buffer . length )
378+ this . buffer . copy ( newBuffer , 0 , this . offset , oldLength )
379+ buffer . copy ( newBuffer , remainingLength , 0 , buffer . length )
380+ this . buffer = newBuffer
376381 this . offset = 0
377382 } else if ( this . totalChunkSize + buffer . length >= this . bigStrSize ) {
378383 this . bufferCache . push ( buffer )
0 commit comments