Skip to content

Commit 23c2f14

Browse files
committed
Discussed changes
1 parent 8e572d3 commit 23c2f14

37 files changed

+222
-182
lines changed

base_read_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (cmd *baseReadCommand) commandType() commandType {
9999
return ttGet
100100
}
101101

102-
func (cmd *baseReadCommand) getNamespaces() *map[string]uint64 {
102+
func (cmd *baseReadCommand) getNamespaces() map[string]uint64 {
103103
return nil
104104
}
105105

base_write_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (cmd *baseWriteCommand) parseHeader() (types.ResultCode, Error) {
101101
return rp.resultCode, nil
102102
}
103103

104-
func (cmd *baseWriteCommand) getNamespaces() *map[string]uint64 {
104+
func (cmd *baseWriteCommand) getNamespaces() map[string]uint64 {
105105
return nil
106106
}
107107

batch_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (cmd *batchCommand) writeBuffer(ifc command) Error {
142142
panic(unreachable)
143143
}
144144

145-
func (cmd *batchCommand) getNamespaces() *map[string]uint64 {
145+
func (cmd *batchCommand) getNamespaces() map[string]uint64 {
146146
return nil
147147
}
148148

batch_command_delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ func (cmd *batchCommandDelete) generateBatchNodes(cluster *Cluster) ([]*batchNod
220220
return newBatchNodeListKeys(cluster, cmd.policy, cmd.keys, nil, cmd.sequenceAP, cmd.sequenceSC, cmd.batch, false)
221221
}
222222

223-
func (cmd *batchCommandDelete) getNamespaces() *map[string]uint64 {
223+
func (cmd *batchCommandDelete) getNamespaces() map[string]uint64 {
224224
response := make(map[string]uint64, len(cmd.keys))
225225
for _, key := range cmd.keys {
226226
response[key.namespace]++
227227
}
228-
return &response
228+
return response
229229
}
230230

231231
func (cmd *batchCommandDelete) getNamespace() *string {

batch_command_exists.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ func (cmd *batchCommandExists) generateBatchNodes(cluster *Cluster) ([]*batchNod
170170
return newBatchNodeListKeys(cluster, cmd.policy, cmd.keys, nil, cmd.sequenceAP, cmd.sequenceSC, cmd.batch, false)
171171
}
172172

173-
func (cmd *batchCommandExists) getNamespaces() *map[string]uint64 {
173+
func (cmd *batchCommandExists) getNamespaces() map[string]uint64 {
174174
response := make(map[string]uint64, len(cmd.keys))
175175
for _, key := range cmd.keys {
176176
response[key.namespace]++
177177
}
178-
return &response
178+
return response
179179
}
180180

181181
func (cmd *batchCommandExists) getNamespace() *string {

batch_command_get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ func (cmd *batchCommandGet) generateBatchNodes(cluster *Cluster) ([]*batchNode,
275275
return newBatchNodeListKeys(cluster, cmd.policy, cmd.keys, nil, cmd.sequenceAP, cmd.sequenceSC, cmd.batch, false)
276276
}
277277

278-
func (cmd *batchCommandGet) getNamespaces() *map[string]uint64 {
278+
func (cmd *batchCommandGet) getNamespaces() map[string]uint64 {
279279
response := make(map[string]uint64, len(cmd.keys))
280280
for _, key := range cmd.keys {
281281
response[key.namespace]++
282282
}
283283

284-
return &response
284+
return response
285285
}
286286

287287
func (cmd *batchCommandGet) getNamespace() *string {

batch_command_operate.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,13 @@ func (cmd *batchCommandOperate) generateBatchNodes(cluster *Cluster) ([]*batchNo
308308
return newBatchOperateNodeListIfcRetry(cluster, cmd.policy, cmd.records, cmd.sequenceAP, cmd.sequenceSC, cmd.batch)
309309
}
310310

311-
func (cmd *batchCommandOperate) getNamespaces() *map[string]uint64 {
311+
func (cmd *batchCommandOperate) getNamespaces() map[string]uint64 {
312312
response := make(map[string]uint64, len(cmd.records))
313313
for _, br := range cmd.records {
314-
switch br := br.(type) {
315-
case *BatchRead:
316-
response[br.Key.namespace]++
317-
case *BatchWrite:
318-
response[br.Key.namespace]++
319-
case *BatchDelete:
320-
response[br.Key.namespace]++
321-
case *BatchUDF:
322-
response[br.Key.namespace]++
323-
}
314+
response[br.key().namespace]++
324315
}
325-
return &response
316+
317+
return response
326318
}
327319

328320
func (cmd *batchCommandOperate) getNamespace() *string {

batch_command_udf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ func (cmd *batchCommandUDF) generateBatchNodes(cluster *Cluster) ([]*batchNode,
230230
return newBatchNodeListKeys(cluster, cmd.policy, cmd.keys, nil, cmd.sequenceAP, cmd.sequenceSC, cmd.batch, false)
231231
}
232232

233-
func (cmd *batchCommandUDF) getNamespaces() *map[string]uint64 {
233+
func (cmd *batchCommandUDF) getNamespaces() map[string]uint64 {
234234
response := make(map[string]uint64, len(cmd.keys))
235235
for _, key := range cmd.keys {
236236
response[key.namespace]++
237237
}
238-
return &response
238+
return response
239239
}
240240

241241
func (cmd *batchCommandUDF) getNamespace() *string {

batch_index_command_get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ func (cmd *batchIndexCommandGet) parseRecord(key *Key, opCount int, generation,
255255
return newRecord(cmd.node, key, bins, generation, expiration), nil
256256
}
257257

258-
func (cmd *batchIndexCommandGet) getNamespaces() *map[string]uint64 {
258+
func (cmd *batchIndexCommandGet) getNamespaces() map[string]uint64 {
259259
response := make(map[string]uint64, len(cmd.records))
260260
for _, br := range cmd.records {
261261
response[br.Key.namespace]++
262262
}
263-
return &response
263+
return response
264264
}
265265

266266
func (cmd *batchIndexCommandGet) getNamespace() *string {

bench_apply_metrics_test.go

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,89 +10,90 @@ import (
1010
)
1111

1212
type fakeCommand struct {
13+
baseCommand
1314
namespace string
1415
namespaces []string
1516
ct commandType
1617
}
1718

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))
2021
for _, namespace := range fc.namespaces {
2122
result[namespace]++
2223
}
2324

24-
return &result
25+
return result
2526
}
2627

27-
func (fc fakeCommand) getNamespace() *string {
28+
func (fc *fakeCommand) getNamespace() *string {
2829
return nil
2930
}
3031

31-
func (fc fakeCommand) commandType() commandType {
32+
func (fc *fakeCommand) commandType() commandType {
3233
return fc.ct
3334
}
3435

35-
func (fn fakeCommand) Execute() Error {
36+
func (fn *fakeCommand) Execute() Error {
3637
return nil
3738
}
3839

39-
func (fn fakeCommand) getPolicy(ifc command) Policy {
40+
func (fn *fakeCommand) getPolicy(ifc command) Policy {
4041
return nil
4142
}
4243

43-
func (fn fakeCommand) writeBuffer(ifc command) Error {
44+
func (fn *fakeCommand) writeBuffer(ifc command) Error {
4445
return nil
4546
}
4647

47-
func (fn fakeCommand) getNode(ifc command) (*Node, Error) {
48+
func (fn *fakeCommand) getNode(ifc command) (*Node, Error) {
4849
return nil, nil
4950
}
5051

51-
func (fn fakeCommand) getConnection(policy Policy) (*Connection, Error) {
52+
func (fn *fakeCommand) getConnection(policy Policy) (*Connection, Error) {
5253
return nil, nil
5354
}
5455

55-
func (fn fakeCommand) putConnection(conn *Connection) {
56+
func (fn *fakeCommand) putConnection(conn *Connection) {
5657

5758
}
5859

59-
func (fn fakeCommand) parseResult(ifc command, conn *Connection) Error {
60+
func (fn *fakeCommand) parseResult(ifc command, conn *Connection) Error {
6061
return nil
6162
}
6263

63-
func (fn fakeCommand) parseRecordResults(ifc command, receiveSize int) (bool, Error) {
64+
func (fn *fakeCommand) parseRecordResults(ifc command, receiveSize int) (bool, Error) {
6465
return false, nil
6566
}
6667

67-
func (fn fakeCommand) prepareRetry(ifc command, isTimeout bool) bool {
68+
func (fn *fakeCommand) prepareRetry(ifc command, isTimeout bool) bool {
6869
return false
6970
}
7071

71-
func (fn fakeCommand) isRead() bool {
72+
func (fn *fakeCommand) isRead() bool {
7273
return false
7374
}
7475

75-
func (fn fakeCommand) onInDoubt() {
76+
func (fn *fakeCommand) onInDoubt() {
7677

7778
}
7879

79-
func (fn fakeCommand) execute(ifc command) Error {
80+
func (fn *fakeCommand) execute(ifc command) Error {
8081
return nil
8182
}
8283

83-
func (fn fakeCommand) executeIter(ifc command, iter int) Error {
84+
func (fn *fakeCommand) executeIter(ifc command, iter int) Error {
8485
return nil
8586
}
8687

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 {
8889
return nil
8990
}
9091

91-
func (fn fakeCommand) canPutConnBack() bool {
92+
func (fn *fakeCommand) canPutConnBack() bool {
9293
return false
9394
}
9495

95-
func newStub() (*baseCommand, fakeCommand) {
96+
func newStub() *fakeCommand {
9697
mp := DefaultMetricsPolicy()
9798
nodeStats := newNodeStats(mp)
9899
me.Store(true)
@@ -105,19 +106,20 @@ func newStub() (*baseCommand, fakeCommand) {
105106
}
106107

107108
// baseCommand to be used for the benchmark.
108-
cmd := &baseCommand{
109+
cmd := baseCommand{
109110
node: node,
110111
}
111112

112113
// Use a non-empty namespace and a command type (for example, ttGet).
113114
fcmd := fakeCommand{
114-
namespace: "test",
115-
ct: ttGet,
115+
baseCommand: cmd,
116+
namespace: "test",
117+
ct: ttGet,
116118
}
117-
return cmd, fcmd
119+
return &fcmd
118120
}
119121

120-
func newStubWithNamespaces() (*baseCommand, fakeCommand) {
122+
func newStubWithNamespaces() *fakeCommand {
121123
mp := DefaultMetricsPolicy()
122124
nodeStats := newNodeStats(mp)
123125
me.Store(true)
@@ -130,23 +132,25 @@ func newStubWithNamespaces() (*baseCommand, fakeCommand) {
130132
}
131133

132134
// baseCommand to be used for the benchmark.
133-
cmd := &baseCommand{
135+
cmd := baseCommand{
134136
node: node,
135137
}
136138

137139
// Use a non-empty namespace and a command type (for example, ttGet).
138140
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,
141144
}
142-
return cmd, fcmd
145+
return &fcmd
143146
}
144147

145148
var me atomic.Bool
146149

147150
func BenchmarkApplyDetailedMetricsDataSizeAndLatency(b *testing.B) {
148151
b.StopTimer()
149-
cmd, fcmd := newStubWithNamespaces()
152+
fcmd := newStubWithNamespaces()
153+
//fcmd := newFakeCmdSingle()
150154

151155
// bytesSent value to simulate.
152156
bytesSent := 100
@@ -155,33 +159,34 @@ func BenchmarkApplyDetailedMetricsDataSizeAndLatency(b *testing.B) {
155159
b.ReportAllocs()
156160
for i := 0; i < b.N; i++ {
157161
// Call the function under test.
158-
cmd.applyDetailedMetricsDataSizeAndLatencyOnWrite(fcmd, bytesSent, time.Now())
162+
fcmd.applyDetailedMetricsDataSizeAndLatencyOnWrite(fcmd, bytesSent, time.Now())
159163
}
160164
}
161165

162166
func BenchmarkApplyDetailedConnectionAq(b *testing.B) {
163167
b.StopTimer()
164-
cmd, fcmd := newStub()
168+
fcmd := newStub()
165169

166170
b.StartTimer()
167171
b.ResetTimer()
168172
b.ReportAllocs()
169173
for i := 0; i < b.N; i++ {
170174
// Call the function under test.
171-
cmd.applyDetailedMetricsConnectionAq(fcmd, time.Now())
175+
fcmd.applyDetailedMetricsConnectionAq(fcmd, time.Now())
172176
}
173177
}
174178

175179
func BenchmarkApplyDetailedParsing(b *testing.B) {
176180
b.StopTimer()
177-
cmd, fcmd := newStub()
181+
fcmd := newStub()
178182

179183
b.StartTimer()
180184
b.ResetTimer()
181185
b.ReportAllocs()
186+
bytesReceived := 100
182187
for i := 0; i < b.N; i++ {
183188
// Call the function under test.
184-
cmd.applyDetailedMetricsParsing(fcmd, time.Now())
189+
fcmd.applyDetailedMetricsParsing(fcmd, time.Now(), int64(bytesReceived))
185190
}
186191
}
187192

@@ -191,9 +196,9 @@ func BenchmarkCommandMergeCommandResultCodeMetrics(b *testing.B) {
191196
targetNodeStats := newNodeStats(mp)
192197
sourceNodeStats := newNodeStats(mp)
193198

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))
197202

198203
b.StartTimer()
199204
b.ResetTimer()
@@ -306,3 +311,21 @@ func BenchmarkCloneAndResetDetailedResultCodeCounts(b *testing.B) {
306311
}
307312
}
308313
}
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

Comments
 (0)