Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Make a Histogram of numbers

$
0
0
I am trying to measure the performance of our service by putting the data in a HashMap like-
`X` number of calls came back in `Y` ms. Below is my code which is very simple. It will set the timer before hitting the service and after the response came back, it will measure the time.

	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);
		}
	}



Currently the output I am getting is something like this-

    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

which means is `1 call came back in 166 ms`, `2 calls came back in 40 ms` and same with other outputs.



**Problem Statement:-**

What I am looking for now is something like this. I should have range setup like this-

    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



And any way to configure the range also. Suppose in future I need to tweak in the range, I should be able to do it. How can I achieve this thing in my current program? Any suggestions will be of great help.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>