You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/02/10 13:33:00 UTC

[GitHub] [ozone] sodonnel opened a new pull request #3071: HDDS-6292. Ensure immutable ContainerReplica set is returned from ContainerStateManagerImpl

sodonnel opened a new pull request #3071:
URL: https://github.com/apache/ozone/pull/3071


   ## What changes were proposed in this pull request?
   
   Inside ContainerStateMap, the replicas for a container are stored in a Set backed by a ConcurrentHashMap.
   
   When you ask for the current replicas of a container, this method is used:
   
   ```
   public Set<ContainerReplica> getContainerReplicas(
         final ContainerID containerID) {
       Preconditions.checkNotNull(containerID);
       final Set<ContainerReplica> replicas = replicaMap.get(containerID);
       return replicas == null ? null : Collections.unmodifiableSet(replicas);
   } 
   ```
   
   Note that it pulls out the Set, wraps it as unmodifiable and returns it.
   
   There is a problem here, in that if the Set is updated by ICR / FCR at the same time as another part of the code has taken a reference to it, the other part of the code can make incorrect decisions. Eg:
   
   ```
   Set<> replicas = getContainerReplicas(...)
   replicaCount = replicas.size()
   // continue to do something based on the size
   ```
   
   ReplicationManger has run into a race condition like this. We also use the Replicas to form pipelines for closed containers, so I worry there could be some strange issues if the set if mutated during the pipeline creation.
   
   I see two possible solutions here. `GetContainerReplicas` should create a copy of the Set and return that, so the copy the other part of the code gets is its own copy and nothing can change it.
   
   Or, we make the Set immutable, so that each new replica details are received, we create the new copy of the set and store that. Then any other parts of the code can get a reference to it, and know it will never change.
   
   Mutations to the replicas for a closed container will only happen with FCR, which is relatively rare.
   
   However we may ask for read pipelines very frequently, so it would be cheaper overall to use option 2.
   
   It we go with option 2, I think we can move from a concurrentHashMap to a plain hashMap too, which may make the memory footprint slightly smaller.
   
   Note access to the replicas is via ContainerStateManagerImpl, which already has a course RW lock protecting access to the container manager. Quite possibly FCR reporting could be improved by a finer grained or striped lock.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-6292
   
   ## How was this patch tested?
   
   Existing tests cover this area.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on pull request #3071: HDDS-6292. Ensure immutable ContainerReplica set is returned from ContainerStateManagerImpl

Posted by GitBox <gi...@apache.org>.
sodonnel commented on pull request #3071:
URL: https://github.com/apache/ozone/pull/3071#issuecomment-1039273006


   I benchmarked FullContainerReport handling for a 30k container report in #3085. To process the 30k containers in the report handler, takes about 2.5 seconds. So if this change can handle 3M new replicas per second, it is clearly not going to be the bottleneck in the container report processing. Therefore I am further convinced the performance of this change is not a concern.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on pull request #3071: HDDS-6292. Ensure immutable ContainerReplica set is returned from ContainerStateManagerImpl

