使用JRockit Mission Control进行性能分析和调优


Mission ControlBEA JRockit JVM自带的一组以极低的开销来监控、管理和分析生产环境中的应用程序的工具。它包括三个独立的应用程序:内存泄漏监测器(Memory Leak Detector)、JVM运行时分析器(Runtime Analyzer)和管理控制台(Management Console)。BEAJRockit R26版本就开始捆绑这个工具套件,目前最新的版本是3.0。最近我们使用其中的Runtime Analyzer对国内某著名行业解决方案进行性分析和调优。


 


JRockit Runtime AnalyzerJRA)是一个JVM分析器,是一个随需应变的“动态记录器”。它记录了Java应用程序和JVM在一段预定的时间内的详细记录。然后通过JRA应用程序对记录下来的文件进行离线分析。所记录的数据包括对方法的调用跟踪、错误的同步、锁定的分析,还有垃圾收集统计信息,优化决策以及对象统计信息和其他重要的应用程序/JVM行为。它的目的是让JRockit开发人员能够找到良好的方法来基于现实应用程序优化JVM,对于帮助客户在生产和开发环境中解决问题十分有用。


 


2.性能数据分析和调优


 


在本次项目中,操作|A和操作B的百人并发脚本执行完成的时间接近两分钟,因此我们使用JRA进行了2分钟(120)的记录。在GC常规信息中,我们发现在短短两分钟时间内,垃圾收集的总数高达365次,而由此造成的暂停时间有42.5秒之多。也就是说35%的执行时间是在做垃圾收集。


 


因为最大堆尺寸已经设置成1024M,对于32位操作系统上的Java应用已经是足够大了(在IA32构架下,由于操作系统给每个进程的最大内存寻址空间为1.8G,因此最大堆尺寸不能超过1.8G),因此堆的大小并不是造成频繁垃圾收集的原因。那么在高并发度的场景下,可能的影响因素很可能是Nursery大小。


 


Nursery 也称为新代,是指运行分代式垃圾收集器时,在堆中分配 新对象 的可用块区域。 Nursery 变满时,会在新垃圾收集中单独对其进行垃圾收集。Nursery 大小决定了新收集的频率和持续时间。较大 Nursery 会降低收集的频率,但是会稍微增加每个新收集的持续时间。 Nursery 之所以具有价值,是因为 Java 应用程序中的大多数对象都是在新代中夭亡的。与收集整个堆相比,应首选从新空间中收集垃圾,因为该收集过程的开销更低,而且在触发收集时,新空间中的大多数对象均已死亡。在新收集过程中,JVM 首先确定 Nursery 中的哪些对象是活动的,此后将它们提升到旧空间,并释放 Nursery,供分配新的小对象使用


 


Nursery的默认缺省值是10M/CPU,对于我们Clovertown服务器来说,只有20M。由于出现频繁收集的情况,那么我们推断是由于Nursery的默认值太低的原因。一方面在高并发用户的场景下,肯定是有大量的新对象产生,那么Nursery的空闲空间很容易就被耗尽。因此Nursery发生垃圾收集频率就会比较高。另一方面更短的垃圾收集间隔会使得新对象在Nursery的存活率提高因为很多新对象可能还没来得及使用完毕就已经发生垃圾收集。这样更多的对象会被提升到旧代,使得旧代的对象也会急剧增加,从而使得旧代发生垃圾收集的频率也增加。


 


因为JRockit JVM可以使用-Xns:<size>来设置Nursery的尺寸,我们要在保证垃圾回收停顿时间(garbage collection-pause)尽可能短的同时,尽量加大Nursery的尺寸,这在创建了大量的临时对象时尤其重要。推荐值是最大堆尺寸的10%,因此我们在JRockit的运行时参数上添加了 –Xns100m。再次运行脚本后,JRA收集的信息显示GC暂停时间骤降到15.3s,次数也有所减少,降到296


 




















Nursery大小


20M(默认值)


100M


GC暂停时间


42.5s


15.3s


垃圾收集的总数


365


296


平均暂停时间


116ms


52ms


 


此外,我们从方法信息中可以看到调用次数最多耗时间最长的两个方法分别是jrockit.vm.Locks.monitorEnterSecondStagecom.ABC.StateManager.makeState两个方法。展开前置任务后发现调用这两个方法最多的方法是com.ABC.SqlQueryAction.query。而jrockit.vm.Locks.monitorEnterSecondStage显然是JRockit实现锁机制的特定的API。因此我们怀疑是对数据库的操作时有资源互斥的现象发现。


 


