本文整理汇总了Golang中ddtxn.Query.S方法的典型用法代码示例。如果您正苦于以下问题:Golang Query.S方法的具体用法?Golang Query.S怎么用?Golang Query.S使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ddtxn.Query
的用法示例。
在下文中一共展示了Query.S方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
runtime.GOMAXPROCS(*nprocs)
if *clientGoRoutines == 0 {
*clientGoRoutines = *nprocs
}
if *nworkers == 0 {
*nworkers = *nprocs
}
if *doValidate {
if !*ddtxn.Allocate {
log.Fatalf("Cannot correctly validate without waiting for results; add -allocate\n")
}
}
var nproducts int
if *contention > 0 {
nproducts = *nbidders / int(*contention)
} else {
nproducts = ddtxn.NUM_ITEMS
}
s := ddtxn.NewStore()
coord := ddtxn.NewCoordinator(*nworkers, s)
if *ddtxn.CountKeys {
for i := 0; i < *nworkers; i++ {
w := coord.Workers[i]
w.NKeyAccesses = make([]int64, *nbidders)
}
}
rubis := &apps.Rubis{}
rubis.Init(nproducts, *nbidders, *nworkers, *clientGoRoutines, *ZipfDist, 0)
rubis.PopulateBids(s, coord) // Just creates items to bid on
fmt.Printf("Done populating bids\n")
if !*ddtxn.Allocate {
prealloc := time.Now()
tmp := *ddtxn.UseRLocks
*ddtxn.UseRLocks = true
// Preallocate keys
bids_per_worker := 200000.0
if *nworkers == 20 {
bids_per_worker *= 20
}
if *rounds {
parallelism := 10
rounds := *nworkers / parallelism
if rounds == 0 {
rounds = 1
}
for j := 0; j < rounds; j++ {
fmt.Printf("Doing round %v\n", j)
var wg sync.WaitGroup
for i := j * parallelism; i < (j+1)*parallelism; i++ {
if i >= *nworkers {
break
}
wg.Add(1)
go func(i int) {
coord.Workers[i].PreallocateRubis(0, int(bids_per_worker), ddtxn.NUM_ITEMS)
wg.Done()
}(i)
}
wg.Wait()
}
} else {
var wg sync.WaitGroup
for i := 0; i < *nworkers; i++ {
wg.Add(1)
go func(i int) {
coord.Workers[i].PreallocateRubis(0, int(bids_per_worker), ddtxn.NUM_ITEMS)
wg.Done()
}(i)
}
wg.Wait()
}
*ddtxn.UseRLocks = tmp
fmt.Printf("Allocation took %v\n", time.Since(prealloc))
}
fmt.Printf("Done initializing rubis\n")
p := prof.StartProfile()
start := time.Now()
gave_up := make([]int64, *clientGoRoutines)
var wg sync.WaitGroup
for i := 0; i < *clientGoRoutines; i++ {
exp := ddtxn.MakeExp(30)
wg.Add(1)
go func(n int) {
retries := make(ddtxn.RetryHeap, 0)
heap.Init(&retries)
end_time := time.Now().Add(time.Duration(*nsec) * time.Second)
var local_seed uint32 = uint32(rand.Intn(1000000))
wi := n % (*nworkers)
w := coord.Workers[wi]
//.........这里部分代码省略.........
示例2: main
func main() {
flag.Parse()
runtime.GOMAXPROCS(*nprocs)
if *clientGoRoutines == 0 {
*clientGoRoutines = *nprocs
}
if *nworkers == 0 {
*nworkers = *nprocs
}
if *doValidate {
if !*ddtxn.Allocate {
log.Fatalf("Cannot correctly validate without waiting for results; add -allocate\n")
}
}
if *contention == -1.0 && *ZipfDist == -1.0 {
log.Fatalf("Should use zipf or contention")
}
var nproducts int
if *contention > 0 {
nproducts = *nbidders / int(*contention)
} else {
nproducts = *nbidders
}
s := ddtxn.NewStore()
buy_app := &apps.Buy{}
buy_app.Init(nproducts, *nbidders, *nworkers, *readrate, *clientGoRoutines, *notcontended_readrate, *ZipfDist)
dlog.Printf("Starting to initialize buy\n")
buy_app.Populate(s, nil)
coord := ddtxn.NewCoordinator(*nworkers, s)
if *ddtxn.CountKeys {
for i := 0; i < *nworkers; i++ {
w := coord.Workers[i]
w.NKeyAccesses = make([]int64, *nbidders)
}
}
dlog.Printf("Done initializing buy\n")
p := prof.StartProfile()
start := time.Now()
var wg sync.WaitGroup
gave_upr := make([]int64, *clientGoRoutines)
gave_upw := make([]int64, *clientGoRoutines)
var ending_retries int64
for i := 0; i < *clientGoRoutines; i++ {
wg.Add(1)
go func(n int) {
exp := ddtxn.MakeExp(50)
retries := make(ddtxn.RetryHeap, 0)
heap.Init(&retries)
end_time := time.Now().Add(time.Duration(*nsec) * time.Second)
var local_seed uint32 = uint32(rand.Intn(10000000))
var sp uint32 = uint32(*nbidders / *clientGoRoutines)
w := coord.Workers[n%(*nworkers)]
var tm time.Time
for {
tm = time.Now()
if !end_time.After(tm) {
break
}
var t ddtxn.Query
if len(retries) > 0 && retries[0].TS.Before(tm) {
t = heap.Pop(&retries).(ddtxn.Query)
} else {
buy_app.MakeOne(w.ID, &local_seed, sp, &t)
if *ddtxn.Latency {
t.S = time.Now()
}
}
if *doValidate {
t.W = make(chan struct {
R *ddtxn.Result
E error
}, 1)
}
committed := false
_, err := w.One(t)
if err == ddtxn.ESTASH {
if *doValidate {
x := <-t.W
err = x.E
if err == ddtxn.EABORT {
log.Fatalf("Should be run until commitment!\n")
}
}
committed = true // The worker stash code will retry
} else if err == ddtxn.EABORT {
committed = false
} else {
committed = true
}
t.I++
if !committed {
e := uint32(exp.Exp(t.I))
if e < 1 {
//.........这里部分代码省略.........