我有一个Multithreaded program
会插入我的一个表格中,而我正在运行的程序 -
java -jar CannedTest.jar 100 10000
表示:
100
10000
因此每个线程都会在我的表中插入10000 records
。这意味着在程序执行完毕后表中的total count (100 * 10000)
应为1,000,000
。
我正在尝试测量插件作为LnP测试的一部分进入我的表的时间。我将所有这些数字存储在ConcurrentHashMap
中,例如插入数据库的时间如下所示。
long start = System.nanoTime();
callableStatement[pos].executeUpdate(); // flush the records.
long end = System.nanoTime() - start;
final AtomicLong before = insertHistogram.putIfAbsent(end / 1000000L, new AtomicLong(1L));
if (before != null) {
before.incrementAndGet();
}
当所有线程都完成了所有任务的执行后,我尝试通过ConcurrentHashMap insertHistogram
Key
对Milliseconds
中的数字进行排序,然后我得到结果如下 -
Milliseconds Number
0 2335
1 62488
2 60286
3 54967
4 52374
5 93034
6 123083
7 179355
8 118686
9 87126
10 42305
.. ..
.. ..
.. ..
而且,同样的ConcurrentHashMap insertHistogram
我试图制作如下的直方图。
17:46:06,112 INFO LoadTest:195 - Insert Histogram List:
17:46:06,112 INFO LoadTest:212 - 64823 came back between 1 and 2 ms
17:46:06,112 INFO LoadTest:212 - 115253 came back between 3 and 4 ms
17:46:06,112 INFO LoadTest:212 - 447846 came back between 5 and 8 ms
17:46:06,112 INFO LoadTest:212 - 330533 came back between 9 and 16 ms
17:46:06,112 INFO LoadTest:212 - 29188 came back between 17 and 32 ms
17:46:06,112 INFO LoadTest:212 - 6548 came back between 33 and 64 ms
17:46:06,112 INFO LoadTest:212 - 3821 came back between 65 and 128 ms
17:46:06,113 INFO LoadTest:212 - 1988 came back greater than 128 ms
注意: - 我正在尝试插入记录的数据库,目前处于Memory Only
模式。
问题陈述: -
在上面的结果中查看这个数字,然后通过在键上对其进行打印 -
0 2335
我不确定在2335 calls
中插入0 milliseconds
是怎么可能的?而且我在测量插入时也使用System.nanotime
。
下面是打印出上述日志的代码 -
private static void logHistogramInfo() {
int[] definition = { 0, 2, 4, 8, 16, 32, 64, 128 };
long[] buckets = new long[definition.length];
System.out.println("Milliseconds Number");
SortedSet<Long> keys = new TreeSet<Long>(Task.insertHistogram.keySet());
for (long key : keys) {
AtomicLong value = Task.insertHistogram.get(key);
System.out.println(key+ " " + value);
}
LOG.info("Insert Histogram List: ");
for (Long time : Task.insertHistogram.keySet()) {
for (int i = definition.length - 1; i >= 0; i--) {
if (time >= definition[i]) {
buckets[i] += Task.insertHistogram.get(time).get();
break;
}
}
}
for (int i = 0; i < definition.length; i++) {
String period = "";
if (i == definition.length - 1) {
period = "greater than " + definition[i] + " ms";
} else {
period = "between " + (definition[i] + 1) + " and " + definition[i + 1] + " ms";
}
LOG.info(buckets[i] + " came back " + period);
}
}
当我尝试通过在键上对其进行排序来直接打印Map中的值时,我不确定为什么会显示0
毫秒。
但是当我尝试将直方图设置为相同的0 milliseconds
时,相同的logHistogramInfo method
无法显示。
我在上述方法的计算过程中是否有任何错误?