peterxcli commented on PR #8360:
URL: https://github.com/apache/ozone/pull/8360#issuecomment-2858715135

   > For example, assume a DN has 10 volumes configuration, and 100 concurrent 
threads to try to create a container, what will be the total/average latency 
before and after the patch?
   
   @ChenSammi 
   
![image](https://github.com/user-attachments/assets/1d7a7da2-088e-481d-84d6-6bc2e6c57989)
   
   <details>
     <summary>test script</summary>
   
   ```java
   /**
    * Performance tests for VolumeChoosingPolicy implementations.
    */
   public class TestVolumeChoosingPolicyPerformance {
     private static final Logger LOG = 
LoggerFactory.getLogger(TestVolumeChoosingPolicyPerformance.class);
     private static final OzoneConfiguration CONF = new OzoneConfiguration();
     private static final int NUM_VOLUMES = 10;
     private static final int NUM_THREADS = 100;
     private static final int NUM_ITERATIONS = 1000;
     private static final long CONTAINER_SIZE = 1;
   
     @TempDir
     private Path baseDir;
   
     private List<HddsVolume> volumes;
     private CapacityVolumeChoosingPolicy capacityPolicy;
     private RoundRobinVolumeChoosingPolicy roundRobinPolicy;
   
     @BeforeEach
     public void setup() throws Exception {
       volumes = new ArrayList<>();
       capacityPolicy = new CapacityVolumeChoosingPolicy();
       roundRobinPolicy = new RoundRobinVolumeChoosingPolicy();
   
       // Create NUM_VOLUMES volumes with different available space
       for (int i = 0; i < NUM_VOLUMES; i++) {
         String volumePath = baseDir + "/disk" + i;
         // Each volume has 1000 bytes capacity and different available space
         SpaceUsageSource source = MockSpaceUsageSource.fixed(1000000000, 
1000000000 - i * 50);
         SpaceUsageCheckFactory factory = MockSpaceUsageCheckFactory.of(
             source, Duration.ZERO, SpaceUsagePersistence.None.INSTANCE);
         HddsVolume volume = new HddsVolume.Builder(volumePath)
             .conf(CONF)
             .usageCheckFactory(factory)
             .build();
         volumes.add(volume);
       }
     }
   
     @AfterEach
     public void cleanUp() {
       volumes.forEach(HddsVolume::shutdown);
     }
   
     @Test
     public void testConcurrentVolumeChoosing() throws Exception {
       // Test both policies
       testPolicyPerformance("CapacityVolumeChoosingPolicy", capacityPolicy);
       testPolicyPerformance("RoundRobinVolumeChoosingPolicy", 
roundRobinPolicy);
     }
   
     private void testPolicyPerformance(String policyName, VolumeChoosingPolicy 
policy) throws Exception {
       ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS);
       CountDownLatch latch = new CountDownLatch(NUM_THREADS);
       AtomicInteger successCount = new AtomicInteger(0);
       AtomicInteger failureCount = new AtomicInteger(0);
   
       long startTime = System.nanoTime();
   
       // Submit NUM_THREADS tasks, each doing NUM_ITERATIONS volume choices
       for (int i = 0; i < NUM_THREADS; i++) {
         executor.submit(() -> {
           try {
             for (int j = 0; j < NUM_ITERATIONS; j++) {
               try {
                 HddsVolume volume = policy.chooseVolume(volumes, 
CONTAINER_SIZE);
                 if (volume != null) {
                   successCount.incrementAndGet();
                 }
               } catch (Exception e) {
                 failureCount.incrementAndGet();
               }
             }
           } finally {
             latch.countDown();
           }
         });
       }
   
       // Wait for all tasks to complete
       assertTrue(latch.await(5, TimeUnit.MINUTES), "Test timed out");
       executor.shutdown();
       assertTrue(executor.awaitTermination(1, TimeUnit.MINUTES), "Executor did 
not terminate");
   
       long endTime = System.nanoTime();
       long totalTime = endTime - startTime;
       long totalOperations = (long) NUM_THREADS * NUM_ITERATIONS;
   
       // Calculate statistics
       double avgTimePerOperation = (double) totalTime / totalOperations;
       double operationsPerSecond = totalOperations / (totalTime / 
1_000_000_000.0);
   
       LOG.info("Performance results for {}:", policyName);
       LOG.info("Total operations: {}", totalOperations);
       LOG.info("Successful operations: {}", successCount.get());
       LOG.info("Failed operations: {}", failureCount.get());
       LOG.info("Total time: {} ms", totalTime / 1_000_000);
       LOG.info("Average time per operation: {} ns", avgTimePerOperation);
       LOG.info("Operations per second: {}", operationsPerSecond);
     }
   }
   ```
   
   </details>
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to