2 Copyright (c) 2019 AT&T Intellectual Property.
3 Copyright (c) 2018-2019 Nokia.
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
19 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 * platform project (RICP).
31 "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
34 type nsKeysBenchmark struct {
43 type keysBenchmark struct {
50 type groupBenchmark struct {
56 func (bm nsKeysBenchmark) String(oper string) string {
57 return fmt.Sprintf("op=%s ns-cnt=%d key-cnt=%d key-sz=%d value-sz=%d",
58 oper, bm.nsCount, bm.keyCount, bm.keySize, bm.valueSize)
61 func (bm keysBenchmark) String(oper string) string {
62 return fmt.Sprintf("op=%s key-cnt=%d key-sz=%d value-sz=%d",
63 oper, bm.keyCount, bm.keySize, bm.valueSize)
66 func (bm groupBenchmark) String(oper string) string {
67 return fmt.Sprintf("op=%s, mbr-cnt=%d", oper, bm.memberCount)
70 func getNsKeyBenchmarkInput() []nsKeysBenchmark {
71 return []nsKeysBenchmark{
72 {"ns-a", 1, "a", 100, 10, 64},
73 {"ns-b", 10, "b", 100, 10, 64},
74 {"ns-c", 100, "c", 100, 10, 64},
75 {"ns-d", 1000, "d", 100, 10, 64},
76 {"ns-e", 10000, "e", 100, 10, 64},
80 func getKeyBenchmarkInput() []keysBenchmark {
81 return []keysBenchmark{
84 {"c", 1, 10, 64 * 1024},
85 {"d", 1, 10, 1024 * 1024},
86 {"e", 1, 10, 10 * 1024 * 1024},
90 {"h", 1, 100, 64 * 1024},
91 {"i", 1, 100, 1024 * 1024},
92 {"j", 1, 100, 10 * 1024 * 1024},
103 {"v", 1000, 100, 64},
104 {"x", 5000, 100, 64},
108 func BenchmarkMultiNamespaceKeysWrite(b *testing.B) {
109 benchmarks := getNsKeyBenchmarkInput()
111 for _, bm := range benchmarks {
112 b.Run(bm.String("ns-keys-set"), func(b *testing.B) {
113 sdl := sdlgo.NewSyncStorage()
114 value := strings.Repeat("1", bm.valueSize)
115 keyVals := make([]string, 0)
116 for i := 0; i < bm.keyCount; i++ {
117 key := strings.Repeat(bm.keyName+strconv.Itoa(i), bm.keySize)
118 keyVals = append(keyVals, key, value)
121 b.RunParallel(func(pb *testing.PB) {
123 for n := 0; n < bm.nsCount; n++ {
124 err := sdl.Set(bm.ns+strconv.Itoa(n), keyVals)
135 func BenchmarkMultiNamespaceKeysRead(b *testing.B) {
136 benchmarks := getNsKeyBenchmarkInput()
138 for _, bm := range benchmarks {
139 b.Run(bm.String("keys-get"), func(b *testing.B) {
140 sdl := sdlgo.NewSyncStorage()
141 keys := make([]string, 0)
142 for i := 0; i < bm.keyCount; i++ {
143 key := strings.Repeat(bm.keyName+strconv.Itoa(i), bm.keySize)
144 keys = append(keys, key)
147 b.RunParallel(func(pb *testing.PB) {
149 for n := 0; n < bm.nsCount; n++ {
150 _, err := sdl.Get(bm.ns+strconv.Itoa(n), keys)
161 func BenchmarkKeysWrite(b *testing.B) {
162 benchmarks := getKeyBenchmarkInput()
164 for _, bm := range benchmarks {
165 b.Run(bm.String("keys-set"), func(b *testing.B) {
166 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
167 value := strings.Repeat("1", bm.valueSize)
168 keyVals := make([]string, 0)
169 for i := 0; i < bm.keyCount; i++ {
170 key := strings.Repeat(bm.keyName+strconv.Itoa(i), bm.keySize)
171 keyVals = append(keyVals, key, value)
174 b.RunParallel(func(pb *testing.PB) {
176 err := sdl.Set(keyVals)
186 func BenchmarkKeysRead(b *testing.B) {
187 benchmarks := getKeyBenchmarkInput()
189 for _, bm := range benchmarks {
190 b.Run(bm.String("keys-get"), func(b *testing.B) {
191 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
192 keys := make([]string, 0)
193 for i := 0; i < bm.keyCount; i++ {
194 key := strings.Repeat(bm.keyName+strconv.Itoa(i), bm.keySize)
195 keys = append(keys, key)
198 b.RunParallel(func(pb *testing.PB) {
200 _, err := sdl.Get(keys)
210 func BenchmarkGroupMemberAdd(b *testing.B) {
211 benchmarks := []groupBenchmark{
218 for _, bm := range benchmarks {
219 b.Run(bm.String("group-add-member"), func(b *testing.B) {
220 sdl := sdlgo.NewSdlInstance("namespace", sdlgo.NewDatabase())
221 members := make([]string, 0)
222 for i := 0; i < bm.memberCount; i++ {
223 member := bm.member + strconv.Itoa(i)
224 members = append(members, member)
227 b.RunParallel(func(pb *testing.PB) {
229 err := sdl.AddMember(bm.key, members)