@@ -10,89 +10,90 @@ import (
10
10
)
11
11
12
12
type fakeCommand struct {
13
+ baseCommand
13
14
namespace string
14
15
namespaces []string
15
16
ct commandType
16
17
}
17
18
18
- func (fc fakeCommand ) getNamespaces () * map [string ]uint64 {
19
- result := make (map [string ]uint64 , 0 )
19
+ func (fc * fakeCommand ) getNamespaces () map [string ]uint64 {
20
+ result := make (map [string ]uint64 , len ( fc . namespaces ) )
20
21
for _ , namespace := range fc .namespaces {
21
22
result [namespace ]++
22
23
}
23
24
24
- return & result
25
+ return result
25
26
}
26
27
27
- func (fc fakeCommand ) getNamespace () * string {
28
+ func (fc * fakeCommand ) getNamespace () * string {
28
29
return nil
29
30
}
30
31
31
- func (fc fakeCommand ) commandType () commandType {
32
+ func (fc * fakeCommand ) commandType () commandType {
32
33
return fc .ct
33
34
}
34
35
35
- func (fn fakeCommand ) Execute () Error {
36
+ func (fn * fakeCommand ) Execute () Error {
36
37
return nil
37
38
}
38
39
39
- func (fn fakeCommand ) getPolicy (ifc command ) Policy {
40
+ func (fn * fakeCommand ) getPolicy (ifc command ) Policy {
40
41
return nil
41
42
}
42
43
43
- func (fn fakeCommand ) writeBuffer (ifc command ) Error {
44
+ func (fn * fakeCommand ) writeBuffer (ifc command ) Error {
44
45
return nil
45
46
}
46
47
47
- func (fn fakeCommand ) getNode (ifc command ) (* Node , Error ) {
48
+ func (fn * fakeCommand ) getNode (ifc command ) (* Node , Error ) {
48
49
return nil , nil
49
50
}
50
51
51
- func (fn fakeCommand ) getConnection (policy Policy ) (* Connection , Error ) {
52
+ func (fn * fakeCommand ) getConnection (policy Policy ) (* Connection , Error ) {
52
53
return nil , nil
53
54
}
54
55
55
- func (fn fakeCommand ) putConnection (conn * Connection ) {
56
+ func (fn * fakeCommand ) putConnection (conn * Connection ) {
56
57
57
58
}
58
59
59
- func (fn fakeCommand ) parseResult (ifc command , conn * Connection ) Error {
60
+ func (fn * fakeCommand ) parseResult (ifc command , conn * Connection ) Error {
60
61
return nil
61
62
}
62
63
63
- func (fn fakeCommand ) parseRecordResults (ifc command , receiveSize int ) (bool , Error ) {
64
+ func (fn * fakeCommand ) parseRecordResults (ifc command , receiveSize int ) (bool , Error ) {
64
65
return false , nil
65
66
}
66
67
67
- func (fn fakeCommand ) prepareRetry (ifc command , isTimeout bool ) bool {
68
+ func (fn * fakeCommand ) prepareRetry (ifc command , isTimeout bool ) bool {
68
69
return false
69
70
}
70
71
71
- func (fn fakeCommand ) isRead () bool {
72
+ func (fn * fakeCommand ) isRead () bool {
72
73
return false
73
74
}
74
75
75
- func (fn fakeCommand ) onInDoubt () {
76
+ func (fn * fakeCommand ) onInDoubt () {
76
77
77
78
}
78
79
79
- func (fn fakeCommand ) execute (ifc command ) Error {
80
+ func (fn * fakeCommand ) execute (ifc command ) Error {
80
81
return nil
81
82
}
82
83
83
- func (fn fakeCommand ) executeIter (ifc command , iter int ) Error {
84
+ func (fn * fakeCommand ) executeIter (ifc command , iter int ) Error {
84
85
return nil
85
86
}
86
87
87
- func (fn fakeCommand ) executeAt (ifc command , policy * BasePolicy , deadline time.Time , iterations int ) Error {
88
+ func (fn * fakeCommand ) executeAt (ifc command , policy * BasePolicy , deadline time.Time , iterations int ) Error {
88
89
return nil
89
90
}
90
91
91
- func (fn fakeCommand ) canPutConnBack () bool {
92
+ func (fn * fakeCommand ) canPutConnBack () bool {
92
93
return false
93
94
}
94
95
95
- func newStub () ( * baseCommand , fakeCommand ) {
96
+ func newStub () * fakeCommand {
96
97
mp := DefaultMetricsPolicy ()
97
98
nodeStats := newNodeStats (mp )
98
99
me .Store (true )
@@ -105,19 +106,20 @@ func newStub() (*baseCommand, fakeCommand) {
105
106
}
106
107
107
108
// baseCommand to be used for the benchmark.
108
- cmd := & baseCommand {
109
+ cmd := baseCommand {
109
110
node : node ,
110
111
}
111
112
112
113
// Use a non-empty namespace and a command type (for example, ttGet).
113
114
fcmd := fakeCommand {
114
- namespace : "test" ,
115
- ct : ttGet ,
115
+ baseCommand : cmd ,
116
+ namespace : "test" ,
117
+ ct : ttGet ,
116
118
}
117
- return cmd , fcmd
119
+ return & fcmd
118
120
}
119
121
120
- func newStubWithNamespaces () ( * baseCommand , fakeCommand ) {
122
+ func newStubWithNamespaces () * fakeCommand {
121
123
mp := DefaultMetricsPolicy ()
122
124
nodeStats := newNodeStats (mp )
123
125
me .Store (true )
@@ -130,23 +132,25 @@ func newStubWithNamespaces() (*baseCommand, fakeCommand) {
130
132
}
131
133
132
134
// baseCommand to be used for the benchmark.
133
- cmd := & baseCommand {
135
+ cmd := baseCommand {
134
136
node : node ,
135
137
}
136
138
137
139
// Use a non-empty namespace and a command type (for example, ttGet).
138
140
fcmd := fakeCommand {
139
- namespaces : []string {"test" , "testTwo" , "testThree" , "testFour" , "testFive" , "testSix" },
140
- ct : ttGet ,
141
+ baseCommand : cmd ,
142
+ namespaces : []string {"test" , "testTwo" , "testThree" , "testFour" , "testFive" , "testSix" },
143
+ ct : ttGet ,
141
144
}
142
- return cmd , fcmd
145
+ return & fcmd
143
146
}
144
147
145
148
var me atomic.Bool
146
149
147
150
func BenchmarkApplyDetailedMetricsDataSizeAndLatency (b * testing.B ) {
148
151
b .StopTimer ()
149
- cmd , fcmd := newStubWithNamespaces ()
152
+ fcmd := newStubWithNamespaces ()
153
+ //fcmd := newFakeCmdSingle()
150
154
151
155
// bytesSent value to simulate.
152
156
bytesSent := 100
@@ -155,33 +159,34 @@ func BenchmarkApplyDetailedMetricsDataSizeAndLatency(b *testing.B) {
155
159
b .ReportAllocs ()
156
160
for i := 0 ; i < b .N ; i ++ {
157
161
// Call the function under test.
158
- cmd .applyDetailedMetricsDataSizeAndLatencyOnWrite (fcmd , bytesSent , time .Now ())
162
+ fcmd .applyDetailedMetricsDataSizeAndLatencyOnWrite (fcmd , bytesSent , time .Now ())
159
163
}
160
164
}
161
165
162
166
func BenchmarkApplyDetailedConnectionAq (b * testing.B ) {
163
167
b .StopTimer ()
164
- cmd , fcmd := newStub ()
168
+ fcmd := newStub ()
165
169
166
170
b .StartTimer ()
167
171
b .ResetTimer ()
168
172
b .ReportAllocs ()
169
173
for i := 0 ; i < b .N ; i ++ {
170
174
// Call the function under test.
171
- cmd .applyDetailedMetricsConnectionAq (fcmd , time .Now ())
175
+ fcmd .applyDetailedMetricsConnectionAq (fcmd , time .Now ())
172
176
}
173
177
}
174
178
175
179
func BenchmarkApplyDetailedParsing (b * testing.B ) {
176
180
b .StopTimer ()
177
- cmd , fcmd := newStub ()
181
+ fcmd := newStub ()
178
182
179
183
b .StartTimer ()
180
184
b .ResetTimer ()
181
185
b .ReportAllocs ()
186
+ bytesReceived := 100
182
187
for i := 0 ; i < b .N ; i ++ {
183
188
// Call the function under test.
184
- cmd .applyDetailedMetricsParsing (fcmd , time .Now ())
189
+ fcmd .applyDetailedMetricsParsing (fcmd , time .Now (), int64 ( bytesReceived ))
185
190
}
186
191
}
187
192
@@ -191,9 +196,9 @@ func BenchmarkCommandMergeCommandResultCodeMetrics(b *testing.B) {
191
196
targetNodeStats := newNodeStats (mp )
192
197
sourceNodeStats := newNodeStats (mp )
193
198
194
- sourceNodeStats .updateOrInsert (fakeCommand {namespace : "test" , ct : ttGet }, types .ResultCode (0 ))
195
- sourceNodeStats .updateOrInsert (fakeCommand {namespace : "testTwo" , ct : ttPut }, types .ResultCode (0 ))
196
- sourceNodeStats .updateOrInsert (fakeCommand {namespace : "testThree" , ct : ttExists }, types .ResultCode (0 ))
199
+ sourceNodeStats .updateOrInsert (& fakeCommand {namespace : "test" , ct : ttGet }, types .ResultCode (0 ))
200
+ sourceNodeStats .updateOrInsert (& fakeCommand {namespace : "testTwo" , ct : ttPut }, types .ResultCode (0 ))
201
+ sourceNodeStats .updateOrInsert (& fakeCommand {namespace : "testThree" , ct : ttExists }, types .ResultCode (0 ))
197
202
198
203
b .StartTimer ()
199
204
b .ResetTimer ()
@@ -306,3 +311,21 @@ func BenchmarkCloneAndResetDetailedResultCodeCounts(b *testing.B) {
306
311
}
307
312
}
308
313
}
314
+
315
+ type fakeCmdSingle struct {
316
+ fakeCommand
317
+ }
318
+
319
+ func (fc * fakeCmdSingle ) getNamespaces () map [string ]uint64 {
320
+ return nil
321
+ }
322
+
323
+ func (fc * fakeCmdSingle ) getNamespace () * string {
324
+ return & fc .namespace
325
+ }
326
+
327
+ func newFakeCmdSingle () * fakeCmdSingle {
328
+ return & fakeCmdSingle {
329
+ fakeCommand : * newStub (),
330
+ }
331
+ }
0 commit comments