Skip to content

Commit

Permalink
improve bulk performance (zincsearch#73)
Browse files Browse the repository at this point in the history
* fix: bulk fail with empty _id

* feature: add full time search in UI

* fix: bulk fail with empty _id

* delete files

* add test for aggregetions

* improve bulk performance

* optimize bulk
  • Loading branch information
hengfeiyang authored Jan 26, 2022
1 parent 7daf4f3 commit 4b39558
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/handlers/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func BulkHandlerWorker(target string, body io.ReadCloser) error {
scanner := bufio.NewScanner(body)
defer body.Close()

// force set batchSize
batchSize := 1000

// Set 1 MB max per line. docs at - https://pkg.go.dev/bufio#pkg-constants
// This is the max size of a line in a file that we will process
const maxCapacityPerLine = 1024 * 1024
Expand Down Expand Up @@ -102,6 +105,19 @@ func BulkHandlerWorker(target string, body io.ReadCloser) error {
batch[indexName].Insert(bdoc)
}

if documentsInBatch >= batchSize {
for _, indexN := range indexesInThisBatch {
// Persist the batch to the index
err := core.ZINC_INDEX_LIST[indexN].Writer.Batch(batch[indexN])
if err != nil {
log.Printf("Error updating batch: %v", err)
return err
}
batch[indexN].Reset()
}
documentsInBatch = 0
}

} else { // This branch will process the metadata line in the request. Each metadata line is preceded by a data line.

for k, v := range doc {
Expand Down

0 comments on commit 4b39558

Please sign in to comment.