[ 
https://issues.apache.org/jira/browse/KAFKA-6722?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

wade wu updated KAFKA-6722:
---------------------------
    Description: 
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. 

The existing code is doing this in order to wait until the sensor 
initialization is finished, but this can be done when the sensor is created 
under the write lock, by having the thread sleep for a while (few 
milliseconds), and this time can be amortized, since sensor creating is a one 
time thing.

It can be easily fixed using code below, and it is still thread safe: 

 

var sensor: Sensor = metrics.getSensor(sensorName)

if (sensor == null) {

lock.writeLock().lock()

try{

........

  was:
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. It can be easily fixed using 
code below, and it is still thread safe: 

 

var sensor: Sensor = metrics.getSensor(sensorName)

if (sensor == null) {

lock.writeLock().lock()

try{

........


> 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
>
> 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. 
> The existing code is doing this in order to wait until the sensor 
> initialization is finished, but this can be done when the sensor is created 
> under the write lock, by having the thread sleep for a while (few 
> milliseconds), and this time can be amortized, since sensor creating is a one 
> time thing.
> It can be easily fixed using code below, and it is still thread safe: 
>  
> var sensor: Sensor = metrics.getSensor(sensorName)
> if (sensor == null) {
> lock.writeLock().lock()
> try{
> ........



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to