-
Notifications
You must be signed in to change notification settings - Fork 208
Fix appendOrMergeRPC inefficiency in message size recalculation #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "io" | ||
| mrand "math/rand" | ||
| "sort" | ||
| "strconv" | ||
| "strings" | ||
| "sync" | ||
| "sync/atomic" | ||
|
|
@@ -2418,6 +2419,7 @@ func TestFragmentRPCFunction(t *testing.T) { | |
| ensureBelowLimit(results) | ||
| msgsPerRPC := limit / msgSize | ||
| expectedRPCs := nMessages / msgsPerRPC | ||
| expectedRPCs += 1 // add one more message to account for message size approximation when fragmenting | ||
| if len(results) != expectedRPCs { | ||
| t.Fatalf("expected %d RPC messages in output, got %d", expectedRPCs, len(results)) | ||
| } | ||
|
|
@@ -3675,3 +3677,48 @@ func TestPublishDuplicateMessage(t *testing.T) { | |
| t.Fatal("Duplicate message should not return an error") | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkAppendOrMergeRPC(b *testing.B) { | ||
| makeTestRPC := func(numMsgs int, msgSize int) RPC { | ||
| msgs := make([]*pb.Message, numMsgs) | ||
| payload := make([]byte, msgSize) | ||
| for i := range msgs { | ||
| msgs[i] = &pb.Message{ | ||
| Data: payload, | ||
| From: []byte(strconv.Itoa(i)), | ||
| } | ||
| } | ||
| return RPC{ | ||
| RPC: pb.RPC{ | ||
| Publish: msgs, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In your workload, do you see RPCs being split primarily due to many messages in a single RPC? I ask because we could add some optimizations if so.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, more messages added into |
||
| }, | ||
| } | ||
| } | ||
| b.Run("small", func(b *testing.B) { | ||
| r := mrand.New(mrand.NewSource(99)) | ||
| const numRPCs = 3 | ||
| const msgSize = 1024 | ||
| rpcs := make([]RPC, numRPCs) | ||
| for i := 0; i < numRPCs; i++ { | ||
| rpcs[i] = makeTestRPC(5, msgSize+r.Intn(100)) | ||
| } | ||
| b.ResetTimer() | ||
| for i := 0; i < b.N; i++ { | ||
| _ = appendOrMergeRPC(nil, DefaultMaxMessageSize, rpcs...) | ||
| } | ||
| }) | ||
|
|
||
| b.Run("large", func(b *testing.B) { | ||
| r := mrand.New(mrand.NewSource(99)) | ||
| const numRPCs = 30 | ||
| const msgSize = 50 * 1024 | ||
| rpcs := make([]RPC, numRPCs) | ||
| for i := 0; i < numRPCs; i++ { | ||
| rpcs[i] = makeTestRPC(20, msgSize+r.Intn(100)) | ||
| } | ||
| b.ResetTimer() | ||
| for i := 0; i < b.N; i++ { | ||
| _ = appendOrMergeRPC(nil, DefaultMaxMessageSize, rpcs...) | ||
| } | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.