[转]比较Jmeter、Grinder和JAVA多线程本身压力测试所带来的性能开销
1. 测试环境
jmeter版本 :jmeter 2.4
grinder的版本 : Grinder 3
JAVA的版本:JDK 1.6
2. 测试代码
Jmeter测试代码
- 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();
- }
- }
grinder测试代码
- 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()
Java本身多线程
- 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();
- }
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. 结论
- 可以看出Jmeter的本身性能开销是很大的,只适合一般应用的性能测试
- Grinder在测试的时候发现上下文切换比较严重,而可能是因为内部机制导致的开销较大的,当然如果测试memcache肯定是不适合的,但一般的应用测试基本上没有问题
- JAVA多线程本身并发框架性能开销也是有的,但是比较低,适合要求较高的性能测试,如对redis和memcache构建的应用进行压测
转:http://blog.csdn.net/techq/article/details/6628533
[转]比较Jmeter、Grinder和JAVA多线程本身压力测试所带来的性能开销的更多相关文章
- java基础六 [异常处理](阅读Head First Java记录)
在程序运行时,我们不能保证所有服务和方法都是正确的,如果发生问题报错会导致程序崩溃,所以需要对一些可以预见的错误进行异常处理,通过throw去抛出一个异常,然后用try..catch..将要执行的该方 ...
- Java Collection 集合类大小调整带来的性能消耗
Java Collection类的某些详细实现因为底层数据存储基于数组,随着元素数量的添加,调整大小的代价非常大.随着Collection元素增长到某个上限,调整其大小可能出现性能问题. 当Colle ...
- Java基础 之软引用、弱引用、虚引用 ·[转载]
Java基础 之软引用.弱引用.虚引用 ·[转载] 2011-11-24 14:43:41 Java基础 之软引用.弱引用.虚引用 浏览(509)|评论(1) 交流分类:Java|笔记分类: Ja ...
- Java多线程-新特性-线程池
Sun在Java5中,对Java线程的类库做了大量的扩展,其中线程池就是Java5的新特征之一,除了线程池之外,还有很多多线程相关的内容,为多线程的编程带来了极大便利.为了编写高效稳定可靠的多线程程序 ...
- Java多线程详解
Java线程:概念与原理 一.操作系统中线程和进程的概念 现在的操作系统是多任务操作系统.多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的一块内存空间,一个进程 ...
- Java多线程与并发模型之锁
这是一篇总结Java多线程开发的长文.文章是从Java创建之初就存在的synchronized关键字引入,对Java多线程和并发模型进行了探讨.希望通过此篇内容的解读能帮助Java开发者更好的理清Ja ...
- java 多线程和线程池
● 多线程 多线程的概念很好理解就是多条线程同时存在,但要用好多线程确不容易,涉及到多线程间通信,多线程共用一个资源等诸多问题. 使用多线程的优缺点: 优点: 1)适当的提高程序的执行效率(多个线程同 ...
- [转]如何在Java中调用DLL方法
转载地址:http://developer.51cto.com/art/200906/129773.htm Java语言本身具有跨平台性,如果通过Java调用DLL的技术方便易用,使用Java开发前台 ...
- java基础九[网络与线程](阅读Head First Java记录)
网络socket连接 Java API的网络功能包(java.net)已经将底层的TCP连接等都封装好了,我们只需要通过Socket对象来建立客户端和服务器的连接,然后客户端能向服务器发送请求,并接收 ...
随机推荐
- ASP.NET本质论第一章网站应用程序学习笔记2
1.初步走进ASP.NET 上篇笔记我们讲述了服务器监听问题,这篇我们就要讲述具体的请求处理了,ASP.NET所涉及的类大多数定义在System.Web程序集中. 在.NET中,程序集管理的最小逻辑单 ...
- .NET破解之PDFdo转换器
无意中看到一个PDF转换器,叫PDFdo,看起了功能挺多的,于是想把它破了. 下载 官网:http://www.pdfdo.com/ 安装 安装后,只有一个exe应用程序,如果是.NET 程序应该有很 ...
- ArcGIS10.2下调试10.1的程序
听说:10.2比10.1好,诚然,安装了10.2打开一看是这样的,以为是下载的版本问题,后来才以现是显示设置的问题. 因为,我使用的两个显示器,屏幕有点大,所以,就改成中等了,不然怎么可截取下面的截图 ...
- oracle10g 统计信息查看、收集
1. 统计信息查看 1.1 单个表的全局统计信息.统计效果查看 2. 统计信息分析(收集) 2.1 分析工具选择 2.2 分析前做index重建 2.3 分析某数据表,可以在PL/SQL的comm ...
- iOS8以后 UISearchController的用法
查了不少资料,都不太全,自己查看了apple文档,写了一份代码: 如下(只是界面): 1. 声明属性 @property (nonatomic, strong) UISearchController ...
- 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 ...
- HTTP 协议中的 Content-Encoding 和 Transfer-Encoding(内容编码和传输编码)
转自:http://network.51cto.com/art/201509/491335.htm Transfer-Encoding,是一个 HTTP 头部字段,字面意思是「传输编码」.实际上,HT ...
- FAQ-Ubuntu12.04 15.04禁止移动介质自动播放
网上有有很多关于Ubuntu10.04关闭移动介质自动播放的方法,包括在文件管理器里面设置或者使用gconf-editor,但是从12.04开始这两种方法都不再好用了,关于移动介质的处理方法被移到了S ...
- 进制,原码VS补码
进制 十,八,十六进制=>二进制 十进制=>二进制:辗转相除取余,10除2商5余0,5除2商2余1,2除2商1余0,1除2商0余1,So,10d=1010b 八进制=>二进制:每1位 ...
- poj 1144 Network 图的割顶判断模板
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8797 Accepted: 4116 Descripti ...