`
raymond2006k
  • 浏览: 295149 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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.



引用
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

 
  You can view it in Excel or make comaprison Graph.






 
  • 大小: 19.8 KB
  • 大小: 28.1 KB
  • 大小: 71.5 KB
分享到:
评论
6 楼 amigo 2010-07-21  
raymond2006k 写道
billgui 写道
Thanks for sharing.  Do you have an estimation on how many threads maximum one machine can handle?  I see 200 in your sample data, not sure if this is an average data or?



Sorry, the parameter 200 of threads is just a test case to test concurrent performance of the code in doWork(int) method.

You can write a loop to use threads from 10 to 10000 step by double. e.g.

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..
5 楼 numen_wlm 2010-07-13  
装,装,装,使劲儿装。
4 楼 raymond2006k 2010-07-12  
billgui 写道
Thanks for sharing.  Do you have an estimation on how many threads maximum one machine can handle?  I see 200 in your sample data, not sure if this is an average data or?


You can also tuning the pool size in a loop the check the best parameter value on the machine , e.g. on a 8-core Xeon server.
3 楼 raymond2006k 2010-07-12  
billgui 写道
Thanks for sharing.  Do you have an estimation on how many threads maximum one machine can handle?  I see 200 in your sample data, not sure if this is an average data or?



Sorry, the parameter 200 of threads is just a test case to test concurrent performance of the code in doWork(int) method.

You can write a loop to use threads from 10 to 10000 step by double. e.g.

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.
2 楼 xiaoyuqi00 2010-07-12  
Can you speak chinese?
1 楼 billgui 2010-07-12  
Thanks for sharing.  Do you have an estimation on how many threads maximum one machine can handle?  I see 200 in your sample data, not sure if this is an average data or?

相关推荐

Global site tag (gtag.js) - Google Analytics