ConcurrentTest并发测试框架介绍

[b]ConcurrentTest
 [/b]
Sourceforge Link: [url=https://sourceforge.net/projects/concurrenttest/]ConcurrentTest[/url], 0.9.1

[b]1. Description[/b]
- A java concurrent test library.
* It provides some base class which can simplify perfermance test for concurrent and multi-core program.
* Write code easily, and detailed CSV report is generated automatically.
* Most accurate result of multi-core program.

[b]2. Design[/b]

This framework provides several classes to use.

[img]http://dl.iteye.com/upload/attachment/275936/b9fb474e-17e8-3c89-b60f-0955a309677b.jpg[/img]


[b] Framework Class Description [/b]
[b]1 AbstractRunner[/b] -
A abstract super class. You can write test class extends it.
[b]2 RunnerFactory[/b] -
A abstract factory. You can extend it and override newRunner() method to create multi threads test runner.
[b]3 ConcurrentTestMeter[/b]
A test meter. You cant use ConcurrentTestMeter.createMeter( poolSize, runnerFactory) to create a meter.
You can use concurrentTestMeter.runTest( n,count) to run the test.
[b]4 ConcurrentTestReport[/b] -
The concurrent test report. It is created by ConcurrentTestMeter.
It can output CSV format report. You can edit it with Microsoft Excel easily.

[b]3. Demo: [/b]

Java Relection Performance Test
(see org.bamboo.concurrenttest.demo.MethodInvokeTest for detailed)

Here is a sample to test java reflection under multi-core,multi thread senario.
1) Write code you want to test.
2) Use ConcurrentTestMeter class to run your test.
3) Write main() method.
4) Performance Test Report.


1) Write code you want to test.
Write a JavaReflectRunner class which extends from AbstractRunner class.
Override doWork(int) method to write logic you want to test,e.g. method.invoke(...)



package org.bamboo.concurrenttest.demo;

import java.lang.reflect.Method;

public class JavaReflectRunner extends AbstractRunner {

private static Method method ;

static {
try {
method = Foo.class.getMethod("sayHello", new Class<?>[]{ String.class });
} catch (Exception e) { }
}

public void doWork(int i) {
try {
Foo foo = new Foo();
method.invoke(foo, new Object[]{"ABCD" + i});
} catch (Exception e) {
e.printStackTrace();
}
}
}



2) Use ConcurrentTestMeter class to run your test. Provide a subclass of RunnerFactory which is in charge of create new JavaReflectRunner you just wrote.

 public class MethodInvokeTest {

public static final int _threadPoolSize = 4;

public static void testJavaReflect(int poolSize,int threads ,int runTimes) {
ConcurrentTestMeter concurrentTestMeter = ConcurrentTestMeter.createMeter( poolSize, new RunnerFactory() {


public Runner newRunner() {
return new JavaReflectRunner();
}


public String getTestName() {
return "JavaReflectRunner";
}
});

ConcurrentTestReport report = concurrentTestMeter.runTest( threads,runTimes);
System.out.printf("%s \r\n" ,report.toCsvFormat());
}


3) Write main() method.
In main() method,you can provide thread pool size, concurrent count of threads and execution times per thread (i.e. run times).
On the whole,ConcurrentTestMeter class gives a full simulation of multi-thread enviroment.

You can specify thread pool size, concurrent theads, execute times as you need.

 

  public static void main(String[] args) {
int poolSize = 4;
int concurrents = 200;
int countPerThread = 10000;

System.out.printf(ConcurrentTestReport.getHeader() +"\r\n");

testJavaReflect(poolSize,concurrents, countPerThread);

testCglibReflect(poolSize,concurrents,countPerThread);

System.out.println("\r\nMain exit...");
}



4) Performance Test Report.

Run main() method. You may get test result on the console. The output format is csv,so you can open it using Micorsof Excel and anylyze,make graph easily.

Test Result on console is below. The first line is column header, the sencond line is result. Maybe TPS index is what you want.


[quote]Type,threadPoolSize ,Concurrency(threads),countPerThread, totalTime(ns),avgTime(ns),TPS:(times/s)
DirectMethodInvokeRunner,4,200,10000,863529862,431,2316
JavaReflectRunner,4,200,10000,1124753844,562,1778
CglibReflectRunner,4,200,10000,918106911,459,2178 [/quote]
 
You can view it in Excel or make comaprison Graph.

[img]http://dl.iteye.com/upload/attachment/275934/81135649-8cc2-396e-a315-e1f238c3d8ce.jpg[/img]

[img]http://dl.iteye.com/upload/attachment/275932/fef13347-e6a9-3e16-abac-787716006041.jpg[/img]


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值