Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
e16fa51b
Commit
e16fa51b
authored
3 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
more sensible benchmarks
parent
fef528c1
No related branches found
No related tags found
No related merge requests found
Pipeline
#81066
failed
3 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
store/mutexStore.go
+77
-0
77 additions, 0 deletions
store/mutexStore.go
store/nologStore.go
+77
-0
77 additions, 0 deletions
store/nologStore.go
store/storeBenchmark_test.go
+96
-24
96 additions, 24 deletions
store/storeBenchmark_test.go
with
250 additions
and
24 deletions
store/mutexStore.go
0 → 100644
+
77
−
0
View file @
e16fa51b
package
store
import
(
"sync"
"code.fbi.h-da.de/danet/gosdn/interfaces/store"
"code.fbi.h-da.de/danet/gosdn/nucleus/errors"
"github.com/google/uuid"
)
// newmutexStore returns a mutexStore
func
newMutexStore
()
*
mutexStore
{
return
&
mutexStore
{
Store
:
make
(
map
[
uuid
.
UUID
]
store
.
Storable
),
storeLock
:
sync
.
Mutex
{}}
}
type
mutexStore
struct
{
Store
map
[
uuid
.
UUID
]
store
.
Storable
storeLock
sync
.
Mutex
}
// Exists takes a Storable's UUID and checks its existence in the store.
func
(
s
*
mutexStore
)
Exists
(
id
uuid
.
UUID
)
bool
{
s
.
storeLock
.
Lock
()
defer
s
.
storeLock
.
Unlock
()
_
,
ok
:=
s
.
Store
[
id
]
return
ok
}
// Add adds a Storable to the Store
func
(
s
*
mutexStore
)
Add
(
item
store
.
Storable
)
error
{
if
s
.
Exists
(
item
.
ID
())
{
return
&
errors
.
ErrAlreadyExists
{
Item
:
item
}
}
s
.
storeLock
.
Lock
()
s
.
Store
[
item
.
ID
()]
=
item
s
.
storeLock
.
Unlock
()
return
nil
}
// Get takes a Storable's UUID and returns the Storable. If the requested
// Storable does not exist an error is returned. Get is only type safe for
// this Storable interface. For type safe get operations on specialised stores
// use GetDevice, GetPND, GetSBI, or GetChange respectively.
func
(
s
*
mutexStore
)
Get
(
id
uuid
.
UUID
)
(
store
.
Storable
,
error
)
{
if
!
s
.
Exists
(
id
)
{
return
nil
,
&
errors
.
ErrNotFound
{
ID
:
id
}
}
s
.
storeLock
.
Lock
()
defer
s
.
storeLock
.
Unlock
()
return
s
.
Store
[
id
],
nil
}
// Delete takes a Storable's UUID and deletes it. If the specified UUID does not
// exist in the Store an error is returned.
func
(
s
*
mutexStore
)
Delete
(
id
uuid
.
UUID
)
error
{
if
!
s
.
Exists
(
id
)
{
return
&
errors
.
ErrNotFound
{
ID
:
id
}
}
s
.
storeLock
.
Lock
()
delete
(
s
.
Store
,
id
)
s
.
storeLock
.
Unlock
()
return
nil
}
// UUIDs returns all UUIDs in the store.
func
(
s
*
mutexStore
)
UUIDs
()
[]
uuid
.
UUID
{
s
.
storeLock
.
Lock
()
defer
s
.
storeLock
.
Unlock
()
keys
:=
make
([]
uuid
.
UUID
,
len
(
s
.
Store
))
i
:=
0
for
k
:=
range
s
.
Store
{
keys
[
i
]
=
k
i
++
}
return
keys
}
This diff is collapsed.
Click to expand it.
store/nologStore.go
0 → 100644
+
77
−
0
View file @
e16fa51b
package
store
import
(
"sync"
"code.fbi.h-da.de/danet/gosdn/interfaces/store"
"code.fbi.h-da.de/danet/gosdn/nucleus/errors"
"github.com/google/uuid"
)
// newnologStore returns a nologStore
func
newNologStore
()
*
nologStore
{
return
&
nologStore
{
Store
:
make
(
map
[
uuid
.
UUID
]
store
.
Storable
),
storeLock
:
sync
.
RWMutex
{}}
}
type
nologStore
struct
{
Store
map
[
uuid
.
UUID
]
store
.
Storable
storeLock
sync
.
RWMutex
}
// Exists takes a Storable's UUID and checks its existence in the store.
func
(
s
*
nologStore
)
Exists
(
id
uuid
.
UUID
)
bool
{
s
.
storeLock
.
RLock
()
defer
s
.
storeLock
.
RUnlock
()
_
,
ok
:=
s
.
Store
[
id
]
return
ok
}
// Add adds a Storable to the Store
func
(
s
*
nologStore
)
Add
(
item
store
.
Storable
)
error
{
if
s
.
Exists
(
item
.
ID
())
{
return
&
errors
.
ErrAlreadyExists
{
Item
:
item
}
}
s
.
storeLock
.
Lock
()
s
.
Store
[
item
.
ID
()]
=
item
s
.
storeLock
.
Unlock
()
return
nil
}
// Get takes a Storable's UUID and returns the Storable. If the requested
// Storable does not exist an error is returned. Get is only type safe for
// this Storable interface. For type safe get operations on specialised stores
// use GetDevice, GetPND, GetSBI, or GetChange respectively.
func
(
s
*
nologStore
)
Get
(
id
uuid
.
UUID
)
(
store
.
Storable
,
error
)
{
if
!
s
.
Exists
(
id
)
{
return
nil
,
&
errors
.
ErrNotFound
{
ID
:
id
}
}
s
.
storeLock
.
RLock
()
defer
s
.
storeLock
.
RUnlock
()
return
s
.
Store
[
id
],
nil
}
// Delete takes a Storable's UUID and deletes it. If the specified UUID does not
// exist in the Store an error is returned.
func
(
s
*
nologStore
)
Delete
(
id
uuid
.
UUID
)
error
{
if
!
s
.
Exists
(
id
)
{
return
&
errors
.
ErrNotFound
{
ID
:
id
}
}
s
.
storeLock
.
Lock
()
delete
(
s
.
Store
,
id
)
s
.
storeLock
.
Unlock
()
return
nil
}
// UUIDs returns all UUIDs in the store.
func
(
s
*
nologStore
)
UUIDs
()
[]
uuid
.
UUID
{
s
.
storeLock
.
RLock
()
defer
s
.
storeLock
.
RUnlock
()
keys
:=
make
([]
uuid
.
UUID
,
len
(
s
.
Store
))
i
:=
0
for
k
:=
range
s
.
Store
{
keys
[
i
]
=
k
i
++
}
return
keys
}
This diff is collapsed.
Click to expand it.
store/storeBenchmark_test.go
+
96
−
24
View file @
e16fa51b
...
...
@@ -28,6 +28,14 @@ func BenchmarkAdd(b *testing.B) {
name
:
"channel"
,
s
:
newChannelStore
(),
},
{
name
:
"mutex"
,
s
:
newMutexStore
(),
},
{
name
:
"nolog"
,
s
:
newNologStore
(),
},
}
for
_
,
bm
:=
range
benchmarks
{
b
.
Run
(
bm
.
name
,
func
(
b
*
testing
.
B
)
{
...
...
@@ -54,6 +62,14 @@ func BenchmarkGet(b *testing.B) {
name
:
"channel"
,
s
:
newChannelStore
(),
},
{
name
:
"mutex"
,
s
:
newMutexStore
(),
},
{
name
:
"nolog"
,
s
:
newNologStore
(),
},
}
for
_
,
bm
:=
range
benchmarks
{
b
.
Run
(
bm
.
name
,
func
(
b
*
testing
.
B
)
{
...
...
@@ -77,6 +93,14 @@ func BenchmarkAddGet(b *testing.B) {
name
:
"channel"
,
s
:
newChannelStore
(),
},
{
name
:
"mutex"
,
s
:
newMutexStore
(),
},
{
name
:
"nolog"
,
s
:
newNologStore
(),
},
}
for
_
,
bm
:=
range
benchmarks
{
b
.
Run
(
bm
.
name
,
func
(
b
*
testing
.
B
)
{
...
...
@@ -101,24 +125,40 @@ func BenchmarkGetParallel(b *testing.B) {
iterations
int
}{
{
name
:
"generic"
,
name
:
"generic"
,
s
:
newGenericStore
(),
},
{
name
:
"channel"
,
s
:
newChannelStore
(),
},
{
name
:
"mutex"
,
s
:
newMutexStore
(),
},
{
name
:
"nolog"
,
s
:
newNologStore
(),
},
{
name
:
"generic overload"
,
s
:
newGenericStore
(),
iterations
:
4
,
},
{
name
:
"channel"
,
name
:
"channel
overload
"
,
s
:
newChannelStore
(),
iterations
:
4
,
},
{
name
:
"
generic long
"
,
s
:
new
Generic
Store
(),
iterations
:
6
4
,
name
:
"
mutex overload
"
,
s
:
new
Mutex
Store
(),
iterations
:
4
,
},
{
name
:
"
channel long
"
,
s
:
new
Channel
Store
(),
iterations
:
6
4
,
name
:
"
nolog overload
"
,
s
:
new
Nolog
Store
(),
iterations
:
4
,
},
}
for
_
,
bm
:=
range
benchmarks
{
...
...
@@ -143,24 +183,40 @@ func BenchmarkAddParallel(b *testing.B) {
iterations
int
}{
{
name
:
"generic"
,
name
:
"generic"
,
s
:
newGenericStore
(),
},
{
name
:
"channel"
,
s
:
newChannelStore
(),
},
{
name
:
"mutex"
,
s
:
newMutexStore
(),
},
{
name
:
"nolog"
,
s
:
newNologStore
(),
},
{
name
:
"generic overload"
,
s
:
newGenericStore
(),
iterations
:
4
,
},
{
name
:
"channel"
,
name
:
"channel
overload
"
,
s
:
newChannelStore
(),
iterations
:
4
,
},
{
name
:
"
generic long
"
,
s
:
new
Generic
Store
(),
iterations
:
6
4
,
name
:
"
mutex overload
"
,
s
:
new
Mutex
Store
(),
iterations
:
4
,
},
{
name
:
"
channel long
"
,
s
:
new
Channel
Store
(),
iterations
:
6
4
,
name
:
"
nolog overload
"
,
s
:
new
Nolog
Store
(),
iterations
:
4
,
},
}
for
_
,
bm
:=
range
benchmarks
{
...
...
@@ -188,24 +244,40 @@ func BenchmarkAddGetParallel(b *testing.B) {
iterations
int
}{
{
name
:
"generic"
,
name
:
"generic"
,
s
:
newGenericStore
(),
},
{
name
:
"channel"
,
s
:
newChannelStore
(),
},
{
name
:
"mutex"
,
s
:
newMutexStore
(),
},
{
name
:
"nolog"
,
s
:
newNologStore
(),
},
{
name
:
"generic overload"
,
s
:
newGenericStore
(),
iterations
:
4
,
},
{
name
:
"channel"
,
name
:
"channel
overload
"
,
s
:
newChannelStore
(),
iterations
:
4
,
},
{
name
:
"
generic long
"
,
s
:
new
Generic
Store
(),
iterations
:
6
4
,
name
:
"
mutex overload
"
,
s
:
new
Mutex
Store
(),
iterations
:
4
,
},
{
name
:
"
channel long
"
,
s
:
new
Channel
Store
(),
iterations
:
6
4
,
name
:
"
nolog overload
"
,
s
:
new
Nolog
Store
(),
iterations
:
4
,
},
}
for
_
,
bm
:=
range
benchmarks
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment