- 浏览: 373344 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
y806839048:
启动activemq我试了,也不行
ActiveMQ5.0实战三:使用Spring发送,消费topic和queue消息 -
y806839048:
是不是要另外启动activemq
ActiveMQ5.0实战三:使用Spring发送,消费topic和queue消息 -
y806839048:
为什么我的两个应用中,不能实现通信
ActiveMQ5.0实战三:使用Spring发送,消费topic和queue消息 -
fengfujie:
[flash=200,200][/flash][tr][th] ...
JMS消息类型模型 -
fengfujie:
...
JMS消息类型模型
At the weekend I managed to get some free time away from working on our next release to look at a recent benchmark that compared the performance of Google Guice 1.0 with Spring 2.5. The benchmark referred to in the article as a modified version of Crazy Bob’s “Semi Useless” Benchmark is interesting not in terms of the results but in the analysis of the results and test construction. After reviewing the findings and benchmark code I thought it would be a good idea to instrument particular parts in the code with our Probes resource metering framework to better understand some peculiarities reported and to show how I use JXInsight Probes myself.
What follows is the typical process steps I perform when investigating a probable performance issue with a code base that I am largely unfamiliar with. During this process I highlight possible pitfalls in creating a benchmark as well in the analysis of results when related to concurrency, GC and memory allocation. Very importantly is that the conclusions of this process are different from those posted on the benchmark blog
In the benchmark there are 2 basic parameters with 4 possible combinations for each technology benchmarked. The first parameter indicates whether the test is to be executed concurrently (5 threads). The second parameter indicates whether a singleton factory is used. It is important to note that in the benchmark the number of calls made by one or more threads is dependent on the value of the singleton parameter (see first line in iterate(..)
method). Below are the results from my own benchmarking on a Mac PowerBook G4 for each of the four possible combinations per technology.
(C) Concurrent
(CS)Concurrent + Singleton
(S) Singleton
( ) Non-Concurrent + Non-Singleton
After being surprised by the large difference in the concurrent tests with a non-singleton factory (Guice is much faster than Spring) I was intrigued by the closeness of the singleton tests across technologies especially as the Guice concurrent test run for the singleton instance was much slower than its concurrent test run for the non-singleton factory even after taking into account the increase (x10) in number of validate(...)
method calls. Time for some basic instrumentation to better explain the results.
Below I have highlighted the main changes I made to the benchmark code to capture the resource consumption across the two different executing thread workers using our open Probes API.
I ran both the Guice and Spring tests separately to ensure that neither impacted the others results. I then merged each of the probes snapshot that were automatically exported at the end of each test run. Here is the jxinsight.override.config
properties file used for my first set of tests.
jxinsight.server.profiler.autostart=false
jxinsight.server.agent.events.gc.enabled=false
# new system property in 5.5.EA.16
jxinsight.server.probes.highprecision.enabled=true
jxinsight.server.probes.meter.clock.time.include=true
jxinsight.server.probes.meter.cpu.time.include=true
jxinsight.server.probes.meter.blocking.time.include=true
jxinsight.server.probes.meter.waiting.time.include=true
jxinsight.server.probes.meter.jmgmt.gc.time.include=true
jxinsight.server.probes.meter.jmgmt.gc.count.include=true
The high level metering results are shown below with times reported in microseconds and the data sorted by total. Note the general ordering of technologies changes within one particular meter.
The table below shows the wall clock times for each technology and for each parameter combination. What immediately struck me about the data was the change in ordering of singleton and non-singleton tests across Spring and Guice. With Guice the singleton tests were always slower than the non-singleton tests which is the complete opposite to Spring and what you would expect. I then noticed that this difference was much more prominent when executed concurrently. Spring (CS) was 13.696 seconds compared with Guice’s (CS) 19.544 seconds - approximately a 6 second difference.
When comparing across concurrent tests I used the Iterate
probe group because the wall clock is a global meter and hence is multiplied by the number of concurrent (aggregating) threads firing probes.
Analysis of the CPU metering data also revealed the same strange difference in test ordering across technologies when the table was sorted by the Total column. Because CPU is a thread specific meter I looked at the totals for the Run
probe group. Spring (CS) was 11.028 seconds compared with Guice’s (CS) 13.112 seconds - approximately 2 seconds in the difference but not 6 seconds. Could this be a clue? Well not necessarily because the CPU times for Spring (S) and Guice (S) were reversed though somewhat closer - 2.203 seconds compared to 2.075 seconds respectively. It would appear from this that Guice trades additional CPU processing with a reduction in thread monitor contention.
When I first looked at the following table I noticed that the difference in ordering between the non-singleton to singleton tests across technologies had disappeared - both Spring and Guice had non-singleton listed first under concurrent testing and the reversed order when executing tests with one thread.
Then I noticed the high blocking time of 9.248 seconds when executing Guice (CS) tests compared 0.054 seconds for the same test using Spring. To have such high blocking times the software needs to be executing a relatively expensive (in terms of this micro-benchmark) operation within a synchronized block that is called with a high degree of concurrency (multiple threads). But this is a singleton test what could that expensive operation be once the singleton has been created?
I was now extremely curious about what would be the final conclusion so I skipped the waiting time meter as this would only report on the Thread.join()
method calls used to determine the end of the concurrent tests runs.
The garbage collection (GC) time meter always has a tale to tell about the software execution model and this time around it was to be no different. My first observation was that Guice placed before Spring within this particular meter. But on closer examination I could see that this was largely a result of the aggregation of GC times for singleton tests (are the alarm bells ringing). Guice appeared to be more efficient, in terms of object allocation, when executing non-singleton tests than when executing singleton tests. Surely this is not correct? It is not correct (at least not completely) and there is a clue in the Spring metering data - object allocation (how else would we have GC) always occurs even when using a singleton factory.
The next meter I looked at is the number of times GC occurs during each test run using the value of the total for the Iterate
probe group because GC like wall clock time is a global meter and thus is duplicated (correctly) in the Run
probe group totals. After looking at the GC times in the table above you might be expecting that the ordering of the technology stack to be the same but it is not! Does this tell me something? That GC is more efficient (shorter cycles) when cleaning up objects created by Spring?
At this stage I had enough information to formulate an educated guess for the cause of the performance degradation when executing singleton tests with Guice but there was still something not right about the data. I decided to re-run my tests but this time turning off all timing metrics and focusing on object allocation. Here are the system properties used in the jxinsight.override.config
file.
jxinsight.server.profiler.autostart=false
jxinsight.server.agent.events.gc.enabled=false
jxinsight.server.agent.events.alloc.enabled=true
jxinsight.server.probes.highprecision.enabled=true
jxinsight.server.probes.meter.alloc.bytes.include=true
jxinsight.server.probes.meter.clock.time.include=false
The test data did confirm the first part of my guess that the underlying cause was related to an increased level of object allocation. (The second part was that this allocation occurred in a synchronized block which would explain why the difference was more pronounce in the concurrent tests.) The Guice singleton tests had not only higher values than the same tests under Spring but more significantly they were higher than the Guice non-singleton tests. But why did the Spring numbers for singleton tests look still too high? I decided to take another look at the validate(...)
method and the out bound calls. This time I was looking for a method that might inadvertently create objects. I found the culprit. The JUnit assertEquals(int,int)
creates two Integers
before calling Object.equals(Object)
.
Here are the revised figures after replacing the Assert.assertEquals(int, int)
method with an implementation that does not create any Integer
objects. The Spring results now looked inline with what we would expect from a single factory - an object instance created for each additional concurrent thread.
The above figures for the Guice singleton tests had decreased by approximately 50% but there was still object allocation occurring. This called for more in-depth resource metering analysis of the Google Guice codebase.
Here is the metering data collected after load-time weaving in our Probes aspect library into the runtime. I have included the Total (Inherent) column in this screen shot to point out the actual object allocation cost centers and call delegation (Hint: 6,400,000 - 1,600,000 = 4,800,000 and 4,800,00 - 2,400,000 = 2,400,000).
Here is the related code snippet extracted from Google Code showing the actual object allocation calls.
Discuss this article with William
原文link: http://www.javalobby.org/articles/guice-vs-spring/发表评论
-
Spring Milestone Maven Repository地址
2009-05-11 10:52 7868使用maven又想试用spring 3.0 m3的朋友可以用s ... -
HiddenHttpMethodFilter:自动转换Http Method
2009-03-29 11:21 5494REST的核心之一就是提供统一接口,也就是说对所有的资源(UR ... -
ActiveMQ5.0实战三:使用Spring发送,消费topic和queue消息
2008-08-28 18:21 33120ActiveMQ5.0实战一: 安装配 ... -
The smallwig theory of optimization
2008-04-17 09:49 1379There are three kinds of optimi ... -
ElementType.LOCAL_VARIABLE目前基本没用
2008-04-07 18:30 3904jdk5.0引入Annotation语法,@Target中的E ... -
Memcached java client 2.01发布
2008-04-05 21:39 2381com.danga.MemCached 发布2.0.1包括许多 ... -
Struts2中使用Stream Result Type
2008-04-05 18:25 18106Stream result type是Struts2中比较有用 ... -
NotSerializableException: EnhancerByCGLIB
2008-04-03 12:23 4292使用Ibatis时,为了获得更好的性能,我们一般都会将enha ... -
Pointcut命名有可能导致错误
2008-02-28 19:16 4315使用Spring @AspectJ方式的AOP,代码@Aspe ... -
异常通知:面向方面的模型
2008-02-28 15:16 2174原文:http://dev2dev.bea.com ... -
Sping容器加载xsd文件时的问题
2008-01-31 17:56 6372今天遇到一个非常奇怪的spring容器问题,先看日志]-303 ... -
关于memcached client的选择
2008-01-10 15:29 13543Memcached(http://www.danga.com/ ... -
Java确实不适合于作为主要编程教学语言
2008-01-10 12:12 1649最近米国那边又在讨论这个话题, 孟岩也发了一篇帖子http:/ ... -
Spring 2.5Annotation使用基本类型和${}
2008-01-08 19:08 2746最近使用了Spring2.5 annotation风格的DI, ... -
ActiveMQ5.0实战二: 基本配置
2008-01-08 17:33 12455/** *作者:andyao,email:andyaoy@gm ... -
JMS消息类型模型
2008-01-04 18:12 9544/**作者:andyao,email:andyaoy@gmai ... -
ActiveMQ5.0实战一: 安装配置ActiveMQ5.0
2008-01-05 18:03 10094/** *作者:andyao,email:andyaoy@gm ... -
Spring Annotation和XML风格的声明式事务
2008-01-04 14:02 5604/***作者:andyao,email:andyaoy@gma ... -
国际化异常消息
2007-12-21 14:26 3865/**作者:andyao,email:andyaoy@gmai ... -
Exception for Action
2007-12-17 16:31 1542原文:http://www.javaworld.com/ja ...
相关推荐
《OTB数据集工具包评测工具包Tracker Benchmark v1.0详解》 OTB(One-Thing-One-Target Benchmark)是计算机视觉领域中一个广泛使用的单目标跟踪数据集,其目的是评估和比较不同追踪算法的性能。Tracker Benchmark ...
《Python库benchmark-runner-1.0.261:高效性能测试与基准分析》 在IT行业中,Python作为一门强大的开发语言,拥有丰富的库资源,为开发者提供了无尽的便利。今天我们要关注的是一个名为“benchmark-runner”的...
python库。 资源全名:benchmark_runner-1.0.280-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:benchmark-runner-1.0.67.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源来自pypi官网。 资源全名:benchmark-runner-1.0.132.tar.gz
**Python库benchmark_runner-1.0.252-py3-none-any.whl详解** 在Python编程中,库(Library)扮演着至关重要的角色,它们提供了丰富的功能,帮助开发者节省时间和精力,专注于核心业务逻辑。`benchmark_runner`是...
《PyPI官网下载:benchmark-runner-1.0.73.tar.gz——探索Python在云原生环境中的性能基准测试》 PyPI(Python Package Index)是Python开发者们分享和获取软件包的重要平台,这里提到的"benchmark-runner-1.0.73....
python库。 资源全名:benchmark_runner-1.0.116-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:benchmark_runner-1.0.291-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:benchmark_runner-1.0.155-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:benchmark_runner-1.0.124-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
《Benchmark::Timer——Perl中的基准测试利器》 在Perl编程领域,进行性能优化是至关重要的。为了有效地评估和比较代码的执行效率,开发者通常需要一个可靠的基准测试工具。"Benchmark::Timer"就是这样一款强大的...
如果您希望使用或学习如何使用 Benchmark Email 的 Java 包装器与我们的 API 集成,那么您来对地方了。 这些文件的目的是帮助您快速有效地开始使用我们的 API 进行开发。 该项目将展示如何: 登录 Benchmark 电子...
资源分类:Python库 所属语言:Python 资源全名:benchmark-runner-1.0.232.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059