KAFKA-2073: migrate to client-side topic metadata request/response#988
KAFKA-2073: migrate to client-side topic metadata request/response#988hachikuji wants to merge 15 commits into
Conversation
|
cc @granthenke Lots of cleanup needed to make this possible, but hopefully not too controversial. I tried to decouple the Cluster object from the MetadataResponse so that it was more of a "pure" response object and not too tied to client-side logic. Other than that, the main work was in MetadataCache and KafkaApis as would be expected. |
|
@hachikuji Overall I really like all the cleanup and decoupling. I just have a concern about compatibility. Its not likely to affect most users, but we may still want to be sure we maintain the old constructors, etc. |
There was a problem hiding this comment.
Just noting here for documentation sake that I think a decent amount of change could be done in the metadata cache still. But this can be handled as part of KAFKA-2969. Things like:
- eliminate the use of
PartitionStateInfoin the cache - eliminate the "bridge" method
partitionStateToPartitionStateInfo - optimally build the data at update time so 'get' requests aren't as heavy
- add some unit tests
There was a problem hiding this comment.
One thing that's not clear to me is whether we actually should use the request/response objects deep in the server code. Part of the problem is just that it's annoying to do the java/scala adapting all over the place, but you also have to carry around response errors, which leads to weird cases where you're not sure if you need to check the error or not. I was actually debating whether we should leave around some of the case classes (e.g. TopicMetadata) and just remove the serde functions. Then we could leave adapting to the request handling layer. That would leave optimizations such as building the response objects in cache off the table though.
There was a problem hiding this comment.
@hachikuji Agreed. I think its important to decouple the request/response from the internals. I think ideally KafkaApis would handle the translation once, and then everything "deeper' would work with server side objects. A good discussion for those "refactoring" jiras.
There was a problem hiding this comment.
I'm a bit surprised that we call apply on cache here. If we want to fail when this is called on a non-existent topic, it would be nicer to throw a more informative message than a generic NoSuchElementException.
There was a problem hiding this comment.
This code used to be nested in getTopicMetadata function and followed an explicit contains check. As a separate (albeit private) method, it might make more sense to make it safer by returning Option. I don't have a strong preference either way.
There was a problem hiding this comment.
That makes sense. We could also return an empty collection if the item is not in the cache. I don't feel strongly either. :)
|
@ijuma @granthenke I added some unit tests for MetadataCache and tried to address Ismael's comments. |
There was a problem hiding this comment.
Nice refactoring. One minor improvement that you can do is to do the toSeq before the flatMap instead of after. That way you avoid adding everything to a Set (which checks for duplicates and is more expensive).
There was a problem hiding this comment.
Btw, sorry for these scattered comments. I'll hopefully do a complete review on Monday, so feel free to leave as is for now.
|
LGTM, cc @gwenshap (on top of reducing tech debt, this also improves efficiency of |
|
Thanks for the ping. Its pretty large, so I'll need few hours to review it. I'll try to fit this in this week. |
|
Thanks. :) |
|
LGTM. Thanks for all the work on this @hachikuji and the additional tests! FYI: This needs to get in before I can update the Metadata response for KIP-4/KIP-36. We are really close to migrating all of the Requests/Responses under the KAFKA-1927 umbrella. |
|
@ijuma @granthenke Thanks for the reviews! @gwenshap I'm adding one more commit to remove the readFrom method as discussed above. |
|
Some testing from @fpj revealed a noticeable performance regression in the |
|
@fpj Thanks for the testing! @hachikuji If we are back to pre-patch levels. I suggest we tackle that as a follow up. I created KAFKA-2969 to track that sort of work. |
|
@granthenke Sounds good to me. |
|
@hachikuji, can you please share the details of the benchmark and the results (maybe in a gist)? |
|
@ijuma Yes, happy to. I'll post it in the morning. I was actually hoping you could share some insight into the difference. Intuitively, the change above avoids a second pass over the broker collection, but in my tests, the replica/isr sets only ever had exactly two elements, so I wouldn't have guessed it would make much difference. |
| def addOrUpdatePartitionInfo(topic: String, | ||
| private def addOrUpdatePartitionInfo(topic: String, | ||
| partitionId: Int, | ||
| stateInfo: PartitionStateInfo) { |
There was a problem hiding this comment.
This is no longer aligned after the last commit (I don't like this formatting approach because of this, but it is the Kafka way).
|
@hachikuji I tested with your latest changes and the latency is indeed half of what it was previously, so performance-wise this looks good. For completeness, here is what I tested precisely. I have measured the latency of processing |
|
Good to know @fpj, thanks for checking. |
|
@ijuma For the record, here's a gist of the benchmark I used: https://gist.github.com/hachikuji/7a3b1df8a19d7f6e8dd0. I varied the parameters a bit to see what difference they made, but generally I saw results looking like this: Before fix: After fix: @fpj Thanks for confirming! |
|
Thanks @hachikuji. I had a look at this and I updated the benchmark a little: https://gist.github.com/ijuma/da362d00ae45cf477e7e Data points of interest: val numTopics = 100
val numPartitions = 1000 // per topic
val numBrokers = 10
val querySize = 100Compiled with Scala 2.11.8, executed with JDK 8 update 76: I tweaked things a little and got it down to less than half the time: A couple of observations:
Pull request is here: Tests passed locally. |
KAFKA-2073: Performance improvements
|
Pulled in @ijuma's optimizations. |
|
LGTM. Actually, looks great. I love the metadata cache refactoring and the response-object refactoring. |
|
Yeah this is a great patch. Thanks @hachikuji! (and others for review, perf tests, etc) |
No description provided.