-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read the clock fewer times during message routing
Previously, we read the system clock twice for each event unless we switched partitions early due to reaching `maxBatchingMessages` or `maxBatchingSize`. Now, we read the clock once per event. This improves performance (especially for larger batch sizes) as the router function is called for every message produced. A bench test of the default router was added; results are below: ``` name old time/op new time/op delta DefaultRouter 106ns ± 0% 61ns ± 0% -42.64% (p=0.029 n=4+4) DefaultRouter-4 106ns ± 0% 61ns ± 0% ~ (p=0.079 n=4+5) ``` Signed-off-by: Daniel Ferstay <dferstay@splunk.com>
- Loading branch information
Daniel Ferstay
committed
Dec 2, 2020
1 parent
154bff0
commit 3105115
Showing
2 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package pulsar | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/apache/pulsar-client-go/pulsar/internal" | ||
) | ||
|
||
var ( | ||
targetPartition int | ||
) | ||
|
||
func BenchmarkDefaultRouter(b *testing.B) { | ||
const ( | ||
numPartitions = uint32(200) | ||
maxBatchingMessages = 2000 | ||
maxBatchingSize = 524288 | ||
maxBatchingDelay = 100 * time.Millisecond | ||
) | ||
msg := &ProducerMessage{ | ||
Payload: []byte("message 1"), | ||
} | ||
router := NewDefaultRouter(internal.JavaStringHash, maxBatchingMessages, maxBatchingSize, maxBatchingDelay, false) | ||
for i := 0; i < b.N; i++ { | ||
targetPartition = router(msg, numPartitions) | ||
} | ||
} |