0

我正在尝试通过将数据放入 HashMap 中来衡量我们服务的性能,就像 在毫秒内X返回的调用数一样。Y下面是我的代码,非常简单。它将在点击服务之前设置计时器,在响应返回后,它将测量时间。

private static void serviceCall() {

    histogram = new HashMap<Long, Long>();
    keys = histogram.keySet();
    long total = 10;
    long runs = total;

    while (runs > 0) {

        long start_time = System.currentTimeMillis();

        // hitting the service      
        result = restTemplate
                .getForObject("Some URL",String.class);

        long difference = (System.currentTimeMillis() - start_time);

        Long count = histogram.get(difference);
        if (count != null) {
            count++;
            histogram.put(Long.valueOf(difference), count);
        } else {
            histogram.put(Long.valueOf(difference), Long.valueOf(1L));
        }
        runs--;
    }
    for (Long key : keys) {
        Long value = histogram.get(key);
        System.out.println("SERVICE MEASUREMENT, HG data, " + key + ":" + value);
    }
}

目前我得到的输出是这样的 -

SERVICE MEASUREMENT, HG data, 166:1
SERVICE MEASUREMENT, HG data, 40:2
SERVICE MEASUREMENT, HG data, 41:4
SERVICE MEASUREMENT, HG data, 42:1
SERVICE MEASUREMENT, HG data, 43:1
SERVICE MEASUREMENT, HG data, 44:1

这意味着 is 1 call came back in 166 ms2 calls came back in 40 ms并且与其他输出相同。

问题陈述:-

我现在正在寻找的是这样的东西。我应该有这样的范围设置-

X Number of calls came back in between 1 and 10 ms
Y Number of calls came back in between 11 and 20 ms
Z Number of calls came back in between 21 and 30 ms
P Number of calls came back in between 31 and 40 ms
T number of calls came back in between 41 and 50 ms

....
....

I number of calls came back in more than 100 ms

以及任何配置范围的方式。假设将来我需要调整范围,我应该能够做到。我怎样才能在我目前的程序中实现这个目标?任何建议都会有很大帮助。

4

1 回答 1

1

直方图是一组数据,它们排列成相同大小的“箱”。您应该将时间测量转换为 bin 并将该 bin 用作映射键。这可以简单地通过将您的时间值除以 bin 大小来完成。例如: time / 10L

于 2013-01-31T01:45:19.060 回答