Skip to content

KAFKA-9670: Reduce allocations in Metadata Response preparation#8236

Merged
hachikuji merged 5 commits intoapache:trunkfrom
omkreddy:inefficient-metadata-building
Mar 16, 2020
Merged

KAFKA-9670: Reduce allocations in Metadata Response preparation#8236
hachikuji merged 5 commits intoapache:trunkfrom
omkreddy:inefficient-metadata-building

Conversation

@omkreddy
Copy link
Copy Markdown
Contributor

@omkreddy omkreddy commented Mar 6, 2020

This PR removes intermediate conversions between MetadataResponse.TopicMetadata => MetadataResponseTopic and MetadataResponse.PartitionMetadata => MetadataResponsePartition objects.

There is 15-20% reduction in object allocations and 5-10% improvement in metadata request performance.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@omkreddy omkreddy requested a review from hachikuji March 6, 2020 07:46
@omkreddy
Copy link
Copy Markdown
Contributor Author

omkreddy commented Mar 6, 2020

Perf results of Benchmark tests:

Old:

Benchmark                                                                                  (partitionCount)  (topicCount)  Mode  Cnt          Score          Error   Units
MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 10           500  avgt   15    4624705.025 ?     9007.996   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             10           500  avgt   15    3362672.703 ?       91.643    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    10           500  avgt   15    3369676.296 ?    63257.016    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       10           500  avgt   15        122.845 ?       65.255    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 10          1000  avgt   15    9561436.199 ?   162385.071   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             10          1000  avgt   15    6694415.974 ?      943.364    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    10          1000  avgt   15    6696068.762 ?   114136.204    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       10          1000  avgt   15       5525.666 ?      486.544    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                10          1000  avgt   15      18700.743 ?     1227.726    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 10          5000  avgt   15   55282793.657 ?   492086.714   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             10          5000  avgt   15   34490318.693 ?      760.718    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    10          5000  avgt   15   32376293.714 ?   539579.934    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       10          5000  avgt   15    2997154.052 ?    49861.017    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                10          5000  avgt   15       3471.934 ?     3137.253    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 20           500  avgt   15    8166348.301 ?    27573.503   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             20           500  avgt   15    6008717.991 ?       92.078    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    20           500  avgt   15    6014864.777 ?   106423.046    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       20           500  avgt   15       4577.626 ?      274.662    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                20           500  avgt   15       8444.542 ?      466.830    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 20          1000  avgt   15   17671545.929 ?   196584.077   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             20          1000  avgt   15   12075198.184 ?    11901.600    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    20          1000  avgt   15   11242489.242 ?   172984.454    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       20          1000  avgt   15     995763.689 ?    15270.385    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                20          1000  avgt   15      18581.310 ?     9165.824    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 20          5000  avgt   15   96856796.596 ?   839257.112   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             20          5000  avgt   15   61430973.255 ?      882.268    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    20          5000  avgt   15   57283268.653 ?  3275729.863    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       20          5000  avgt   15    5175846.120 ?   295732.537    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                20          5000  avgt   15     208951.674 ?   205025.696    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 50           500  avgt   15   19512585.039 ?    63594.327   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             50           500  avgt   15   14042543.790 ?      164.341    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    50           500  avgt   15   12993631.341 ?   282662.936    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       50           500  avgt   15    2044144.074 ?    44330.975    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                50           500  avgt   15      23168.561 ?     2132.219    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 50          1000  avgt   15   40850062.480 ?   111136.984   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             50          1000  avgt   15   28176631.992 ?    12597.548    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    50          1000  avgt   15   26148578.561 ?   620777.575    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       50          1000  avgt   15    3054397.028 ?    72409.582    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                50          1000  avgt   15      13112.312 ?    12149.545    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 50          5000  avgt   15  207082085.641 ?  1578283.055   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             50          5000  avgt   15  142091811.101 ?      246.865    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    50          5000  avgt   15  131752831.361 ? 14336631.786    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       50          5000  avgt   15   11434129.734 ?  1260618.649    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                50          5000  avgt   15    1429100.902 ?   484830.174    B/op

New

