jmeter版本 :jmeter 2.4
grinder的版本 : Grinder 3
JAVA的版本:JDK 1.6
public class Sampler { public void test() { return; } }
public class JmeterTest extends AbstractJavaSamplerClient { Sampler sampler; @Override public SampleResult runTest(JavaSamplerContext context) { SampleResult results = new SampleResult(); results.sampleStart(); sampler.test(); results.sampleEnd(); results.setSuccessful(true); return results; } @Override public void setupTest(JavaSamplerContext arg0) { sampler = new Sampler(); } }
public class Sampler { public void test() { return; } }
# Test.py # # A minimal script that tests The Grinder logging facility. # # This script shows the recommended style for scripts, with a # TestRunner class. The script is executed just once by each worker # process and defines the TestRunner class. The Grinder creates an # instance of TestRunner for each worker thread, and repeatedly calls # the instance for each run of that thread. from net.grinder.script.Grinder import grinder from net.grinder.script import Test from sampler import Sampler test = Test(1, "Sample") class TestRunner: # This method is called for every run. def __call__(self): mySampler = test.wrap(Sampler()) mySampler.test()
public static void test(int numOfThreads, int times) throws InterruptedException, ExecutionException { ExecutorService executor = Executors.newFixedThreadPool(numOfThreads); final Sampler sampler = new Sampler(); List<Future<Long>> results = new ArrayList<Future<Long>>(); for (int i = 0; i < times; i++) { results.add(executor.submit(new Callable<Long>() { @Override public Long call() throws Exception { long begin = System.currentTimeMillis(); sampler.test(); long end = System.currentTimeMillis(); return end - begin; } })); } executor.shutdown(); while(!executor.awaitTermination(1, TimeUnit.SECONDS)); long sum = 0; for (Future<Long> result : results) { sum += result.get(); } System.out.println("---------------------------------"); System.out.println("number of threads :" + numOfThreads + " times:" + times); System.out.println("running time: " + sum + "ms"); System.out.println("TPS: " + (double)(100000 * 1000) / (double)(sum)); System.out.println(); }
10个线程 100000次运行
-- | TPS |
Jmeter | 50426.10 |
Grinder | 290275.76 |
Java threads | 2.5E7 |
20个线程 100000次运行
-- | TPS |
Jmeter | 49215.02 |
Grinder | 225402.91 |
Java threads | 2.5E7 |
50个线程 100000次运行
-- | TPS |
Jmeter | 29312.61 |
Grinder | 212242.13 |
Java threads | 2.5E7 |
100个线程 100000次运行
-- | TPS |
Jmeter | 29031.03 |
Grinder | 245507.22 |
Java threads | 2.5E7 |
200个线程 10000次运行(这里减少了一个0)
-- | TPS |
Jmeter | 28039.87 |
Grinder | 232801.77 |
Java threads | 2.5E7 |
300个线程 10000次运行
-- | TPS |
Jmeter | 27208.16 |
Grinder | 236537.10 |
Java threads | 1818181.81 |
1000个线程 10000次运行
-- | TPS |
Jmeter | 27208.16 |
Grinder | 236537.10 |
Java threads | 2.5E7 |