考虑到高并发用户的场景下,对数据库操作的并发度也很高,因此对数据库连接的争用比较激烈。我们察看了一下当时WebLogic JDBC的配置,发现connection pool的大小只是缺省值20,相对来说偏小了,对性能会有一定的影响。因此我们增大connection pool的大小到100。重新运行测试脚本后发现性能有较大提升。


 


 



















 


JDBC connection size 20  w/ default nursery


JDBC connection size 100 w/ 100M nursery


Increase %


 


操作A


22.125


12.079


83%


操作B


35.195


21.773


62%


 


 


在性能调优完成后,我们又进行了功能测试(回归测试),以验证上述改动没有影响系统的功能性正确。


四、小结


其实利用Mission ControlJava应用进行调优并不难,对吧?希望本次性能分析调优的过程可以给大家一些启发,今后可以应用到日常工作中。

resin clustering

本文主要讲述resin的clustering,简单明了。由于条件限制,只使用一台服务器,运行多个resin来实现clustering,如果多台服务器,只要修改相应的ip地下就可以了。

 

步骤1:

配置好resin.conf,至少可以把web应用运行起来。

 

步骤2:

执行:cp resin.conf resin-web.conf

 

resin.conf作为clustering的配置文件;

resin-web.conf为作web-tier的配置文件;

 

修改resin.conf

把app-tier中的<http address=”*” port=”80″/> 修改为       <!–http address=”*” port=”80″/–>

 

在<!– define the servers in the cluster –>下面增加servers(ip和端口可以自行修改)

 <server id=”a” address=”192.168.1.65″ port=”6800″/>
 <server id=”b” address=”192.168.1.64″ port=”6801″/>

 

修改resin-web.conf


在<!– define the servers in the cluster –>下面增加servers(ip和端口可以自行修改)

 <server id=”a” address=”192.168.1.65″ port=”6800″/>
 <server id=”b” address=”192.168.1.64″ port=”6801″/>

 

把web-tier中的 <http address=”*” port=”9080″/>修改为 <http address=”*” port=”80″/>

 

步骤3:

启动app-tier

java -jar lib/resin.jar -conf conf/resin.conf -server a &

java -jar lib/resin.jar -conf conf/resin.conf -server b &

 

启动web-tier

java -jar lib/resin.jar -conf conf/resin-web.conf -server web-a &

 

打开浏览器输入localhost

看看输出什么?

 

试着把a关闭,再打开locahost看看?

 

成功了吧?

lighttpd configure java web server

我的apache 2.061在window 2003 下老是报告错误,虽然也可以使用但感觉很不爽.
错误入下,找了很久也没有办法,包括修复sockt也没用.
报告队列中的错误: 错误应用程序 Apache.exe,版本 2.0.61.200,错误模块 ntdll.dll,版本 5.2.3790.3959,错误地

一直想找一个替代apache的软件,最近看了lighttpd想用lighttpd来替代apache,先下放过资料.
下载地址.
http://ftp.dtech.hu/pub/WLMP-Project/LightTPD-Win32/



. When to use lighttpd


You can use lighttpd to



  • secure access to your application server
  • reduce load on your server by offloading static requests
  • load balance your application servers
  • use lighttpd’s spambot and bad bot blocking capabilities
  • get more request rewriting and redirecting flexibility
  • use the above flexibility to improve your search engine rankings
  • profit.

2. When not to use lighttpd


You might not like lighttpd if you



  • don’t like configuring software
  • use URL rewriting and ;jsessionid (though a patch is available for this problem).

3. lighttpd modules you need


The following lighty modules are needed:



  • mod_access
  • mod_redirect
  • mod_rewrite
  • mod_proxy

Add them to your server.modules section:

server.modules = (
“mod_accesslog”,
“mod_access”,
“mod_redirect”,
“mod_rewrite”,
“mod_proxy”
,
“mod_status”,
“mod_evhost”,
“mod_expire”
)

4. Denying access to JEE directories


The WEB-INF and META-INF directories shouldn’t be accessible through lighttpd. Files from your development environment also shouldn’t be visible.

url.access-deny = ( “WEB-INF”, “.classpath”, “.project”, “META-INF” )

5. Binding your application server to localhost


To prevent duplicate content penalties, your application server shouldn’t be visible from the web. Even if you run it on a high port, someone might eventually find it.


Binding a web site to localhost looks like this in Orion’s <name>-web-site.xml:

<web-site host=”127.0.0.1″ port=”12345″>
<frontend host=”johannburkard.de” port=”80″/>

Consult your documentation if you aren’t using Orion.


6. Redirecting www. to non-www. hosts


Even if you don’t really need to do this, I recommend doing so. Removing duplicate content will improve your rankings.


The following snippet redirects all visitors from www.<domain> to <domain> with a 301 permanent redirect.

$HTTP[“host”] =~ “^www\.(.*)___FCKpd___3quot; {
url.redirect = ( “^/(.*)” => “http://%1/$1” )
}

You should also redirect all additional domains (johannburkard.com, johann-burkard.org) to your main domain.


7. Proxying dynamic requests


We will use mod_proxy to proxy some requests to your Java application server.


Depending on your site’s structure, one of the following approaches will work better.


Simple JSP


If all you have is a bunch of Java Server Pages, the following mod_proxy rule is sufficient:

proxy.server = ( “.jsp” =>
(
( “host” => “127.0.0.1”,
“port” => “12345”
)
)
)

Note that the JSP must be actual files. You cannot use Servlets mapped to these URIs.


Applications


If you use Servlets or more complex applications, you can proxy URIs by prefix:

proxy.server = ( “/blog/” =>
(
( “host” => “127.0.0.1”,
“port” => “12345”
)
)
)

Proxying with exceptions


If most of your site is dynamic and you have a directory for static content (/assets, /static or so), you can proxy all requests except requests for static files:

$HTTP[“url”] !~ “^/static” {
proxy.server = ( “” =>
(
( “host” => “127.0.0.1”,
“port” => “12345”
)
)
)
}

8. Rewriting requests


lighttpd can dynamically rewrite requests. I mostly use this to use default.jsp as dynamic index file instead of index.html. Here’s an example:

url.rewrite-once = ( “^(.*)/___FCKpd___7quot; => “$1/default.jsp”,
“^(.*)/([;?]+.*)___FCKpd___7quot; => “$1/default.jsp$2” )

This is visible at gra0.com and internally rewrites all requests from / to /default.jsp (including jsessionid and query string).


mod_rewrite can also be used to make URLs shorter. For example, to remove the ?page=comments query string, I use the following:

url.rewrite-once = (
“^/blog/(.*)\.html___FCKpd___8quot; => “/blog/$1.html?page=comments”
)

9. Redirecting requests


You can use mod_redirect to redirect the user to a different URL. Contrary to mod_rewrite where the request is rewritten, a 301 permanent redirect will be sent to the browser.


In this example, I’m redirecting requests to an old domain to a new domain:

$HTTP[“host”] == “olddomain.com” {
url.redirect = (
“^/(.*)___FCKpd___9quot; => “http://newdomain.com/$1”
)
}

10. More things to be aware of



  • The only IP address in your application server log files should be 127.0.0.1. If you need the original address, log the X-FORWARDED-FOR header.
  • Don’t analyze both lighttpd and application server logs – lighty’s log files already contain all requests.
  • You might want to set up virtual hosts sooner or later.
  • Use mod_expire to make resources cacheable. Doing so can make your site a lot faster and save you money.

Freez 3GP Video Converter







Freez 3GP Video Converter is a 3GP-converting tool for mobile phone users. With Freez 3GP Video Converter, you can convert batches of video files to 3gp, 3g2 formats to be played on mobile phones.

Freez 3GP Video Converter supports most popular video formats to be converted to 3gp video, including AVI, DivX, Xvid, MPEG 1/2/4, VOB, WMV, ASF, MP4, MOV, RM, RMVB, Flv, SWF etc. You can create both 3GPP and 3GPP2 video files. The output video codecs include MPEG4, XVID and H263; the audio codecs include AMR-NB and AAC-LC. You can set the video size, quality, framerate, audio bitrate, frequency, and channel. And there are two zoom modes: Stretch and Letterbox, which will add black letterbox on output video to keep aspect ratio.

Freez 3GP Video Converter is easy-to-use, fast and creates good quality. Have fun with it!


 

DOWNLOAD HERE: http://www.smallvideosoft.com/downloads/freez_3gpconverter.exe