Benchmark                                                                                  (partitionCount)  (topicCount)  Mode  Cnt          Score          Error   Units
MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 10           500  avgt   15    4472924.213 ?    13864.976   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             10           500  avgt   15    2838424.579 ?       91.691    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    10           500  avgt   15    2847247.530 ?    84345.034    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       10           500  avgt   15        605.012 ?      232.335    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                10           500  avgt   15        812.743 ?      297.499    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 10          1000  avgt   15    8881445.686 ?    75262.135   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             10          1000  avgt   15    5646684.102 ?       98.972    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    10          1000  avgt   15    5670663.012 ?   129820.047    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       10          1000  avgt   15       2025.593 ?      286.759    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                10          1000  avgt   15      12964.258 ?     2781.392    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 10          5000  avgt   15   52140958.479 ?   823626.991   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             10          5000  avgt   15   29250203.918 ?      658.319    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    10          5000  avgt   15   27132719.962 ?   862825.442    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       10          5000  avgt   15    3063940.313 ?    97310.632    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                10          5000  avgt   15     418476.058 ?    27026.062    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 20           500  avgt   15    7622827.298 ?    75181.071   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             20           500  avgt   15    4904797.355 ?       92.037    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    20           500  avgt   15    4919485.008 ?    79165.841    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       20           500  avgt   15        708.682 ?      190.625    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 20          1000  avgt   15   16399900.112 ?   143683.687   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             20          1000  avgt   15    9884636.091 ?    11281.442    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    20          1000  avgt   15    9051384.201 ?   180517.992    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       20          1000  avgt   15    1002241.208 ?    20927.836    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                20          1000  avgt   15      42838.379 ?    33872.489    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 20          5000  avgt   15   85957476.734 ?   502588.396   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             20          5000  avgt   15   50470802.258 ?      919.850    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    20          5000  avgt   15   46336908.482 ?   288988.315    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                20          5000  avgt   15       2395.155 ?     4395.403    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 50           500  avgt   15   17840614.572 ?   158426.205   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             50           500  avgt   15   11166304.427 ?      159.600    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    50           500  avgt   15   10113029.080 ?   212285.387    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       50           500  avgt   15    2045886.934 ?    43296.428    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                50           500  avgt   15      18822.120 ?     1982.940    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 50          1000  avgt   15   38308947.007 ?   297649.114   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             50          1000  avgt   15   22414627.923 ?      271.024    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    50          1000  avgt   15   20290835.197 ?   343253.900    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       50          1000  avgt   15    3062223.960 ?    51621.492    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                50          1000  avgt   15     240967.749 ?    22990.126    B/op

MetadataRequestBenchmark.testMetadataRequestForAllTopics                                                 50          5000  avgt   15  201697751.438 ?  3161982.664   ns/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.alloc.rate.norm                             50          5000  avgt   15  113331824.670 ?      245.842    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Eden_Space.norm                    50          5000  avgt   15  103802755.202 ? 14003309.806    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Old_Gen.norm                       50          5000  avgt   15   11554814.802 ?  1560388.833    B/op
MetadataRequestBenchmark.testMetadataRequestForAllTopics:?gc.churn.G1_Survivor_Space.norm                50          5000  avgt   15    2188386.084 ?   441436.149    B/op

@omkreddy omkreddy force-pushed the inefficient-metadata-building branch from 579344e to d846111 Compare March 6, 2020 08:30
Copy link
Copy Markdown
Member

@ijuma ijuma Mar 6, 2020

Choose a reason for hiding this comment

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

Should we remove MetadataResponse.TopicMetadata altogether or does it add value?

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 think, we can continue to use MetadataResponse.TopicMetadata in some of the internal classes and tests. But I open to update/remove the classes the code required.

Copy link
Copy Markdown
Contributor

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

@omkreddy This looks reasonable to me. I just had some small comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I'd suggest changing this to accept Errors so that we don't need all the annoying .code() calls.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: for ra bunch of these accessors, we can drop parenthesis.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: this looks misaligned

@omkreddy omkreddy force-pushed the inefficient-metadata-building branch 2 times, most recently from 7ea70b2 to 3777b18 Compare March 13, 2020 07:47
@omkreddy omkreddy force-pushed the inefficient-metadata-building branch from 3777b18 to ddd4825 Compare March 13, 2020 07:59
@omkreddy
Copy link
Copy Markdown
Contributor Author

@hachikuji Thanks for the review. Addressed the review comments.

Copy link
Copy Markdown
Contributor

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the patch!

@hachikuji hachikuji merged commit a0e1407 into apache:trunk Mar 16, 2020
ijuma added a commit to confluentinc/kafka that referenced this pull request Mar 17, 2020
* apache-github/trunk: (39 commits)
  MINOR: cleanup and add tests to StateDirectoryTest (apache#8304)
  HOTFIX: StateDirectoryTest should use Set instead of List (apache#8305)
  MINOR: Fix build and JavaDoc warnings (apache#8291)
  MINOR: Fix kafka.server.RequestQuotaTest missing new ApiKeys. (apache#8302)
  KAFKA-9712: Catch and handle exception thrown by reflections scanner (apache#8289)
  KAFKA-9670; Reduce allocations in Metadata Response preparation (apache#8236)
  MINOR: fix Scala 2.13 build error introduced in apache#8083 (apache#8301)
  MINOR: enforce non-negative invariant for checkpointed offsets (apache#8297)
  MINOR: comment apikey types in generated switch (apache#8201)
  MINOR: Fix typo in CreateTopicsResponse.json (apache#8300)
  KIP-546: Implement describeClientQuotas and alterClientQuotas. (apache#8083)
  KAFKA-6647: Do note delete the lock file while holding the lock (apache#8267)
  KAFKA-9677: Fix consumer fetch with small consume bandwidth quotas (apache#8290)
  KAFKA-9533: Fix JavaDocs of KStream.transformValues (apache#8298)
  MINOR: reuse pseudo-topic in FKJoin (apache#8296)
  KAFKA-6145: Pt 2. Include offset sums in subscription (apache#8246)
  KAFKA-9714; Eliminate unused reference to IBP in `TransactionStateManager` (apache#8293)
  KAFKA-9718; Don't log passwords for AlterConfigs in request logs (apache#8294)
  KAFKA-8768: DeleteRecords request/response automated protocol (apache#7957)
  KAFKA-9685: Solve Set concatenation perf issue in AclAuthorizer
  ...
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.

4 participants