divijvaidya commented on PR #13078: URL: https://github.com/apache/kafka/pull/13078#issuecomment-1386788880
@ijuma @jolshan what I wanted to convey was a situation where the approximate nature of this metrics may cause problem during troubleshooting. **But I was wrong. I read the code incorrectly at one place and wrongly assumed that this map is updated frequently** Let me write it as a FAQ. **What is the situation that you are worried about?** When we have only one or two producers, the approximate nature of the metric may display the producerId to be 0 when actually it should be 1. Having one producer is a realistic production scenario since there are use cases for Kafka where folks use Kafka primarily for fan out, i.e. single producer but a large number of consumers. **Would the metric be inconsistent only during concurrent updates to `producers` map (and stable for rest of the time)?** Yes **What is the likelihood that the metric is captured by the gauge at the same time when the map is undergoing concurrent update?** Not likely (this is where I was wrong in my earlier comment). Note that producer IDs are *not* added frequently and the map is modified only during expiration or addition. Hence, the likelihood of metric display at the same time when map is being mutated is low. **Is the metric only going to be stale (reflecting a state after some time of it's occurrence) or is it going to be inaccurate (even after some time of state change it may reflect the wrong state)?** It can be inaccurate. This is because when modifications are being done on concurrent hash map, they are pointer manipulation and depending on the state the internal data structure the size may reflect an inaccurate value. I don't have any further concerns with using @clolov's proposal to use ConcurrentHashMap, in fact, that is the better approach here. Thanks all for clarifying my doubts and answering my questions. Appreciate it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org