Posted by GitBox <gi...@apache.org>.
sodonnel commented on pull request #3071:
URL: https://github.com/apache/ozone/pull/3071#issuecomment-1035111134


   Running a JMH benchmark of the old code and new code, updating a replica and then removing it, the old code is significantly faster, which is expected:
   
   ```
     @Benchmark
     @Threads(1)
     @Warmup(iterations = 8)
     @Fork(value = 1, warmups = 0)
     @Measurement(iterations = 8, time = 1)
     @BenchmarkMode(Mode.Throughput)
     public void testThroughput(Blackhole blackhole, BenchmarkState state) {
       state.stateMap.updateContainerReplica(state.containerID, state.replicaFour);
       state.stateMap.removeContainerReplica(state.containerID, state.replicaFour);
   }
   ```
   
   The original code:
   
   ```
   # JMH version: 1.19
   # VM version: JDK 1.8.0_191, VM 25.191-b12
   # VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/bin/java
   # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50055:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
   # Warmup: 8 iterations, 1 s each
   # Measurement: 8 iterations, 1 s each
   # Timeout: 10 min per iteration
   # Threads: 1 thread, will synchronize iterations
   # Benchmark mode: Throughput, ops/time
   # Benchmark: org.apache.hadoop.hdds.scm.container.states.TestContainerStateMap.testThroughput
   
   # Run progress: 0.00% complete, ETA 00:00:16
   # Fork: 1 of 1
   # Warmup Iteration   1: 10654846.120 ops/s
   # Warmup Iteration   2: 14203695.606 ops/s
   # Warmup Iteration   3: 14477058.760 ops/s
   # Warmup Iteration   4: 14862223.617 ops/s
   # Warmup Iteration   5: 15210005.038 ops/s
   # Warmup Iteration   6: 15311166.593 ops/s
   # Warmup Iteration   7: 15424823.884 ops/s
   # Warmup Iteration   8: 14333141.302 ops/s
   Iteration   1: 14818352.522 ops/s
   Iteration   2: 13990685.695 ops/s
   Iteration   3: 15023685.518 ops/s
   Iteration   4: 15339804.391 ops/s
   Iteration   5: 14484697.570 ops/s
   Iteration   6: 14779324.214 ops/s
   Iteration   7: 15191010.527 ops/s
   Iteration   8: 14782146.253 ops/s
   
   
   Result "org.apache.hadoop.hdds.scm.container.states.TestContainerStateMap.testThroughput":
     14801213.336 ±(99.9%) 807889.044 ops/s [Average]
     (min, avg, max) = (13990685.695, 14801213.336, 15339804.391), stdev = 422541.591
     CI (99.9%): [13993324.293, 15609102.380] (assumes normal distribution)
   
   
   # Run complete. Total time: 00:00:17
   
   Benchmark                              Mode  Cnt         Score        Error  Units
   TestContainerStateMap.testThroughput  thrpt    8  14801213.336 ± 807889.044  ops/s
   
   Process finished with exit code 0
   ```
   
   
   The new code:
   
   ```
   # Run progress: 0.00% complete, ETA 00:00:16
   # Fork: 1 of 1
   # Warmup Iteration   1: 1758424.107 ops/s
   # Warmup Iteration   2: 2250132.450 ops/s
   # Warmup Iteration   3: 2387809.016 ops/s
   # Warmup Iteration   4: 3191520.754 ops/s
   # Warmup Iteration   5: 3252523.875 ops/s
   # Warmup Iteration   6: 3235586.076 ops/s
   # Warmup Iteration   7: 3224184.559 ops/s
   # Warmup Iteration   8: 3222207.929 ops/s
   Iteration   1: 3228500.630 ops/s
   Iteration   2: 2510779.817 ops/s
   Iteration   3: 2911199.519 ops/s
   Iteration   4: 3146874.884 ops/s
   Iteration   5: 3176646.341 ops/s
   Iteration   6: 3161151.617 ops/s
   Iteration   7: 3054023.948 ops/s
   Iteration   8: 3176391.213 ops/s
   
   
   Result "org.apache.hadoop.hdds.scm.container.states.TestContainerStateMap.testThroughput":
     3045695.996 ±(99.9%) 454475.862 ops/s [Average]
     (min, avg, max) = (2510779.817, 3045695.996, 3228500.630), stdev = 237699.664
     CI (99.9%): [2591220.134, 3500171.858] (assumes normal distribution)
   
   
   # Run complete. Total time: 00:00:17
   
   Benchmark                              Mode  Cnt        Score        Error  Units
   TestContainerStateMap.testThroughput  thrpt    8  3045695.996 ± 454475.862  ops/s
   ```
   
   So this change takes it from about 15M ops per second (where an op is update and remove a replica) to about 3M ops per second. That is a reduction of 5x.
   
   The usual use case, of just updating a replica (ie not performing the remove), lifts the performance to about 6M ops/s on the new code vs 17.6M op/s on the old. Approx a 3x difference.
   
   The new code is more correct and avoids a need to lock to avoid the set of replicas getting mutated. The question is if this performance difference is really noticeable on full container reports?
   
   The alternative, is to make gets slower by creating a new Set and returning it each time the replicas are requested, however get is the more common operation, so the performance issue would be worse in aggregate there.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] kerneltime commented on pull request #3071: HDDS-6292. Ensure immutable ContainerReplica set is returned from ContainerStateManagerImpl

Posted by GitBox <gi...@apache.org>.
kerneltime commented on pull request #3071:
URL: https://github.com/apache/ozone/pull/3071#issuecomment-1035889174


   This change looks good to me, FCR are usually sent once an hour on a per DN basis and we can dedicate a thread to an FCR from a node, so the performance concerns should not block this change for now. 
   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel commented on pull request #3071: HDDS-6292. Ensure immutable ContainerReplica set is returned from ContainerStateManagerImpl

Posted by GitBox <gi...@apache.org>.
sodonnel commented on pull request #3071:
URL: https://github.com/apache/ozone/pull/3071#issuecomment-1039273006


   I benchmarked FullContainerReport handling for a 30k container report in #3085. To process the 30k containers in the report handler, takes about 2.5 seconds. So if this change can handle 3M new replicas per second, it is clearly not going to be the bottleneck in the container report processing. Therefore I am further convinced the performance of this change is not a concern.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] sodonnel merged pull request #3071: HDDS-6292. Ensure immutable ContainerReplica set is returned from ContainerStateManagerImpl

Posted by GitBox <gi...@apache.org>.
sodonnel merged pull request #3071:
URL: https://github.com/apache/ozone/pull/3071


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org