Page:
Profiler
Pages
ActiveMQ
Ajax
AssertJ
BDD
Base Utils
BluePrintCSS(Deprecated)
CXF
Caching
Change4
ChangeLog
CreateNewProject
Crypto
Database
Datasource
DateTime
Design
Dozer
Eclipse
Ehcache
Email
Executable War
Graphite Windows
Graphite
Guava Cache
H2 Database
Hibernate Validator
High Performance Utils
Home
Home4.0
HttpClient
Hystrix
JMeter
JPA
JQuery Validation Plugin
JQuery
JSP
Jaxb
Jersey(Deprecated)
Jetty
Jmx
Json
Log
Logstash
Maven
Memcached
Metrics library
Mock
Monitoring and Metrics
MyBatis
Nodejs
Non Function
Performace test
Profiler
QuickStart
Rate Limiter
Redis
Reflection
ReleaseProcess(Internal)
Schedule
Selenium2
Serialize
Shiro Security
Simulator
SiteMesh
Sonar
Spring Data JPA
Spring MVC
Spring Restful Service
Spring
SpringSide Utils Overview
System Protection
Test Overview
Text
Transaction
Travis CI
Tutorial
Twitter Bootstrap
Unit Test
Validation
YUI Compressor
git
Clone
Table of Contents
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
选型
在性能调优时,总想知道一些函数消耗的时间,找出瓶颈。有很多开源方案能满足这一点,几者之间相差毫厘而已。
从大的分类上,Profiler工具不同于Netflix Servo,Yammer Metric, etsy statsd 这些Monitor/Metrics工具,莫要搞混了。
基于编码或AOP的:
- JaMon,可能最为老牌,但也有很久没更新了。
- JavaMelody,LGPL的协议,而且管得太多了,连CPU、内存都管,Web Dashboard也不好看。
- Perf4j,没有内置Web Dashboard。
- JavaSimon,各方面正合适,作者原来也用JaMon,后来加了树型排列结果与纳秒级统计的支持,详见Javasimon自述
基于JVM整体的profiler:VisualVM,EClipse Profiler,Yourkit 等,经常过大过慢和崩溃,失望了几次后就不再尝试了。
##JavaSimon Simon不是西蒙,是Simple Monitoring的意思,太简单了,和其他几种monitor也差不多,几乎没什么好讲的,看官方的简短文档就足够。
在showcase中作了演示,手工点击综合演示或运行Jmeter脚本后,查看dashboard即可看见结果。
一、pom.xml,加入core与dashboard的依赖:
<dependency>
<groupId>org.javasimon</groupId>
<artifactId>javasimon-spring</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.javasimon</groupId>
<artifactId>javasimon-console-embed</artifactId>
<version>3.3.0</version>
</dependency>
二、web.xml,加入dashboard:
<servlet>
<servlet-name>SimonConsoleServlet</servlet-name>
<servlet-class>org.javasimon.console.SimonConsoleServlet</servlet-class>
<init-param>
<param-name>url-prefix</param-name>
<param-value>/javasimon</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SimonConsoleServlet</servlet-name>
<url-pattern>/javasimon/*</url-pattern>
</servlet-mapping>
三、applicationContext.xml 加入AOP设置
如下片段监控用@monitored定义了的类或方法:
<!-- 调用StopWatch计时的Interceptor -->
<bean id="monitoringInterceptor" class="org.javasimon.spring.MonitoringInterceptor" />
<!-- 监控定义了@Monitored的方法 -->
<bean id="monitoringAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice" ref="monitoringInterceptor" />
<property name="pointcut">
<bean class="org.javasimon.spring.MonitoredMeasuringPointcut" />
</property>
</bean>
如果在其他xml文件未包含DefaultAdvisorAutoProxyCreator,此处需要定义:
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
<property name="proxyTargetClass" value="true" />
</bean>
四、在已知一定要监控的类或方法上加@Monitored。
五、不修改代码监控新的方法
如下AOP定义片段监控了NotifyMessageProducer与BusinessLogger的公共方法:
<aop:config>
<aop:advisor advice-ref="monitoringInterceptor" pointcut="execution(public * org.springside..NotifyMessageProducer.*(..))
|| execution(public * org.springside..BusinessLogger.*(..))" />
</aop:config>
六、(可选)监控jdbc访问速度 换用新的jdbc driver,在旧的jdbc url里插入simon
jdbc.driver=org.javasimon.jdbc4.Driver
jdbc.url=jdbc:simon:h2:file:~/.h2/showcase4;