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. ASP.NET本质论第一章网站应用程序学习笔记2

    1.初步走进ASP.NET 上篇笔记我们讲述了服务器监听问题,这篇我们就要讲述具体的请求处理了,ASP.NET所涉及的类大多数定义在System.Web程序集中. 在.NET中,程序集管理的最小逻辑单 ...

  2. .NET破解之PDFdo转换器

    无意中看到一个PDF转换器,叫PDFdo,看起了功能挺多的,于是想把它破了. 下载 官网:http://www.pdfdo.com/ 安装 安装后,只有一个exe应用程序,如果是.NET 程序应该有很 ...

  3. ArcGIS10.2下调试10.1的程序

    听说:10.2比10.1好,诚然,安装了10.2打开一看是这样的,以为是下载的版本问题,后来才以现是显示设置的问题. 因为,我使用的两个显示器,屏幕有点大,所以,就改成中等了,不然怎么可截取下面的截图 ...

  4. oracle10g 统计信息查看、收集

      1. 统计信息查看 1.1 单个表的全局统计信息.统计效果查看 2. 统计信息分析(收集) 2.1 分析工具选择 2.2 分析前做index重建 2.3 分析某数据表,可以在PL/SQL的comm ...

  5. iOS8以后 UISearchController的用法

    查了不少资料,都不太全,自己查看了apple文档,写了一份代码: 如下(只是界面): 1. 声明属性 @property (nonatomic, strong) UISearchController ...

  6. Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot evaluate com.hotel.Object_$$_jvst485_15.toString()

    数据库字段和类Object属性不匹配,Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot eval ...

  7. HTTP 协议中的 Content-Encoding 和 Transfer-Encoding(内容编码和传输编码)

    转自:http://network.51cto.com/art/201509/491335.htm Transfer-Encoding,是一个 HTTP 头部字段,字面意思是「传输编码」.实际上,HT ...

  8. FAQ-Ubuntu12.04 15.04禁止移动介质自动播放

    网上有有很多关于Ubuntu10.04关闭移动介质自动播放的方法,包括在文件管理器里面设置或者使用gconf-editor,但是从12.04开始这两种方法都不再好用了,关于移动介质的处理方法被移到了S ...

  9. 进制,原码VS补码

    进制 十,八,十六进制=>二进制 十进制=>二进制:辗转相除取余,10除2商5余0,5除2商2余1,2除2商1余0,1除2商0余1,So,10d=1010b 八进制=>二进制:每1位 ...

  10. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...