[ https://issues.apache.org/jira/browse/KAFKA-6722?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
wade wu updated KAFKA-6722: --------------------------- External issue URL: https://cwiki.apache.org/confluence/display/KAFKA/KIP-NEXT%3A+Get+rid+of+unnecessary+read+lock > SensorAccess.getOrCreate should be more efficient > ------------------------------------------------- > > Key: KAFKA-6722 > URL: https://issues.apache.org/jira/browse/KAFKA-6722 > Project: Kafka > Issue Type: Improvement > Reporter: wade wu > Priority: Major > > In this source code: > [https://github.com/Microsoft/kafka/blob/azpubsub-release-0-10-2/core/src/main/scala/kafka/server/SensorAccess.scala] > The lock/unlock of read lock in getOrCreate() is not necessary, or it should > be refactored. For each request from Producer, this read lock lock/unlock is > called and lock/unlock, it is costing the time. > By using a temp variable, we can completely get rid of the read lock. > var sensor: Sensor = metrics.getSensor(sensorName) > if (sensor == null) { > lock.writeLock().lock() > try > { var temp = new sensor(); tmp.add(metrics); sensor = temp; } > catch() > {...} > > lock.writelock.unlock(); > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)