Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-6722

SensorAccess.getOrCreate should be more efficient

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: metrics
    • Labels:
      None

      Description

      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();

       

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              wadewu wade wu
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: