Skip to content

Commit

Permalink
refactor(logger): specify buffer capacity and keep allocated memory o…
Browse files Browse the repository at this point in the history
…f buffer
  • Loading branch information
symbiont-stevan-andjelkovic committed Jan 26, 2021
1 parent 9e3b1a0 commit c9e5632
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/logger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func main() {
}

func worker(db *sql.DB, queue chan []byte) {
var buffer [][]byte
buffer := make([][]byte, 0, BUFFER_LEN)
for {
if len(buffer) >= BUFFER_LEN {
commit(db, buffer)
buffer = [][]byte{}
buffer = buffer[:0]
} else {
if len(buffer) == 0 {
entry := <-queue // Blocking.
Expand All @@ -52,7 +52,7 @@ func worker(db *sql.DB, queue chan []byte) {
buffer = append(buffer, entry)
} else {
commit(db, buffer)
buffer = [][]byte{}
buffer = buffer[:0]
}
}
}
Expand Down

0 comments on commit c9e5632

Please sign in to comment.