作者:魑魅魍魉龌蹉尴尬 | 来源:互联网 | 2023-05-19 18:48
Iamtryingtomeasurehowmuchtimeeachthreadtakesininsertingtodatabase.Ihavecapturedall
I am trying to measure how much time each thread takes in inserting to database. I have captured all those performance numbers in a ConcurrentHashMap
named map like how much time each thread is taking in inserting. In that concurrent hash map it will be something like this.
我试图测量每个线程插入数据库所花费的时间。我已经在ConcurrentHashMap命名映射中捕获了所有这些性能数字,比如每个线程插入的时间。在那个并发哈希映射中,它将是这样的。
Key- 10
Value- 2
So that means, 2 Calls came back in 10 ms. Another example below
这意味着,2个呼叫在10毫秒内恢复。另一个例子如下
Key - 20
Value -1
which means, 1 Call came back in 20 ms.
这意味着,1个电话在20毫秒内回来了。
And that map will contain lot more data means lot more key value pair.
而且该地图将包含更多的数据意味着更多的关键值对。
So now I am trying to do something like below by using the same map above, that means I need to iterate the above map to get the below numbers in that particular range. Is that possible to do?
所以现在我尝试通过使用上面的相同地图来做类似下面的事情,这意味着我需要迭代上面的地图以获得该特定范围内的以下数字。这可能吗?
How many calls(X number) came back in between 1 and 20 ms
How many calls(X number) came back in between 20 and 40 ms
How many calls(X number) came back in between 40 and 60 ms
How many calls(X number) came back in between 60 and 80 ms
How many calls(X number) came back in between 80 and 100 ms
How many calls(X number) came back after 100 ms
Some code that I thought of initially.
我最初想到的一些代码。
SortedSet keys = new TreeSet(map.keySet());
for (Long key : keys) {
System.out.print(key + " : ");
for (int i = 0; i
Can anyone help me here?
有人能帮我一下吗?
Update:-
My map sample value-
我的地图样本值 -
{31=3, 48=1, 33=1, 30=12, 43=1, 38=1, 32=1}
It means total call was 3+1+1+12+1+1+1 = 20
by adding value
from the map
这意味着通过从地图添加值,总呼叫为3 + 1 + 1 + 12 + 1 + 1 + 1 = 20
And out of that I need to figure out the above scenario means something like this
除此之外,我需要弄清楚上面的情况意味着这样的事情
How many calls(X number) came back in between 1 and 20 ms
How many calls(X number) came back in between 20 and 40 ms
How many calls(X number) came back in between 40 and 60 ms
How many calls(X number) came back in between 60 and 80 ms
How many calls(X number) came back in between 80 and 100 ms
How many calls(X number) came back after 100 ms
Below is my code that I have tried with the below suggestion-
以下是我用以下建议尝试过的代码 -
private static void drawHistogram(Map map) {
private static void drawHistogram(Map map){
int counter[] = new int[6];
for (Integer key : map.keySet()) {
System.out.println("" + key);
// add sample
int idx = key / 20;
idx = Math.min(idx, counter.length - 1);
counter[idx]++;
}
for (int i = 0; i
}
As you can see, I have 20 calls made but this is showing only 7 calls. Anything wrong I did? This is the output I got-
如你所见,我有20个电话,但这只显示7个电话。我做错了什么?这是我得到的输出 -
0 came back in between 0 and 20 ms
5 came back in between 20 and 40 ms
2 came back in between 40 and 60 ms
0 came back in between 60 and 80 ms
0 came back in between 80 and 100 ms
0 came back in between 100 and 120 ms
which shows only 7 calls. But there are 20 calls.
它只显示7个电话。但是有20个电话。
5 个解决方案