thread safety + go1.13
This commit is contained in:
parent
c735f46ecb
commit
adfd010a93
3 changed files with 44 additions and 6 deletions
|
|
@ -15,10 +15,10 @@ func main() {
|
||||||
// I will ignore all errors for demonstration purposes
|
// I will ignore all errors for demonstration purposes
|
||||||
|
|
||||||
_ = ingester.BulkPush("movies", "general", 3, []sonic.IngestBulkRecord{
|
_ = ingester.BulkPush("movies", "general", 3, []sonic.IngestBulkRecord{
|
||||||
{"id:6ab56b4kk3", "Star wars"},
|
{Object: "id:6ab56b4kk3", Text: "Star wars"},
|
||||||
{"id:5hg67f8dg5", "Spider man"},
|
{Object: "id:5hg67f8dg5", Text: "Spider man"},
|
||||||
{"id:1m2n3b4vf6", "Batman"},
|
{Object: "id:1m2n3b4vf6", Text: "Batman"},
|
||||||
{"id:68d96h5h9d0", "This is another movie"},
|
{Object: "id:68d96h5h9d0", Text: "This is another movie"},
|
||||||
})
|
})
|
||||||
|
|
||||||
search, err := sonic.NewSearch("localhost", 1491, "SecretPassword")
|
search, err := sonic.NewSearch("localhost", 1491, "SecretPassword")
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,3 +1,3 @@
|
||||||
module github.com/expectedsh/go-sonic
|
module github.com/expectedsh/go-sonic
|
||||||
|
|
||||||
go 1.12
|
go 1.13
|
||||||
|
|
|
||||||
40
readme.md
40
readme.md
|
|
@ -62,5 +62,43 @@ BenchmarkIngesterChannel_Push-8 1 1023322864 ns/op
|
||||||
PASS
|
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.
|
Bulk push is faster than for loop on Push.
|
||||||
Hardware detail: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
|
Hardware detail: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue