1. 测试环境

jmeter版本 :jmeter 2.4

grinder的版本 : Grinder 3

JAVA的版本:JDK 1.6

2. 测试代码

Jmeter测试代码

  1. public class Sampler {
  2. public void test() {
  3. return;
  4. }
  5. }
  1. public class JmeterTest extends AbstractJavaSamplerClient {
  2. Sampler sampler;
  3. @Override
  4. public SampleResult runTest(JavaSamplerContext context) {
  5. SampleResult results = new SampleResult();
  6. results.sampleStart();
  7. sampler.test();
  8. results.sampleEnd();
  9. results.setSuccessful(true);
  10. return results;
  11. }
  12. @Override
  13. public void setupTest(JavaSamplerContext arg0) {
  14. sampler = new Sampler();
  15. }
  16. }

grinder测试代码

  1. public class Sampler {
  2. public void test() {
  3. return;
  4. }
  5. }
  1. # Test.py
  2. #
  3. # A minimal script that tests The Grinder logging facility.
  4. #
  5. # This script shows the recommended style for scripts, with a
  6. # TestRunner class. The script is executed just once by each worker
  7. # process and defines the TestRunner class. The Grinder creates an
  8. # instance of TestRunner for each worker thread, and repeatedly calls
  9. # the instance for each run of that thread.
  10. from net.grinder.script.Grinder import grinder
  11. from net.grinder.script import Test
  12. from sampler import Sampler
  13. test = Test(1, "Sample")
  14. class TestRunner:
  15. # This method is called for every run.
  16. def __call__(self):
  17. mySampler = test.wrap(Sampler())
  18. mySampler.test()

Java本身多线程

  1. public static void test(int numOfThreads, int times) throws InterruptedException, ExecutionException {
  2. ExecutorService executor = Executors.newFixedThreadPool(numOfThreads);
  3. final Sampler sampler = new Sampler();
  4. List<Future<Long>> results = new ArrayList<Future<Long>>();
  5. for (int i = 0; i < times; i++) {
  6. results.add(executor.submit(new Callable<Long>() {
  7. @Override
  8. public Long call() throws Exception {
  9. long begin = System.currentTimeMillis();
  10. sampler.test();
  11. long end = System.currentTimeMillis();
  12. return end - begin;
  13. }
  14. }));
  15. }
  16. executor.shutdown();
  17. while(!executor.awaitTermination(1, TimeUnit.SECONDS));
  18. long sum = 0;
  19. for (Future<Long> result : results) {
  20. sum += result.get();
  21. }
  22. System.out.println("---------------------------------");
  23. System.out.println("number of threads :" + numOfThreads + " times:" + times);
  24. System.out.println("running time: " + sum + "ms");
  25. System.out.println("TPS: " + (double)(100000 * 1000) / (double)(sum));
  26. System.out.println();
  27. }

3. 测试结果

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

4. 结论

    1. 可以看出Jmeter的本身性能开销是很大的,只适合一般应用的性能测试
    2. Grinder在测试的时候发现上下文切换比较严重,而可能是因为内部机制导致的开销较大的,当然如果测试memcache肯定是不适合的,但一般的应用测试基本上没有问题
    3. JAVA多线程本身并发框架性能开销也是有的,但是比较低,适合要求较高的性能测试,如对redis和memcache构建的应用进行压测

转:http://blog.csdn.net/techq/article/details/6628533

