Search in sources :

Example 1 with TableOperator

use of com.alibaba.druid.benckmark.pool.model.TableOperator in project druid by alibaba.

the class Case4 method p0.

private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(threadCount);
    final CountDownLatch dumpLatch = new CountDownLatch(1);
    Thread[] threads = new Thread[threadCount];
    final TableOperator operator = new TableOperator();
    operator.setDataSource(dataSource);
    operator.createTable();
    for (int i = 0; i < threadCount; ++i) {
        Thread thread = new Thread() {

            public void run() {
                try {
                    startLatch.await();
                    for (int i = 0; i < LOOP_COUNT; ++i) {
                        operator.insert();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                endLatch.countDown();
                try {
                    dumpLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        threads[i] = thread;
        thread.start();
    }
    long startMillis = System.currentTimeMillis();
    long startYGC = TestUtil.getYoungGC();
    long startFullGC = TestUtil.getFullGC();
    startLatch.countDown();
    endLatch.await();
    long[] threadIdArray = new long[threads.length];
    for (int i = 0; i < threads.length; ++i) {
        threadIdArray[i] = threads[i].getId();
    }
    ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray);
    dumpLatch.countDown();
    operator.dropTable();
    long blockedCount = 0;
    long waitedCount = 0;
    for (int i = 0; i < threadInfoArray.length; ++i) {
        ThreadInfo threadInfo = threadInfoArray[i];
        blockedCount += threadInfo.getBlockedCount();
        waitedCount += threadInfo.getWaitedCount();
    }
    long millis = System.currentTimeMillis() - startMillis;
    long ygc = TestUtil.getYoungGC() - startYGC;
    long fullGC = TestUtil.getFullGC() - startFullGC;
    System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC + " blocked " + //
    NumberFormat.getInstance().format(blockedCount) + " waited " + NumberFormat.getInstance().format(waitedCount));
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) TableOperator(com.alibaba.druid.benckmark.pool.model.TableOperator) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

TableOperator (com.alibaba.druid.benckmark.pool.model.TableOperator)1 ThreadInfo (java.lang.management.ThreadInfo)1 CountDownLatch (java.util.concurrent.CountDownLatch)1