-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add benchmark and check program for core ngt #2179
Conversation
[CHATOPS:HELP] ChatOps commands.
|
cmd/tools/cli/benchmark/core/main.go
Outdated
for i := 0; i < row; i++ { | ||
vecs[i] = make([]float32, dim) | ||
for j := 0; j < dim; j++ { | ||
vecs[i][j] = float32(vec[i*dim+j]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
unnecessary conversion (unconvert)
cmd/tools/cli/benchmark/core/main.go
Outdated
"os/signal" | ||
"runtime" | ||
"strings" | ||
"sync" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
import 'sync' is not allowed from list 'main': sync is allowed only by internal/sync (depguard)
cmd/tools/cli/benchmark/core/main.go
Outdated
vectors, _, _ := load("sift-128-euclidean.hdf5") | ||
n, _ := ngt.New( | ||
ngt.WithDimension(len(vectors[0])), | ||
ngt.WithDefaultPoolSize(8), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 8, in detected (gomnd)
cmd/tools/cli/benchmark/core/main.go
Outdated
|
||
var m runtime.MemStats | ||
runtime.ReadMemStats(&m) | ||
log.Infof("%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v", header, vmpeak, vmhwm, vmrss, m.Alloc/1024, m.TotalAlloc/1024, m.HeapAlloc/1024, m.HeapSys/1024, m.HeapInuse/1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 1024, in detected (gomnd)
cmd/tools/cli/benchmark/core/main.go
Outdated
} | ||
output(" insert") | ||
|
||
if err := n.CreateIndex(8); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 8, in detected (gomnd)
return nil, nil, err | ||
} | ||
|
||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
naked return in func load
with 60 lines of code (nakedret)
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2179 +/- ##
==========================================
+ Coverage 30.43% 30.49% +0.05%
==========================================
Files 362 358 -4
Lines 35443 35325 -118
==========================================
- Hits 10787 10772 -15
+ Misses 24143 24052 -91
+ Partials 513 501 -12 ☔ View full report in Codecov by Sentry. |
09e9263
to
cb61392
Compare
Deploying with Cloudflare Pages
|
cb61392
to
af77978
Compare
wg.Add(1) | ||
go func() { | ||
wg.Done() | ||
srv := &http.Server{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)
} | ||
go srv.ListenAndServe() | ||
<-ctx.Done() | ||
srv.Shutdown(context.Background()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
af77978
to
f838ef9
Compare
[WARNING:INTCFG] Changes in |
bccccb4
to
5bc1bd0
Compare
5bc1bd0
to
a1be637
Compare
cmd/tools/cli/benchmark/core/main.go
Outdated
} | ||
output(" insert") | ||
|
||
if err := n.CreateIndex(8); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 8, in detected (gomnd)
cmd/tools/cli/benchmark/core/main.go
Outdated
cancel() | ||
|
||
wg.Wait() | ||
end := time.NewTicker(30 * time.Minute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 30, in detected (gomnd)
cmd/tools/cli/benchmark/core/main.go
Outdated
wg.Wait() | ||
end := time.NewTicker(30 * time.Minute) | ||
defer end.Stop() | ||
ticker := time.NewTicker(5 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 5, in detected (gomnd)
a1be637
to
2ccc077
Compare
cmd/tools/cli/benchmark/core/main.go
Outdated
log.Info(" operation\tVmPeak\tVmHWM\tVmRSS\tAlloc\tTotalAlloc\tHeapAlloc\tHeapSys\tHeapInuse") | ||
output(" start") | ||
defer output(" end") | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Hour*2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 2, in detected (gomnd)
1cd6811
to
f00fad7
Compare
Signed-off-by: Kosuke Morimoto <[email protected]>
}) | ||
} | ||
|
||
func run(ctx context.Context, load bool, path string, dim int, vectors [][]float32, ids []uint, dur time.Duration, output func(header string)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶run
- path
is unused (unparam)
@@ -15,6 +15,7 @@ package comparator | |||
|
|||
import ( | |||
"reflect" | |||
"sync/atomic" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
import 'sync/atomic' is not allowed from list 'main': sync is allowed only by internal/sync (depguard)
// } | ||
// type test struct { | ||
// name string | ||
// args args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Duplicate words (args) found (dupword)
// } | ||
// type test struct { | ||
// name string | ||
// args args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Duplicate words (args) found (dupword)
@@ -50,4 +51,10 @@ | |||
// skipcq: VET-V0008 | |||
return reflect.DeepEqual(x, y) | |||
}) | |||
|
|||
// skipcq: VET-V0008 | |||
AtomicUint64Comparator = Comparer(func(x, y atomic.Uint64) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
AtomicUint64Comparator is a global variable (gochecknoglobals)
cmd/tools/cli/benchmark/core/main.go
Outdated
fn() | ||
} | ||
} | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
S1023: redundant return
statement (gosimple)
// skipcq: VET-V0008 | ||
AtomicUint64Comparator = Comparer(func(x, y atomic.Uint64) bool { | ||
// skipcq: VET-V0008 | ||
return reflect.DeepEqual(x, y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
copylocks: call of reflect.DeepEqual copies lock value: sync/atomic.Uint64 contains sync/atomic.noCopy (govet)
"gonum.org/v1/hdf5" | ||
) | ||
|
||
func main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Function name: main, Cyclomatic Complexity: 31, Halstead Volume: 8179.08, Maintainability Index: 14 (maintidx)
}) | ||
run(ctx, true, path, len(vectors[0]), vectors, ids, time.Hour*2, output) | ||
|
||
ids = ids[:0:0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
SA4006: this value of ids
is never used (staticcheck)
|
||
ids = ids[:0:0] | ||
ids = nil | ||
vectors = vectors[:0:0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
SA4006: this value of vectors
is never used (staticcheck)
Profile Report
|
Signed-off-by: Kosuke Morimoto <[email protected]>
cmd/tools/cli/benchmark/core/main.go
Outdated
<-ctx.Done() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
srv.Shutdown(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
go func() { | ||
const timeout = time.Second * 5 | ||
defer wg.Done() | ||
srv := &http.Server{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
http.Server is missing fields DisableGeneralOptionsHandler, TLSConfig, ReadTimeout, WriteTimeout, IdleTimeout, MaxHeaderBytes, TLSNextProto, ConnState, ErrorLog, BaseContext, ConnContext (exhaustruct)
cmd/tools/cli/benchmark/core/main.go
Outdated
waitForGC = time.Minute * 5 | ||
timeToFinalize = time.Minute * 5 | ||
) | ||
sleep(ctx, time.Second*5, waitForGC, func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 5, in detected (gomnd)
cmd/tools/cli/benchmark/core/main.go
Outdated
runtime.GC() | ||
output("gc") | ||
}) | ||
sleep(ctx, time.Second*5, waitForGC, func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 5, in detected (gomnd)
cmd/tools/cli/benchmark/core/main.go
Outdated
runtime.GC() | ||
output("gc") | ||
}) | ||
sleep(ctx, time.Second*5, timeToFinalize, func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 5, in detected (gomnd)
"gonum.org/v1/hdf5" | ||
) | ||
|
||
func main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Function name: main, Cyclomatic Complexity: 31, Halstead Volume: 8412.52, Maintainability Index: 14 (maintidx)
Signed-off-by: Kosuke Morimoto <[email protected]>
output("save index") | ||
}) | ||
} | ||
sleep(ctx, time.Second*5, time.Minute*10, func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 5, in detected (gomnd)
"gonum.org/v1/hdf5" | ||
) | ||
|
||
func main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Function name: main, Cyclomatic Complexity: 31, Halstead Volume: 8293.88, Maintainability Index: 14 (maintidx)
Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
I'll approve once the conflicts are resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* add core ngt benchmark Signed-off-by: kpango <[email protected]> * add finalizer for pooling Signed-off-by: kpango <[email protected]> * fix benchmark Signed-off-by: Kosuke Morimoto <[email protected]> * fix test Signed-off-by: Kosuke Morimoto <[email protected]> * fix test Signed-off-by: Kosuke Morimoto <[email protected]> * fix test Signed-off-by: Kosuke Morimoto <[email protected]> * fix reviewdog report Signed-off-by: Kosuke Morimoto <[email protected]> * fix reviewdog report Signed-off-by: Kosuke Morimoto <[email protected]> * fix deepsource report Signed-off-by: Kosuke Morimoto <[email protected]> * fix according to comments Signed-off-by: Kosuke Morimoto <[email protected]> --------- Signed-off-by: kpango <[email protected]> Signed-off-by: Kosuke Morimoto <[email protected]> Co-authored-by: kpango <[email protected]>
Description:
Implement core algorithm NGT's benchmark and getting metrics about memory usage.
It has 2 way of measuring memory usage.
One way is to use cmd/tools/cli/benchmark/core/main.go while another way is to use internal/core/algorithm/ngt/ngt_bench_test.go.
If you want detailed metrics, I recommend you to use the first way.
And include some fix.
Related Issue:
Versions:
Checklist:
Special notes for your reviewer: