Uploaded image for project: 'Hibernate ORM'
  1. HHH-10924

Replace ConcurrentServiceBinding by ConcurrentHashMap

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.1
    • Fix Version/s: 5.2.2
    • Component/s: hibernate-core
    • Labels:
      None

      Description

      While looking through the source code of Hibernate I found the class ConcurrentServiceBinding. My first thought was: cool idea, maybe I can use something similar too. And the second thought was: is it really faster than IdentityHashMap or ConcurrentHashMap. To answer this question I have created small JMH tests. Here are the results from the execution of this tests on Intel Core i7 2 GHz:

      # JMH 1.12 (released 78 days ago)
      # VM version: JDK 1.8.0_92, VM 25.92-b14
      # VM options: <none>
      # Warmup: 10 iterations, 3 s each
      # Measurement: 10 iterations, 3 s each
      # Timeout: 10 min per iteration
      # Threads: 1 thread, will synchronize iterations
      # Benchmark mode: Average time, time/op
      
      Benchmark                                                                               Mode  Cnt   Score   Error  Units
      ConcurrentServiceBindingBenchmark.baseConcurrentServiceBindingGetEventListenerRegistry  avgt  100  11.197 ± 0.534  ns/op
      ConcurrentServiceBindingBenchmark.baseConcurrentServiceBindingGetJdbcServices           avgt  100   8.126 ± 1.197  ns/op
      ConcurrentServiceBindingBenchmark.chmConcurrentServiceBindingGetEventListenerRegistry   avgt  100   6.594 ± 0.023  ns/op
      ConcurrentServiceBindingBenchmark.chmConcurrentServiceBindingGetJdbcServices            avgt  100   6.589 ± 0.025  ns/op
      ConcurrentServiceBindingBenchmark.ihmConcurrentServiceBindingGetEventListenerRegistry   avgt  100   6.206 ± 0.005  ns/op
      ConcurrentServiceBindingBenchmark.ihmConcurrentServiceBindingGetJdbcServices            avgt  100   6.325 ± 0.108  ns/op
      

      Same as above but with 10 threads:

      # Threads: 10 threads, will synchronize iterations
      
      Benchmark                                                                               Mode  Cnt   Score   Error  Units
      ConcurrentServiceBindingBenchmark.baseConcurrentServiceBindingGetEventListenerRegistry  avgt  100  27.125 ± 0.967  ns/op
      ConcurrentServiceBindingBenchmark.baseConcurrentServiceBindingGetJdbcServices           avgt  100  27.019 ± 2.590  ns/op
      ConcurrentServiceBindingBenchmark.chmConcurrentServiceBindingGetEventListenerRegistry   avgt  100  18.367 ± 0.507  ns/op
      ConcurrentServiceBindingBenchmark.chmConcurrentServiceBindingGetJdbcServices            avgt  100  17.919 ± 0.403  ns/op
      ConcurrentServiceBindingBenchmark.ihmConcurrentServiceBindingGetEventListenerRegistry   avgt  100  17.049 ± 0.315  ns/op
      ConcurrentServiceBindingBenchmark.ihmConcurrentServiceBindingGetJdbcServices            avgt  100  17.871 ± 0.520  ns/op
      

      baseConcurrentServiceBindingXXX uses the current implementation of ConcurrentServiceBinding in Hibernate. chmConcurrentServiceBindingXXX uses ConcurrentHashMap and ihmConcurrentServiceBinding uses IdentityHashMap.

      As you can see CHM based implementation is faster than the current implementation of ConcurrentServiceBinding. The IdentityHashMap based implementation is only slightly faster than the CHM based. Therefore I think it is not worth to maintain an extra class when CHM is good enough and suggest to replace ConcurrentServiceBinding by ConcurrentHashMap.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: