-
Notifications
You must be signed in to change notification settings - Fork 14.8k
improve kafka client sensor registration performance by lazily calculating JMX attributes #5011
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
MBeanInfo class does not access field values like attributes because arrayGetSafe will be false for subclasses.
|
LGTM. It should be a safe optimization. @hachikuji do you think this patch is OK? Thanks! |
|
This caused a regression as it broke serialization #5114 |
|
@ijuma I am sorry for the problem caused by this. And thanks much for noticing this. I missed the serialization issue when thinking about the safty of this patch. If I remember correctly, at most one seemingly-unrelated test for one scala version failed for this test before this PR is merged. So it seems that the existing Kafka code does not attempt to serialize the MBeanInfo returned by In order to prevent for this in the future, I will write a unit test for this issue after understanding where it caused the problem. |
|
@lindong28 Yes, I agree that our testing is lacking here and thanks for offering to improve that. The serialization happens automatically when other processes read JMX metrics via RMI. Some Confluent system tests failed as well as some internal deployments that rely on JMX metrics. I'm not sure why Kafka system tests didn't fail. There were a couple of failures in the last build, but I don't know if they are related: |
|
@ijuma Yeah it is not clear whether these tests are related. It will be easier for us to debug those tests now that we have reverted this patch. We will need test for this patch later. |
…ributes (#5114) This reverts commit c9ec292 (#5011). That commit introduces an anonymous inner class which retains a reference to the non-serializable outer class `KafkaMbean` breaking Serialization. This means that reading JMX metrics via JConsole or JmxTool no longer works since RMI relies on Java Serialization. Reviewers: Jason Gustafson <jason@confluent.io>, Dong Lin <lindong28@gmail.com>, Ismael Juma <ismael@juma.me.uk>
|
@ijuma After digging into the root cause of this performance issue, I find that in https://issues.apache.org/jira/browse/KAFKA-4381 we introduced per-partition metrics where we put the topic partition in the metric name instead of the tags. This introduces mbean whose number of attributes is proportional to the number of topic partition of the consumer. This can significantly reduce the MM startup time (see #5011) because consumer needs to create O(n^2) number of objects for metrics during initialization, where n is the number of topic partition assigned to the consumer. Fortunately, KIP-225 (https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74686649) has deprecated these metrics and moved the topic partition information to the tags of the new metrics. Thus we already have a long term fix for this issue. Radai has a solution to override the mbean class here but it requires non-trivial trivial. Since we already have a long term solution for the issue, we probably want to keep the code base as simple as possible. I also have two other ideas for hot fixing the issue, i.e. use time-based or counter-based way to just return empty list of attribute when |
|
i fixed the jmx and serialization issues (with the help of SO). we will probably end up using this internally. as @lindong28 has removed the offending sensors, and KIP-225 would probably end up trading tens of thousands of attributes for tens of thousands of MBeans, i'll leave the decision on whether or not to merge this up to you. |
|
Do you have performance numbers before and after with this change post KIP-225? |
|
i dont. i'll try running my original workload with vanilla 1.1.0 next week (jira says kip-225 landed in 1.1.0, right?) |
|
Note that KIP-225 does not immediately address the performance issue. It deprecates the problematic metrics. We need to additionally remove the problematic metrics (see #5172) before checking whether this PR improves performance. |
|
true, so i'll need to run against trunk. |
…ating JMX attributes When any metric (e.g. per-partition metric) is created or deleted, registerMBean() is called which in turn calls getMBeanInfo().getClassName(). However, KafkaMbean.getMBeanInfo() instantiates an array of all sensors even though we only need the class name. This costs a lot of CPU to register sensors when consumer with large partition assignment starts. For example, it takes 5 minutes to start a consumer with 35k partitions. This patch reduces the consumer startup time seconds. Author: radai-rosenblatt <radai.rosenblatt@gmail.com> Reviewers: Satish Duggana <satish.duggana@gmail.com>, Dong Lin <lindong28@gmail.com> Closes apache#5011 from radai-rosenblatt/fun-with-jmx
…ributes (apache#5114) This reverts commit c9ec292 (apache#5011). That commit introduces an anonymous inner class which retains a reference to the non-serializable outer class `KafkaMbean` breaking Serialization. This means that reading JMX metrics via JConsole or JmxTool no longer works since RMI relies on Java Serialization. Reviewers: Jason Gustafson <jason@confluent.io>, Dong Lin <lindong28@gmail.com>, Ismael Juma <ismael@juma.me.uk>
|
closing this as after removing the old metrics this is (likely) not required |
kafka re-registers its sensor MBean on any sensor change (addition/removal of sensors).
kafka also has per-topic-partition sensors, and the mbean attribute array size is a multiple of those.
on large assignment sets (~35K topic partitions assigned to a single consumer), we've seen sensor registration code take 5 entire consecutive minutes (!!) of CPU time.
the offending code path is in (re)registering the MBean, which triggers this code (called by
DefaultMBeanServerInterceptor.registerMBean())this triggers the creation of the (big) attribute array, while the caller really only wants the mbean name.
this patch delays the array creation to the time when the mbean attributes are actually queried - which may be never (in case no one is even looking at the jmx sensors).
in local testing this removes a ~5 minute delay in rebalancing/assigning large groups of topic partitions.