@@ -313,7 +313,7 @@ function decreaseBufferPool () {
313
313
// Balance between increasing and decreasing the bufferPool
314
314
if ( counter === 1 || notDecreased > counter * 2 ) {
315
315
// 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 )
317
317
} else {
318
318
notDecreased ++
319
319
counter --
@@ -338,12 +338,17 @@ function concatBuffer (parser, length) {
338
338
length -= parser . offset
339
339
if ( bufferPool . length < length + bufferOffset ) {
340
340
// 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 )
342
347
bufferOffset = 0
343
348
counter ++
344
349
pos = 0
345
350
if ( interval === null ) {
346
- interval = setInterval ( decreaseBufferPool , 30 )
351
+ interval = setInterval ( decreaseBufferPool , 50 )
347
352
}
348
353
}
349
354
list [ 0 ] . copy ( bufferPool , pos , parser . offset , list [ 0 ] . length )
@@ -369,10 +374,10 @@ JavascriptRedisParser.prototype.execute = function (buffer) {
369
374
} else if ( this . bigStrSize === 0 ) {
370
375
var oldLength = this . buffer . length
371
376
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
376
381
this . offset = 0
377
382
} else if ( this . totalChunkSize + buffer . length >= this . bigStrSize ) {
378
383
this . bufferCache . push ( buffer )
0 commit comments