go


Make a blocking/consistent/predictable reply/request on ScyllaDB via GoCQL


Sometimes when running a command it shows a timeout (gocql: no response received from cassandra within timeout period), for example:
package main
import "fmt"
import "github.com/gocql/gocql"
import "time"
import "log"
func main() {
clust := gocql.NewCluster(`172.17.0.2`) // docker#localhost
clust.Keyspace = `test4`
clust.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: 3}
db, err := clust.CreateSession()
defer db.Close()
if err != nil {
log.Fatal(err)
return
}
fmt.Println(`test4: scylladb`)
if err := db.Query(`DROP TABLE test4`).Exec(); err != nil {
log.Println(err)
}
if err := db.Query(`CREATE TABLE test4 (bucket text, k text, v TEXT, PRIMARY KEY(bucket,k))`).Exec(); err != nil {
log.Fatal(err)
return
}
const max = 999
const jump = 40
t := time.Now()
for x := 1; x <= max; x++ {
err = db.Query(fmt.Sprintf(`INSERT INTO test4(bucket,k,v)VALUES('foo','%05d','%05d')`, x, x)).Exec()
if err != nil {
log.Fatal(err)
return
}
if x % 200 == 0 {
fmt.Print(`.`)
}
}
dur := time.Now().Sub(t)
fmt.Printf("INSERT: %v (%.2f ms/op)\n", dur, float64(dur.Nanoseconds()) / 1000000 / max)
t = time.Now()
for x := 1; x <= max; x++ {
err = db.Query(fmt.Sprintf(`UPDATE test4 SET v = '%06d' WHERE bucket = 'foo' AND k = '%05d'`, x, x)).Exec()
if err != nil {
log.Fatal(err)
return
}
if x % 200 == 0 {
fmt.Print(`.`)
}
}
dur = time.Now().Sub(t)
fmt.Printf("UPDATE: %v (%.2f ms/op)\n", dur, float64(dur.Nanoseconds()) / 1000000 / max)
t = time.Now()
ops := int64(0)
for y := 2; y < jump; y++ {
for x := max - 1; x > 0; x -= y {
ops++
iter := db.Query(fmt.Sprintf(`SELECT k, v FROM test4 WHERE bucket = 'foo' AND k >= '%05d' ORDER BY k ASC LIMIT %d`, x, y * y)).Iter()
for {
m := map[string]interface{}{}
if !iter.MapScan(m) {
break
}
}
iter.Close()
if ops % 500 == 0 {
fmt.Print(`.`)
}
}
for x := 1; x < max; x += y {
ops++
iter := db.Query(fmt.Sprintf(`SELECT k, v FROM test4 WHERE bucket = 'foo' AND k <= '%05d' ORDER BY k DESC LIMIT %d`, x, y * y)).Iter()
for {
m := map[string]interface{}{}
if !iter.MapScan(m) {
break
}
}
iter.Close()
if ops % 500 == 0 {
fmt.Print(`.`)
}
}
}
dur = time.Now().Sub(t)
fmt.Printf("SELECT: %v (%.2f ms/op)\n", dur, float64(dur.Nanoseconds()) / 1000000 / float64(ops))
}
It shows inconsistent output:
$ go run scylla.go
test4: scylladb
2017/05/16 12:09:05 gocql: no response received from cassandra within timeout period
2017/05/16 12:09:05 gocql: no response received from cassandra within timeout period
exit status 1
$ go run scylla.go
test4: scylladb
....INSERT: 188.277521ms (0.19 ms/op)
....UPDATE: 150.403282ms (0.15 ms/op)
.............SELECT: 5.357779756s (0.82 ms/op)
$ go run scylla.go
test4: scylladb
2017/05/16 12:09:50 gocql: no response received from cassandra within timeout period
....INSERT: 142.91132ms (0.14 ms/op)
....UPDATE: 144.272872ms (0.14 ms/op)
.............SELECT: 5.268130283s (0.81 ms/op)
$ go run scylla.go
test4: scylladb
2017/05/16 12:10:00 gocql: no response received from cassandra within timeout period
2017/05/16 12:10:00 gocql: no response received from cassandra within timeout period
exit status 1
$ go run scylla.go
test4: scylladb
....INSERT: 184.402052ms (0.18 ms/op)
....UPDATE: 158.200184ms (0.16 ms/op)
.............SELECT: 5.345212835s (0.82 ms/op)
How to make it consistent? I need to be sure if a command completed successfully.. Or should I loop the DROP TABLE/CREATE TABLE command manually?

Related Links

Go/Golang sql.DB reuse in functions
How to use a Logger outside of main
Find all matches in Go array
Go: http.Server connection pool
How to distribute a Go app?
How to use RWMutex in Golang?
What is the intended usage of named return variables in Go?
what can create huge overhead of goroutines?
GoLang / CGO: Problems calling Mach API host_statistics() from Go
Read until end of channel in Go
How would I read a growing file in Go?
How are Go channels implemented?
Correct directory structure for a Go Project?
Building and linking dynamically from a go binary
Is there a big.BitCount?
interrupt pattern for google go goroutine (speed issue)

Categories

HOME
turing-machines
string
codenvy
alexa-skills-kit
youtube-data-api-v3
devise
spring-data-mongodb
entity-framework-core
bookmarks
character
accessibility
spin
android-securityexception
naivebayes
automatic-ref-counting
renjin
dynatrace
google-container-registry
named-entity-recognition
dataflow-diagram
scriptella
gpio
iis-express
alm
complex-numbers
angularjs-material
fstream
linkedhashmap
sharding
lint
playframework-2.1
signals-slots
preloader
glm-math
http-request
placeholder
wc
automapper-5
chai-as-promised
vugen
context-switch
scalding
android-testing
skin
sundials
offline.js
change-tracking
angular2-testing
segment-io
signalr.client
jquery-jscrollpane
embedding
hadoop-partitioning
database-relations
qbxml
atan2
concurrentmodification
lazybones
toolkit
typemock
haskell-warp
mirror
typeconverter
code-documentation
procedural-programming
adehabitathr
showdialog
packet-sniffers
viewer
addressing-mode
administration
rmysql
winginx
jquery-slider
eclipse-kepler
artemis
printdialog
chart-director
extreme-programming
patricia-trie
correlated-subquery
garbage
database-create
catransform3d
easyb
openfaces
duplex
mathematical-notation
visualj#
fault-tolerance
image-capture

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App