@ijuma If I understand your comment correctly, you are talking about calling 
`RequestBuilder.build()` only once to address this issue without modifying the 
Request class itself. Here are my thoughts:

- Controller has separate request send threads talking to brokers and each of 
them contains a separate network client. Although we pass in the same request 
builder to each of the network clients, we cannot ensure that 
`RequestBuilder.build()` is called only once because we currently don't 
maintain states across these network clients. However, we can explicitly cache 
the request object in the RequestBuilder to avoid re-instantiation (this is 
what this PR did).
- Even if we can ensure `RequestBuilder.build()` is called only once and we use 
the same request object in the network clients, in the current implementation 
we will still create multiple Struct objects each time we serialize the request 
when network clients are trying to send out the request. To avoid that, this PR 
caches the Struct object and re-uses it when `toStruct()` is called.

Although this is a general optimization for all types of request, this PR only 
changes `UpdateMetadataRequest` instead of `AbstractRequest` because 
`UpdateMetadataRequest` is the only use case where we send out requests with 
the same payload for multiple times.

[ Full content available at: https://github.com/apache/kafka/pull/5519 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to