backend-tech-forge / benchmark

A enterprise level performance testing solution. Taking inspiration from nGrinder, this project aims to develop a Spring Boot application mirroring nGrinder's functionality as closely as feasible.
MIT License
4 stars 0 forks source link

ConcurrentHashMap stream sorted 시 멈춤현상 #57

Closed ghkdqhrbals closed 6 months ago

ghkdqhrbals commented 6 months ago

해당 메소드에서 다음 단계로 진행이 불가능했습니다.

@Slf4j
@Getter
public class HttpSender {
   private ConcurrentHashMap<LocalDateTime, Double> tpsMap = new ConcurrentHashMap<>();
    /**
     * Calculate percentile for TPS (Transactions Per Second)
     *
     * @param percentile The percentile to calculate (e.g., 90 for 90th percentile)
     * @return The calculated percentile value
     */
    public double calculateTpsPercentile(double percentile) {
        log.info("in calculate");
        List<Double> tpsValues = tpsMap.values().stream().sorted().toList();
        log.info(tpsValues.toString());
        int index = (int) Math.ceil((percentile / 100) * tpsValues.size()) - 1;
        return tpsValues.get(index);
    }
}
ghkdqhrbals commented 6 months ago

index 가 음수일 경우 예외처리

    public double calculateTpsPercentile(double percentile) {
        log.info("in calculate");
        Map<LocalDateTime, Double> tpsSnapshot = new ConcurrentHashMap<>(tpsMap);
        tpsSnapshot.values().stream().toList();
        List<Double> tpsValues = tpsSnapshot.values().stream().sorted().toList(); // <-- Here STOP!
        log.info(tpsValues.toString());
        int index = (int) Math.ceil((percentile / 100) * tpsValues.size()) - 1;
        if (index < 0) {
            return 0; // 예외처리: 인덱스가 음수인 경우
        }
        return tpsValues.get(index);
    }