Download Latest Version concurrenttest-0.9.0.jar (7.1 kB)
Email in envelope

Get an email when there's a new version of ConcurrentTest

Home / 0.9.0
Name Modified Size InfoDownloads / Week
Parent folder
This folder has no files.
Totals: 0 Items   0
ConcurrentTest

 - 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 report automatically.
 
 
 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;
    
public class JavaReflectRunner extends AbstractRunner {
	
	public void doWork(int i) {		
		try {
			Foo foo = new Foo();
			Method method = Foo.class.getMethod("sayHello", new Class<?>[]{ String.class });
			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 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 count 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 count as you need.
         
  	public static void main(String[] args) {
		int poolSize = 4;
		int concurrents = 200;
		int countPerThread = 10000;			
		
		System.out.printf("ConTest Demo" +"\r\n");	
		System.out.printf("ConTest: A Java Concurrent Test Framework." +"\r\n");
		System.out.printf("Author: Raymond He" +"\r\n");
		System.out.printf("Version: 0.9" +"\r\n");
		
		System.out.printf("****************************************\r\n");
		System.out.printf(ConcurrentTestReport.getHeader() +"\r\n");	
		
		testJavaReflect(poolSize,concurrents, countPerThread);
		
	}
	
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)
  JavaReflectRunner,4,200,10000,1751520934,875,1141 
  
Source: Readme.txt, updated 2010-05-30