[转]比较Jmeter、Grinder和JAVA多线程本身压力测试所带来的性能开销的更多相关文章

  1. java基础六 [异常处理](阅读Head First Java记录)

    在程序运行时,我们不能保证所有服务和方法都是正确的,如果发生问题报错会导致程序崩溃,所以需要对一些可以预见的错误进行异常处理,通过throw去抛出一个异常,然后用try..catch..将要执行的该方 ...

  2. Java Collection 集合类大小调整带来的性能消耗

    Java Collection类的某些详细实现因为底层数据存储基于数组,随着元素数量的添加,调整大小的代价非常大.随着Collection元素增长到某个上限,调整其大小可能出现性能问题. 当Colle ...

  3. Java基础 之软引用、弱引用、虚引用 ·[转载]

    Java基础 之软引用.弱引用.虚引用 ·[转载] 2011-11-24 14:43:41 Java基础 之软引用.弱引用.虚引用 浏览(509)|评论(1)   交流分类:Java|笔记分类: Ja ...

  4. Java多线程-新特性-线程池

    Sun在Java5中,对Java线程的类库做了大量的扩展,其中线程池就是Java5的新特征之一,除了线程池之外,还有很多多线程相关的内容,为多线程的编程带来了极大便利.为了编写高效稳定可靠的多线程程序 ...

  5. Java多线程详解

    Java线程:概念与原理 一.操作系统中线程和进程的概念 现在的操作系统是多任务操作系统.多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的一块内存空间,一个进程 ...

  6. Java多线程与并发模型之锁

    这是一篇总结Java多线程开发的长文.文章是从Java创建之初就存在的synchronized关键字引入,对Java多线程和并发模型进行了探讨.希望通过此篇内容的解读能帮助Java开发者更好的理清Ja ...

  7. java 多线程和线程池

    ● 多线程 多线程的概念很好理解就是多条线程同时存在,但要用好多线程确不容易,涉及到多线程间通信,多线程共用一个资源等诸多问题. 使用多线程的优缺点: 优点: 1)适当的提高程序的执行效率(多个线程同 ...

  8. [转]如何在Java中调用DLL方法

    转载地址:http://developer.51cto.com/art/200906/129773.htm Java语言本身具有跨平台性,如果通过Java调用DLL的技术方便易用,使用Java开发前台 ...

  9. java基础九[网络与线程](阅读Head First Java记录)

    网络socket连接 Java API的网络功能包(java.net)已经将底层的TCP连接等都封装好了,我们只需要通过Socket对象来建立客户端和服务器的连接,然后客户端能向服务器发送请求,并接收 ...

随机推荐

  1. mysql performance_schema/information_schema授权问题

    mysql> grant all on performance_schema.* to 'testuser'@'%';ERROR 1044 (42000): Access denied for ...

  2. MySQL Plugin 'InnoDB' init function returned error一例

    早上上班后,测试说演示环境挂了,维护上去看了下,启动报错了: XXXXXX08:30:47 mysqld_safe Starting mysqld daemon with databases from ...

  3. javascript中||和&&代替if

    首先,我们来看一段代码: ; ){ add_level = ; } ){ add_level = ; } ){ add_level = ; } ){ add_level = ; } else { ad ...

  4. 对getElementsByTagName("*")获取全部元素的总结

    var all=document.getElementsByTagName("*")      //获取整个页面的标签元素 alert(all.length);           ...

  5. 用单例模式封装常用方法 utils class v1.0

    utils class v1.0:The common methods used in our JS are included. * by sarah on 2016/01/28 var utils ...

  6. win10应用部署到手机出现问题Exception from HRESULT: 0x80073CFD

    今天把应用部署到手机上时,出现了这样的问题 Exception from HRESULT: 0x80073CFD 具体错误是: Error Error : DEP0001 : Unexpected E ...

  7. R Graphics Cookbook 第3章 – Bar Graphs

    3.1 基本条形图 library(ggplot2) library(gcookbook) pg_mean   #这是用到的数据   group weight 1  ctrl  5.032 2  tr ...

  8. Android 开发组件

    每一个应用程序都有自己独立的运行沙盒(授予应用程序代码的访问权) Android操作系统是一个多用户的Linux系统,其中的每一个应用程序都是一个独立的用户. 系统会为每一个应用程序分配一个唯一的Li ...

  9. C语言常量与指针

    C语言功能强大而丰富,还表现在const与指针的结合使用上,对不同的问题,它提供不同的保护,特别有用的是指向常量的指针 本文地址:http://www.cnblogs.com/archimedes/p ...

  10. 《ASP.NET MVC 5 框架揭秘》

    <ASP.NET MVC 5 框架揭秘> 基本信息 作者: 蒋金楠 出版社:电子工业出版社 ISBN:9787121237812 上架时间:2014-8-1 出版日期:2014 年8月 开 ...