Skip to content

Commit

Permalink
add BenchmarkSeachWithCreateIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Jul 26, 2023
1 parent b5524d5 commit 7f747cb
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions pkg/agent/core/ngt/service/ngt_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"runtime/trace"
"testing"

stdlog "log"

"github.com/kpango/fuid"
"github.com/vdaas/vald/internal/config"
"github.com/vdaas/vald/internal/errors"
Expand Down Expand Up @@ -155,6 +153,10 @@ func BenchmarkGetObjectWithUpdate(b *testing.B) {
}

func BenchmarkSeachWithCreateIndex(b *testing.B) {
// stdlog.Println("starting benchmark")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

log.Init(log.WithLoggerType(logger.NOP.String()))

datasetPath := "fashion-mnist-784-euclidean.hdf5"
Expand Down Expand Up @@ -204,43 +206,49 @@ func BenchmarkSeachWithCreateIndex(b *testing.B) {
defer trace.Stop()

b.RunParallel(func(pb *testing.PB) {
go func() {
go func(ctx context.Context) {
for {
var err2 error
idxs := make([]uint32, 0, insertCount)

for i := 0; i < insertCount; i++ {
idx := rand.LimitedUint32(uint64(maxindex))
idxs = append(idxs, idx)

err2 = n.Insert(ids[idx], train[idx])
if err2 != nil {
if errors.Is(err2, errors.ErrUUIDAlreadyExists(ids[idx])) {
continue
select {
case <-ctx.Done():
// stdlog.Println("done")
return
default:
var err2 error
idxs := make([]uint32, 0, insertCount)

for i := 0; i < insertCount; i++ {
idx := rand.LimitedUint32(uint64(maxindex))
idxs = append(idxs, idx)

err2 = n.Insert(ids[idx], train[idx])
if err2 != nil {
if errors.Is(err2, errors.ErrUUIDAlreadyExists(ids[idx])) {
continue
}
// stdlog.Println(err2, ": insert error")
}
stdlog.Println(err2, ": insert error")
}
}

err2 = n.CreateIndex(context.Background(), uint32(insertCount))
if err2 != nil {
stdlog.Fatal(err2, "create index error")
}

for _, idx := range idxs {
err2 = n.Delete(ids[idx])
err2 = n.CreateIndex(ctx, uint32(insertCount))
if err2 != nil {
if errors.Is(err2, errors.ErrObjectIDNotFound(ids[idx])) {
continue
// stdlog.Println(err2, "create index error")
}

for _, idx := range idxs {
err2 = n.Delete(ids[idx])
if err2 != nil {
if errors.Is(err2, errors.ErrObjectIDNotFound(ids[idx])) {
continue
}
// stdlog.Println(err2, "delete error")
}
stdlog.Println(err2, "delete error")
}
}
}
}()
}(ctx)
for pb.Next() {
_, err := n.Search(
context.Background(),
ctx,
train[insertCount],
uint32(defaultConfig.SearchEdgeSize),
defaultConfig.DefaultEpsilon,
Expand Down

0 comments on commit 7f747cb

Please sign in to comment.