Skip to content

Commit

Permalink
use recordsBufferSize instead of hardcoded constant
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded committed Jun 1, 2018
1 parent 0cda5be commit 1ed4d5c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const analyticsKeyName = "tyk-system-analytics"

const (
minRecordsBufferSize = 1000
minRecordsWriteBatchSize = 200
recordsBufferFlushInterval = 200 * time.Millisecond
)

Expand Down Expand Up @@ -225,8 +224,8 @@ func (r *RedisAnalyticsHandler) recordWorker() {
defer r.poolWg.Done()

// this is buffer to send one pipelined command to redis
// use minRecordsWriteBatchSize as cap to reduce slice re-allocations
recordsBuffer := make([]string, 0, minRecordsWriteBatchSize)
// use r.recordsBufferSize as cap to reduce slice re-allocations
recordsBuffer := make([]string, 0, r.recordsBufferSize)

// read records from channel and process
for {
Expand Down Expand Up @@ -274,7 +273,7 @@ func (r *RedisAnalyticsHandler) recordWorker() {
}

// identify that buffer is ready to be sent
readyToSend = uint64(len(recordsBuffer)) == minRecordsWriteBatchSize
readyToSend = uint64(len(recordsBuffer)) == r.recordsBufferSize

case <-time.After(recordsBufferFlushInterval):
// nothing was received for that period of time
Expand All @@ -285,7 +284,7 @@ func (r *RedisAnalyticsHandler) recordWorker() {
// send data to Redis and reset buffer
if readyToSend && len(recordsBuffer) > 0 {
r.Store.AppendToSetPipelined(analyticsKeyName, recordsBuffer)
recordsBuffer = make([]string, 0, minRecordsWriteBatchSize)
recordsBuffer = make([]string, 0, r.recordsBufferSize)
}
}
}

0 comments on commit 1ed4d5c

Please sign in to comment.