首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

ConcurrentTest并发测试框架引见

2012-10-15 
ConcurrentTest并发测试框架介绍ConcurrentTest Sourceforge Link:ConcurrentTest, 0.9.1 1. Description-

ConcurrentTest并发测试框架介绍
ConcurrentTest
 

Sourceforge Link:  ConcurrentTest, 0.9.1

1. Description
- 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.

2. Design

    This framework provides several classes to use.




  Framework Class Description
1 AbstractRunner -
   A abstract super class. You can write test class extends it.
2 RunnerFactory -
   A abstract factory. You can extend it and override newRunner() method to create multi threads test runner.
3 ConcurrentTestMeter
  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.
4  ConcurrentTestReport -
The concurrent test report. It is created by  ConcurrentTestMeter.
It can output CSV format report. You can edit it with Microsoft Excel easily.
   
3. Demo:

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.








 
public static void main(String[] args) { int concurrents= 10 ; System.out.printf(ConcurrentTestReport.getHeader() +"\r\n"); while( concurrents<10000) { testCglibReflect(poolSize,concurrents,countPerThread); concurrents = concurrents * 2; } System.out.println("\r\nMain exit..."); }
Then you will get a report which render then performance variation from threads 10 to 10000. And you can get the threads maximum on the machine from the curve.
public static void main(String[] args) { int concurrents= 10 ; System.out.printf(ConcurrentTestReport.getHeader() +"\r\n"); while( concurrents<10000) { testCglibReflect(poolSize,concurrents,countPerThread); concurrents = concurrents * 2; } System.out.println("\r\nMain exit..."); }
Then you will get a report which render then performance variation from threads 10 to 10000. And you can get the threads maximum on the machine from the curve.


why not shutdown threadpool? such as
executorService.shutdown()

It's to increase rapidly when repeated test..

热点排行