Skip to content

sync.Pool for expectation channels#3106

Closed
kasimtj wants to merge 1 commit intoIBM:mainfrom
kasimtj:feature/sync-pool-for-expectation-channels
Closed

sync.Pool for expectation channels#3106
kasimtj wants to merge 1 commit intoIBM:mainfrom
kasimtj:feature/sync-pool-for-expectation-channels

Conversation

@kasimtj
Copy link
Copy Markdown
Contributor

@kasimtj kasimtj commented Feb 26, 2025

Ran benchmarks on solution with sync.Pool for expectation channels on SyncProducer

k.torgaev@macbook-HGX9V4RMKP sarama % benchstat all.txt
goos: darwin
goarch: arm64
pkg: github.com/IBM/sarama
cpu: Apple M2 Pro
                                         │     all.txt     │
                                         │     sec/op      │
SendMessageComparison/SendMessage/Old-12   0.001931n ± 43%
SendMessageComparison/SendMessage/New-12   0.001106n ±  4%
geomean                                    0.001461n
k.torgaev@macbook-HGX9V4RMKP sarama % 

Metadata: "test",
}
b.Run("SendMessage/"+name, func(b *testing.B) {
for i := 0; i < 10; i++ {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i := 0; i < 10; i++ {
for i := 0; i < b.N; i++ {


// NewSyncProducerFromClient creates a new SyncProducer using the given client. It is still
// necessary to call Close() on the underlying client when shutting down this producer.
func NewSyncProducerFromOptimized(client Client) (SyncProducer, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this wouldn’t stay the name, but we should either drop all of FromClient or neither word.

Suggested change
func NewSyncProducerFromOptimized(client Client) (SyncProducer, error) {
func NewSyncProducerFromClientOptimized(client Client) (SyncProducer, error) {

(That is, I expect this is a demonstration that the sync pool way is better without any downside, and so the original implementation should be converted to this implementation.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i wanted to ran benchmarks and compare them, also i will try to run fork on our production and come back with profiler results comparison.

For now can i just add sync.Pool into SyncProducer, remove SyncProducerOptimized and remove benchmark? Is there any suggestions to additional tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i also created an issue for it #3107

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might suggest starting a different branch for the intended-to-be-merged changes. (That is, incorporating the sync.Pool into SyncProducer, and dropping SyncProducerOptimized.) But keeping this sort of change open so anyone can run their own benchmarks locally has a lot of value, even if the PR would just be closed after merging the intended fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linked both of them here
#3107 (comment)

@dnwe
Copy link
Copy Markdown
Collaborator

dnwe commented Mar 2, 2025

Thanks for #3109 - closing this one now

@dnwe dnwe closed this Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants