-
Notifications
You must be signed in to change notification settings - Fork 36
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
Rework clientmap.RefcountMap, add tests, add bench tests. #610
Rework clientmap.RefcountMap, add tests, add bench tests. #610
Conversation
Is test failing if work with |
Yep, it is not the line to line test. In the real test there was |
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
4cb3ecb
to
7936339
Compare
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
efd79a5
to
5942072
Compare
pkg/tools/clientmap/bench_test.go
Outdated
|
||
func BenchmarkMap(b *testing.B) { | ||
var m clientmap.Map | ||
b.SetParallelism(1000) |
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.
Why do we need to use 1000
here?
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.
You are right, there is no need to use such big numbers in here. Our case is:
- executors count > IDs count (multiple connections to single clientURL)
- IDs count and executors count should be some prime numbers to be sure that all types of operations are executed on all ID+executor pairs
Probably something like 23 executors and 11 IDs is well enough for us in such case.
pkg/tools/clientmap/bench_test.go
Outdated
var m clientmap.Map | ||
b.SetParallelism(1000) | ||
b.RunParallel(func(pb *testing.PB) { | ||
client := null.NewClient() |
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.
This allocation could a little bit affects results.
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.
I have tried with it and without it, it doesn't affect the results.
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.
I guess it can affect tests with cmd go test -v -bench=. -benchmem
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.
Fixed with per-test readonly client.
pkg/tools/clientmap/refcount_test.go
Outdated
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/null" | ||
"github.com/networkservicemesh/sdk/pkg/tools/clientmap" | ||
) | ||
|
||
const ( | ||
parallelCount = 1000 |
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.
Why 1000?
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.
My fault it is not actually the parallelCount
but the retriesCount
.
TestRefcountMap_Actions
is not the test fully validating the correctness of the RefcountMap
. It should eventually fail if RefcountMap
is invalid. So if we start increasing retries count, such eventually is becoming most probably.
1000 is good, because it is not too big to make test performing > 1 sec (10000 is too big for such case) and not too small to keep eventually somewhere far away from us.
@@ -1,3 +1,5 @@ | |||
// Copyright (c) 2020 Doc.ai and/or its affiliates. |
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.
I feel this test can be simplified.
Please take a look at tests from sync.Map https://golang.org/src/sync/map_test.go
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.
It is the only way to add some eventually failing on incorrect implementation test I see. There are no such tests actually in the sync.Map
tests. Such tests should be very helpful for someone who will try to optimize the RefcountMap
implementation.
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
a0e26bd
to
8cbe94b
Compare
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#610 networkservicemesh/sdk PR link: networkservicemesh/sdk#610 networkservicemesh/sdk commit message: commit 1080307813ee9db83b78bf0a3331b7def61258e4 Author: Vladimir Popov <vladimir.popov@xored.com> Date: Wed Dec 9 15:01:32 2020 +0700 Rework clientmap.RefcountMap, add tests, add bench tests. (#610) * Rework clientmap.RefcountMap, add tests, add bench tests. Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Make RefcountMap.LoadAndDelete(), .Delete() return deleted Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add README, fix copyright issues Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix naming issue§ Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix bench tests Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
Issue
Existing refcount map is incorrect, such test can fail:
Solution
Rework refcount map with per-entry locks, add action tests, add bench tests.