我有一个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);
}
}
我不确定为什么0
当我尝试通过在键上排序直接从 Map 打印值时显示毫秒。
但是0 milliseconds
当我尝试将直方图制作成相同的logHistogramInfo method
.
我在上述方法的计算过程中做错了什么吗?