diff --git a/cmd/example/main.go b/cmd/example/main.go index 5cf19f7..c1266a9 100644 --- a/cmd/example/main.go +++ b/cmd/example/main.go @@ -15,10 +15,10 @@ func main() { // I will ignore all errors for demonstration purposes _ = ingester.BulkPush("movies", "general", 3, []sonic.IngestBulkRecord{ - {"id:6ab56b4kk3", "Star wars"}, - {"id:5hg67f8dg5", "Spider man"}, - {"id:1m2n3b4vf6", "Batman"}, - {"id:68d96h5h9d0", "This is another movie"}, + {Object: "id:6ab56b4kk3", Text: "Star wars"}, + {Object: "id:5hg67f8dg5", Text: "Spider man"}, + {Object: "id:1m2n3b4vf6", Text: "Batman"}, + {Object: "id:68d96h5h9d0", Text: "This is another movie"}, }) search, err := sonic.NewSearch("localhost", 1491, "SecretPassword") diff --git a/go.mod b/go.mod index de7ee70..04def90 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/expectedsh/go-sonic -go 1.12 +go 1.13 diff --git a/readme.md b/readme.md index bb9d0a0..b673057 100644 --- a/readme.md +++ b/readme.md @@ -62,5 +62,43 @@ BenchmarkIngesterChannel_Push-8 1 1023322864 ns/op PASS ``` +### Thread Safety + +The driver itself isn't thread safe. You could use locks or channels to avoid crashes. + +```go +package main + +import ( + "fmt" + + "github.com/expectedsh/go-sonic/sonic" +) + +func main() { + events := make(chan []string, 1) + + // simulating a high incoming message load + tryCrash := func() { + for { + events <- []string{"some_text", "some_id"} + } + } + + go tryCrash() + go tryCrash() + go tryCrash() + go tryCrash() + + ingester, _ := sonic.NewIngester("localhost", 1491, "SecretPassword") + + for { + msg := <-events + // Or use some buffering along with BulkPush + ingester.Push("collection", "bucket", msg[1], msg[0]) + } +} +``` + Bulk push is faster than for loop on Push. -Hardware detail: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz \ No newline at end of file +Hardware detail: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz