Commit 09185538 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/t/tzodb.go: errgroup -> xsync.WorkGroup

See go123@515a6d14
parent ea53a795
// Copyright (C) 2017-2019 Nexedi SA and Contributors. // Copyright (C) 2017-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -39,10 +39,9 @@ import ( ...@@ -39,10 +39,9 @@ import (
"testing" "testing"
"time" "time"
"golang.org/x/sync/errgroup"
"lab.nexedi.com/kirr/go123/prog" "lab.nexedi.com/kirr/go123/prog"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xsync"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
_ "lab.nexedi.com/kirr/neo/go/zodb/wks" _ "lab.nexedi.com/kirr/neo/go/zodb/wks"
...@@ -322,14 +321,14 @@ func zwrk(ctx context.Context, url string, nwrk int, h hasher, bench, check stri ...@@ -322,14 +321,14 @@ func zwrk(ctx context.Context, url string, nwrk int, h hasher, bench, check stri
// benchmark parallel loads // benchmark parallel loads
defer xerr.Contextf(&err, "zwrk-%d/bench", nwrk) defer xerr.Contextf(&err, "zwrk-%d/bench", nwrk)
r := testing.Benchmark(func (b *testing.B) { r := testing.Benchmark(func (b *testing.B) {
wg, ctx := errgroup.WithContext(ctx) wg := xsync.NewWorkGroup(ctx)
var n int64 var n int64
for i := 0; i < nwrk; i++ { for i := 0; i < nwrk; i++ {
stor := storv[i] stor := storv[i]
oid := zodb.Oid(0) oid := zodb.Oid(0)
wg.Go(func() error { wg.Go(func(ctx context.Context) error {
for { for {
n := atomic.AddInt64(&n, +1) n := atomic.AddInt64(&n, +1)
if n >= int64(b.N) { if n >= int64(b.N) {
...@@ -382,10 +381,10 @@ func zwrkPreconnect(ctx context.Context, url string, at zodb.Tid, nwrk int) (_ [ ...@@ -382,10 +381,10 @@ func zwrkPreconnect(ctx context.Context, url string, at zodb.Tid, nwrk int) (_ [
defer xerr.Contextf(&err, "zwrk-%d/preconnect", nwrk) defer xerr.Contextf(&err, "zwrk-%d/preconnect", nwrk)
storv := make([]zodb.IStorage, nwrk) storv := make([]zodb.IStorage, nwrk)
wg, ctx := errgroup.WithContext(ctx) wg := xsync.NewWorkGroup(ctx)
for i := 0; i < nwrk; i++ { for i := 0; i < nwrk; i++ {
i := i i := i
wg.Go(func() error { wg.Go(func(ctx context.Context) error {
// open storage without caching - we need to take // open storage without caching - we need to take
// latency of every request into account, and a cache // latency of every request into account, and a cache
// could be inhibiting (e.g. making significantly // could be inhibiting (e.g. making significantly
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment