Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-365

Poor concurrency handling in DBApiLayer.doGetCollection

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.1
    • Fix Version/s: None
    • Component/s: Performance
    • Labels:
      None

      Description

      It seems that the synchronized block has been put in place in order to guarantee that a particular DBCollection is uniquely created and returned to the caller.

      The synchronization is needed because the operation as a whole must be atomic. However, it adds an extra lock/unlock beyond that provided by synchronizedMap on _collections, and this can significantly negatively affect performance in highly concurrent situations which call this essential function.

      One solution could be to not use synchronizedMap, and instead handle locking ourselves by always wrapping uses of _collections with synchronized blocks. This would reduce the number of blocking lock acquisitions.

      However, a much better solution is for _collection to be ConcurrentHashMap. We would then never have to use synchronized blocks, and in this case could check the result of a putIfAbsent call:

      MyCollection existing = _collections.putIfAbsent(name , c);
      if (existing != null) c = existing;

      This code would guarantee uniqueness of the collection, and offer much better throughput in high concurrency.

        Attachments

          Activity

            People

            Assignee:
            antoine Antoine Girbal
            Reporter:
            tal.liron Tal Liron
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: