-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (46 loc) · 1.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"sync"
"github.com/gocql/gocql"
)
// on my machine this test passes with 50_000 workers and 100 queries but fails with 100_000 workers
const workers = 100_000
const queries = 100
func main() {
cluster := gocql.NewCluster("localhost:9042")
session, err := cluster.CreateSession()
if err != nil {
panic(err)
}
execRelease(session.Query("drop keyspace if exists pargettest"))
execRelease(session.Query("create keyspace pargettest with replication = {'class' : 'SimpleStrategy', 'replication_factor' : 1}"))
execRelease(session.Query("drop table if exists pargettest.test"))
execRelease(session.Query("create table pargettest.test (a text, b int, primary key(a))"))
execRelease(session.Query("insert into pargettest.test (a, b) values ( 'a', 1)"))
var wg sync.WaitGroup
for i := 1; i <= workers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j < queries; j++ {
iterRelease(session.Query("select * from pargettest.test where a='a'"))
}
}()
}
wg.Wait()
}
func iterRelease(query *gocql.Query) {
_, err := query.Iter().SliceMap()
if err != nil {
println(err.Error())
panic(err)
}
query.Release()
}
func execRelease(query *gocql.Query) {
if err := query.Exec(); err != nil {
println(err.Error())
panic(err)
}
query.Release()
}