Skip to content

Commit

Permalink
add encoderBufferPool benchmark option
Browse files Browse the repository at this point in the history
Add an option to use a shared encoder buffer pool during benchmarks.
  • Loading branch information
HippoBaro committed Sep 11, 2023
1 parent bfa059a commit e1ae3c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions benchmark/benchmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var (
recvBufferPool = flags.StringWithAllowedValues("recvBufferPool", recvBufferPoolNil, "Configures the shared receive buffer pool. One of: nil, simple, all", allRecvBufferPools)
sharedWriteBuffer = flags.StringWithAllowedValues("sharedWriteBuffer", toggleModeOff,
fmt.Sprintf("Configures both client and server to share write buffer - One of: %v", strings.Join(allToggleModes, ", ")), allToggleModes)
encoderBufferPool = flags.StringWithAllowedValues("encoderBufferPool", toggleModeOff, fmt.Sprintf("Configures both client and server to share encoder buffers - One of: %v", strings.Join(allToggleModes, ", ")), allToggleModes)

logger = grpclog.Component("benchmark")
)
Expand Down Expand Up @@ -341,6 +342,10 @@ func makeClients(bf stats.Features) ([]testgrpc.BenchmarkServiceClient, func())
opts = append(opts, grpc.WithSharedWriteBuffer(true))
sopts = append(sopts, grpc.SharedWriteBuffer(true))
}
if bf.EncoderBufferPool {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.ClientEncoderBufferPool(grpc.NewSharedBufferPool())))
sopts = append(sopts, grpc.ServerEncoderBufferPool(grpc.NewSharedBufferPool()))
}
if bf.ServerWriteBufferSize >= 0 {
sopts = append(sopts, grpc.WriteBufferSize(bf.ServerWriteBufferSize))
}
Expand Down Expand Up @@ -610,6 +615,7 @@ type featureOpts struct {
sleepBetweenRPCs []time.Duration
recvBufferPools []string
sharedWriteBuffer []bool
encoderBufferPool []bool
}

// makeFeaturesNum returns a slice of ints of size 'maxFeatureIndex' where each
Expand Down Expand Up @@ -660,6 +666,8 @@ func makeFeaturesNum(b *benchOpts) []int {
featuresNum[i] = len(b.features.recvBufferPools)
case stats.SharedWriteBuffer:
featuresNum[i] = len(b.features.sharedWriteBuffer)
case stats.EncoderBufferPool:
featuresNum[i] = len(b.features.encoderBufferPool)
default:
log.Fatalf("Unknown feature index %v in generateFeatures. maxFeatureIndex is %v", i, stats.MaxFeatureIndex)
}
Expand Down Expand Up @@ -730,6 +738,7 @@ func (b *benchOpts) generateFeatures(featuresNum []int) []stats.Features {
SleepBetweenRPCs: b.features.sleepBetweenRPCs[curPos[stats.SleepBetweenRPCs]],
RecvBufferPool: b.features.recvBufferPools[curPos[stats.RecvBufferPool]],
SharedWriteBuffer: b.features.sharedWriteBuffer[curPos[stats.SharedWriteBuffer]],
EncoderBufferPool: b.features.encoderBufferPool[curPos[stats.EncoderBufferPool]],
}
if len(b.features.reqPayloadCurves) == 0 {
f.ReqSizeBytes = b.features.reqSizeBytes[curPos[stats.ReqSizeBytesIndex]]
Expand Down Expand Up @@ -804,6 +813,7 @@ func processFlags() *benchOpts {
sleepBetweenRPCs: append([]time.Duration(nil), *sleepBetweenRPCs...),
recvBufferPools: setRecvBufferPool(*recvBufferPool),
sharedWriteBuffer: setToggleMode(*sharedWriteBuffer),
encoderBufferPool: setToggleMode(*encoderBufferPool),
},
}

Expand Down
10 changes: 8 additions & 2 deletions benchmark/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (
SleepBetweenRPCs
RecvBufferPool
SharedWriteBuffer
EncoderBufferPool

// MaxFeatureIndex is a place holder to indicate the total number of feature
// indices we have. Any new feature indices should be added above this.
Expand Down Expand Up @@ -132,6 +133,8 @@ type Features struct {
RecvBufferPool string
// SharedWriteBuffer configures whether both client and server share per-connection write buffer
SharedWriteBuffer bool
// SharedWriteBuffer configures whether both client and server share encoder buffers
EncoderBufferPool bool
}

// String returns all the feature values as a string.
Expand All @@ -151,13 +154,14 @@ func (f Features) String() string {
"trace_%v-latency_%v-kbps_%v-MTU_%v-maxConcurrentCalls_%v-%s-%s-"+
"compressor_%v-channelz_%v-preloader_%v-clientReadBufferSize_%v-"+
"clientWriteBufferSize_%v-serverReadBufferSize_%v-serverWriteBufferSize_%v-"+
"sleepBetweenRPCs_%v-connections_%v-recvBufferPool_%v-sharedWriteBuffer_%v",
"sleepBetweenRPCs_%v-connections_%v-recvBufferPool_%v-sharedWriteBuffer_%v-"+
"encoderBufferPool_%v",
f.NetworkMode, f.UseBufConn, f.EnableKeepalive, f.BenchTime, f.EnableTrace,
f.Latency, f.Kbps, f.MTU, f.MaxConcurrentCalls, reqPayloadString,
respPayloadString, f.ModeCompressor, f.EnableChannelz, f.EnablePreloader,
f.ClientReadBufferSize, f.ClientWriteBufferSize, f.ServerReadBufferSize,
f.ServerWriteBufferSize, f.SleepBetweenRPCs, f.Connections,
f.RecvBufferPool, f.SharedWriteBuffer)
f.RecvBufferPool, f.SharedWriteBuffer, f.EncoderBufferPool)
}

// SharedFeatures returns the shared features as a pretty printable string.
Expand Down Expand Up @@ -235,6 +239,8 @@ func (f Features) partialString(b *bytes.Buffer, wantFeatures []bool, sep, delim
b.WriteString(fmt.Sprintf("RecvBufferPool%v%v%v", sep, f.RecvBufferPool, delim))
case SharedWriteBuffer:
b.WriteString(fmt.Sprintf("SharedWriteBuffer%v%v%v", sep, f.SharedWriteBuffer, delim))
case EncoderBufferPool:
b.WriteString(fmt.Sprintf("EncoderBufferPool%v%v%v", sep, f.EncoderBufferPool, delim))
default:
log.Fatalf("Unknown feature index %v. maxFeatureIndex is %v", i, MaxFeatureIndex)
}
Expand Down

0 comments on commit e1ae3c0

Please sign in to comment.