peterxcli commented on PR #8360: URL: https://github.com/apache/ozone/pull/8360#issuecomment-2861651766
Updated result: <img width="991" alt="image" src="https://github.com/user-attachments/assets/21b6eb72-f292-4fee-a275-c36c05d9e461" /> <details> <summary>test script</summary> ```java 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 for (int i = 0; i < 5; i++) { setup(); testPolicyPerformance("CapacityVolumeChoosingPolicy", capacityPolicy); cleanUp(); setup(); testPolicyPerformance("RoundRobinVolumeChoosingPolicy", roundRobinPolicy); cleanUp(); } } 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); AtomicLong totalTimeNanos = new AtomicLong(0); // Submit NUM_THREADS tasks, each doing NUM_ITERATIONS volume choices for (int i = 0; i < NUM_THREADS; i++) { executor.submit(() -> { try { long threadStartTime = System.nanoTime(); 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(); } } long threadEndTime = System.nanoTime(); totalTimeNanos.addAndGet((threadEndTime - threadStartTime)); } 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 totalOperations = (long) NUM_THREADS * NUM_ITERATIONS; double avgTimePerOperation = (double) totalTimeNanos.get() / totalOperations; double operationsPerSecond = totalOperations / (totalTimeNanos.get() / 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", totalTimeNanos.get() / 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: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org