thread safety + go1.13
This commit is contained in:
parent
c735f46ecb
commit
adfd010a93
3 changed files with 44 additions and 6 deletions
40
readme.md
40
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
|
||||
Hardware detail: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue