版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、WebLogic性能调优第1页,共50页。调优通常应用系统会根据用户数、并发数、用户的行为等等来确定具体的性能目标,如果确定应用程序不能满足性能目标,那么就需要优化、重构程序并调整JVM、应用服务器、数据库、OS 或者改变硬件配置等等第2页,共50页。影响Java 性能的主要因素硬件,如CPU、内存、体系结构等等操作系统数据库系统JVM应用服务器数据库服务器网络环境应用架构及程序编写水平第3页,共50页。性能调整的步骤1、 使用工具测试系统是否满足性能目标2、 发现性能瓶颈3、 假设瓶颈的原因4、 测试你的假设5、 如果假设成立,更改这一部分6、 测试确定更改是否可以提高性能,衡量性能提高的程
2、度7、重复以上步骤,直到获得可以接受的性能。第4页,共50页。J2EE性能不好时的现象主要表现在对客户端的请求响应很慢:一向很慢:应用的响应总是很慢,改变环境(如应用负载、数据库的连接池数量等等),对响应时间的影响不大。越来越慢:在相同的负载情况下,随着系统运行的时间的增长,系统越来越慢,这可能是系统已到达极限或是系统死锁和错误引起的。低于负载时会越来越慢(Slower and slower under load):.偶尔的挂起或异常错误(Sporadic hangs or aberrant errors):有时这可能是由于负载的变化或其他情况引起的可以预测的死锁(Foreseeable lo
3、ck ups): 挂起或最初只有少量错误,但随着时间的推移整个系统都锁上了,典型地这可能是为的适应management by restarts.“突发性的混乱(Sudden chaos): 系统已运行了一段时间(如一个小时或可能是三、四天),性能稳定并可以接受, 突然没有任何理由,开始出错或死锁了。第5页,共50页。监控工具WebLogic Server的控制台cpu内存JDBC辅助的工具JprobeOptimizitVtuneTowerJ Performance第6页,共50页。J2EE 应用程序体系结构2003 BEA Systems, Inc. | 7Web ServerWL Plug-
4、In State DataDBMSEJBJDBCRMIJNDIJTA/JTSJMSJMXJIDLJavaMail State DataServletJSPPresentationLayerBusinessLayer* WLS Optional *Non-JNDIObjectsJNDIObjectsStatic ContentLayerDataLayerHardware/NetworkO/SJVMWebLogicServerJ2EE APIJ2EEApplication第7页,共50页。J2EE 应用程序中可能出现的瓶颈Application Code is explicitly managin
5、g threads and overusing sleep()Singleton class with synchronized statementPoor coding Application Serverrequest-handling threads enough?Garbage collectionDB connection pool numberDatabase serverShared dataUnnecessarily strict isolation levelsClient to app serverBusiness methods, remote garbage colle
6、ction, keep-alive trafficApp server to database DB access logic make I/O intensive第8页,共50页。如何优化J2EE应用程序?在开发阶段作优化构架和应用程序设计方面程序代码方面的优化对应用程序作单元测试发现应用程序存在的瓶胫部署方面的优化OS/JVM/Application ServerDatabase/Network作系统测试和基准测试发现系统级存在的瓶胫第9页,共50页。Common Sense在性能和灵活性之间寻找平衡点!80-20 principle: 20% of the code uses 80% r
7、esource.20% of the code executes 80% of the time.KISS law: Keep It Simple & Small!Use independent resources like poolsReduce unnecessary distribution and transactionsPush the multiple SQL statement operation to the DB level.第10页,共50页。尽量使用Pool资源Pool资源包括:JDBC Connection PoolSocket PoolObject PoolObjec
8、tPool (Class p_class, int size) Object getObjectFromPool()void returnObjectToPool(Object p_object)synchronized expandObjectPool()Thread Pool第11页,共50页。Servlet & JSPFor Servlet to Servlet calls, forward() 比 sendRedirect()性能要好一些 尽量避免跨越JVMs调用EJB,不要在一个JVM中调用其它JVM中的 EJBs尽量避免在Servlet/JSP中定界事务Servlets在缺省情况下
9、是单线程的,是线程不安全的如果使用单线程Servlet, 最好分配大量的Pool来处理服务请求最好使用 HttpSessions 来管理用户数据第12页,共50页。HttpSessionSession 管理会造成额外开销建议使用 setAttribute() 来保存粗粒度对象不要使用很大的 HttpSession 对象如果需要复制Session,把session的大小限制在 2-3KB以内在session对象上使用KISS原则尽量使用内存复制第13页,共50页。EJB 设计方面的考虑尽量创建粗粒度的 EJB , 不要太粗,粗到能满足实际需求就可以使用Session bean作为entity b
10、ean 的前置(Filter entity beans behind a session bean).When relationship between 2 business entities is structural, model it inside entity bean.When modeling external relationships, use stateless session bean outside entity bean. 避免EJB之间相互调用如果所有对EJBs的调用都是remote的, 请把 enable-call-by-reference 设置为 true第14页
11、,共50页。Entity Beans 设计方面的考虑尽量使用 Read-Mostly and Read-Only Entity beans,遵守small & simple的原则, WLS会对只读EJB设置 cache.Set isModified() to true when state is changed like ejbRemove(), ejbActivate(), ejbPassivate().Set isModified() to false when using CMP with ejbLoad(), ejbStore().Code ejbFindByPrimaryKey to
12、 return the primary key,e.g. String ejbFindByPrimaryKey(String pk) return pk; Use db-is-shared第15页,共50页。Entity Beans 设计方面的考虑并发策略(Concurrency strategy) is defined as how the locks for an entity bean are managedIn WLS 6 there are 3 caching strategies of tag in the weblogic-ejb-jar.xml file).Exclusive
13、(WLS5.1): hold a exclusive LOCK in WLS per PrimaryKeyDatabase (Default in WLS 6): DBMS hold the LOCKsRead Only : optimizied for read only entity bean, similar to ExclusiveObject-by-value : 直接使用set/get 方法操作 EntityBean 的代价太高,使用一个Java对象作为缓冲区来保存字段值,来更新 entity bean尽量不要提供 FindAll() 方法,因为它的实现代价太大如果只有一个很小的数
14、据子集被经常改变,可以当作JDO来处理,而不是当作Entity Bean来处理.尽量使用 bean-independent 的资源.第16页,共50页。Entity Beans 设计方面的考虑避免连接多个表创建BMP EJBUse Stored Procedures for certain types of BMPUse Database Views to simulate multi-table classUse 3rd party tools such as TopLink for O/R mappingConsider TX Supports vs TX Required ,事务会造成很
15、大的额外开销,适当考虑适当使用可以把TX 隔离级别设置为 Optimistic Locking考虑使用 javax.ejb.SessionSynchronization 接口提供在Rollback之后恢复数据的方法: afterBegin(), beforeCompletion(), afterCompletion().Automatical called by container (JTS/JTA impl.)第17页,共50页。JMS 设计方面的考虑考虑尽量使用更多的Destination, 而不是少量地使用考虑尽量使用Message Driven Beans to process.考虑在
16、 Persistence 和 Non-Persistence之间平衡Consider Transactional vs. Non-Transactional Message考虑合理使用 Auto Acknowledgements 、 non和 Duplicates OK考虑合理使用 Topics 的Multicast feature考虑使用多个JMS server,减少第个 Topics支持的 subscribers数量This is a Tree-like approach as one JMS server subscribes to another on behalf of its pa
17、rtitioned subscribersSee第18页,共50页。关于事务如果可能,尽量使用 CMT with required attribute for update/create/delete database methodWith supports or NotSupported with read-only operation在设计EJB时,要适当考虑EJB的粒度Fine-grain trasactions cause excessive traffic between TM and RMCoarse-grain transactions may block clients acc
18、essing the same resources.Do NOT have transaction span multiple web requests. Use a faade session bean to wrap multiple methods in a transaction第19页,共50页。程序代码减少不必要的操作Object creations/allocationdata member initializationsychronized operationuse of expensive system servicesE.g. Date() harbors a substa
19、ntial amount of overhead,create a LazyDate(mSecs) cache date, update at set intervals 尽量使用buffer和cacheBuffer object reference for GC Use JSP cache, Servlet buffer (e.g. reponse.setBufferSize(int)Buffer I/O, StringBuffer vs Sring同步调用和锁的瓶胫understand synchronization bottlenecksdescribe synchronized Jav
20、a classes and their alternativesunderstand locking bottlenecks第20页,共50页。对象创建只在需要对象的区域内定义它. Allocation, and construction use cycles, and, may require garbage collection to do extra work. Reconstruction is the absolute worst situation! Dont fall back on C/C+ techniques.void f() int i;Date x = new Date
21、(); / Date x is constructed. / .outside the scope where./ . it is used.if (.) / Date object x only used here .void f() int i;.if (.) Date x = new Date();/ Date x is constructed./ .inside the scope where./. it is used ./ Date object x only used here .第21页,共50页。不要多次初始化一个对象public class X / member v is
22、initd twice private Vector v = new Vector( ); public X( ) v = new Vector ( ) public class Y / member v is initd once private Vector v = new Vector( ); public Y( ) Time to construct 100,000 objects第22页,共50页。Java 2中的垃圾回收Concept of strength of reachabilityStrongly reachableSoftly reachableWeakly reacha
23、blePhantomly reachableUnreachable2003 BEA Systems, Inc. | 23第23页,共50页。Java 2中的垃圾回收Phantom references are useful if cleanup activity is neededSoft References work well for images2003 BEA Systems, Inc. | 24 Use of reference queues GC is requ ired to clear all soft references before throwing OutOfMemor
24、y error Weak references are always collected第24页,共50页。使用对象易于垃圾回收void drawPanel() Panel pnl = null; if (sftRef = null) pnl = new Panel(); /* create a OR when neededsftRef = new SoftReference(pnl); /* put it into soft listelsepnl = (Panel) sftRef.get(); /* get OR from soft list/* */pnl = null; /* set
25、OR to null after use!第25页,共50页。Java IO 流 BuffersPlan ahead! Dont flush prematurelyBuffered FileOutputStream executes faster than Buffered FileWriter UnicodeFileWriter performs Unicode to Byte translationThis results in higher use overheadSeconds第26页,共50页。Buffered I/OWhich is more efficient? - Given
26、-PrintWriter pw = new PrintWriter( new BufferedWriter( new FileWriter(“junk.out”);printWriter.print(“one ” + i);-or-printWriter.print(“one ”);printWriter.print(i);第27页,共50页。String 和 StringBufferMany hidden pitfalls exist for the novice to intermediate programmers. String s = new String();long start
27、= System.currentTimeMillis();for (int i = 0; i10000; i+) s +=“a”;long stop = System.currentTimeMillis();StringBuffer s = new StringBuffer();long start = System.currentTimeMillis();for (int i = 0; i10000; i+) s.append (“a”);long stop = System.currentTimeMillis();第28页,共50页。HttpServletResponse 缓冲区publi
28、c void service(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException res.setContentType(text/html);ServletOutputStream out = res.getOutputStream();res.setBufferSize(20000);out.print(String 1);out.print(String 2);if (res.isCommitted()out.print(Oh well, buffering did not
29、 work);elseout.print(Buffering is working well);res.reset();out.print(Hello World);第29页,共50页。Sockets vs RMI No time limit No Disqualifications! Sockets The assembly language of distributed programming. RMI 易用,但代价太高!milliseconds第30页,共50页。同步调用瓶颈同步调用可能会导致瓶胫的产生:overusing synchronized classes when not ne
30、ededusing a synchronized class as an attribute of a larger object and the larger object handles the synchronization of the method callsusing synchronization for complex, long-running operations第31页,共50页。同步调用的例子2003 BEA Systems, Inc. | 32Example of Using a Synchronized Class Within a Larger Object:im
31、port java.util.Vector;public class Employees Vector names = new Vector();Employees() Object object = new Object();synchronized (object) names.add(Chris);names.add(Stephanie);synchronized String getName(int index) String name = (String) names.elementAt(index);return name;第32页,共50页。同步调用类Many commonly
32、used Java classes use synchronization, such as:java.lang.StringBufferjava.util.Calendarjava.util.Hashtablejava.util.Randomjava.util.StringTokenizerjava.util.Vectormany classes in the java.io package第33页,共50页。ArrayList 和 Vector20902080308030803070第34页,共50页。Hashtable 和. HashMap401200221511211551210481
33、160361第35页,共50页。锁产生的瓶颈锁可以用于协调多个操作对单个资源的更新.Locking mechanisms can take into account what needs to be done to the object, for example:the object is going to be read: read lockthe object is going to be written to: write lock由于同时只能有一个写锁,所以当一个线程拥有写锁时,其它线程只能被阻塞。第36页,共50页。死锁死锁是如何发生的:两个进程同时要求访问两个资源,其中每个进程锁定
34、一个资源,同时要求锁定另外一个资源。R2R1P1P2waiting for resourceholds resource第37页,共50页。死锁与锁定死锁,是我们要尽量避免的,因为它占用了资源,阻塞了线程的执行。下列情况都有可能导致死锁的发生:mutual exclusionhold and waitno preemptioncircular wait第38页,共50页。部署方面的调优步骤Bottom-Up StrategyTune OSTune JVMTune WLSTune DB LogicTesting PerformanceBack to step 1/2/3/4Tuning is e
35、ndless process, so set a goal for tuning!第39页,共50页。调整 OSUse performance pace to take advantages with native method.调整TCP参数为线程配置轻量级进程增加文件描述符的数量Need at least as many as the number of socket connections增加可使用的最大内存数量Some OS initialize the limit to 128Mb Max. Increase it.For NT/2000, use NT/2000 native I/
36、O to serve static pages.第40页,共50页。Tuning OS TCP/IPtcp_keepalive_interval 90000tcp_ip_abort_interval 60000tcp_ip_abort_cinterval 60000tcp_rexmit_interval_initial 3000tcp_rexmit_interval_min 3000tcp_rexmit_interval_max 10000tcp_conn_grace_period 500ip_ignore_redirect 1tcp_slow_start_initial 2tcp_conn_
37、hash_size 262144tcp_time_wait_interval 60000tcp_mss_max 6000tcp_fin_wait_2_flush_interval 16000ip_path_mtu_discovery 0tcp_conn_req_max_q 8096 (*)tcp_conn_req_max_q0 8096 (*)tcp_conn_req_min 1tcp_xmit_hiwat 65535tcp_recv_hiwat 65535tcp_cwnd_max 65534第41页,共50页。OS调整IO和内存Connection Backlog Bufferingwebl
38、ogic.system.acceptBacklog如果出现了 “connection refused”的消息,可以适当增大weblogic.system.acceptBacklog的值Operating System Tuningfile descriptors(ulimit), maximum memory available for a user process网络和硬件配置what is the available network bandwidth第42页,共50页。调整 JVM 使用本地线程支持的 JVM.Turn on the JIT (Just in Time Compiler)
39、For the Sun JVM, see the documentation for 1.3 Hotspot specificsAlways use native threads as opposed to green threadsTune the Heap for Garbage Collection (-ms and -mx)Large Heap allows for slower, but more infrequent GCSmall Heap allows for faster, but more frequent GCHeap larger than RAM will cause
40、 page swappingGoal is to find the midpoint that is acceptable for the applicationRedirect -verbosegc (or equivalent) to file to analyze GC occurrenceHeuristic! Full GC should take between 3 and 5 secondsConsult your JVM documentation for all options to control GC第43页,共50页。从console中调整 WLS 9/10From th
41、e console, click on a server, configuration, tuning. Client Certificate Enforced (Two way authentication).Login Timeout: 1000 msAccept Backlog: 50.Tunneling Client Ping: 45 seconds.Execute Threads: 150 threadsTunneling Client Timeout: 40 secondsEnable Native I/O第44页,共50页。Tuning WebLogic 8.1For JSP c
42、ompilation, use a faster compiler (jikes, sj)From Console, click on a Server, Configuration, CompilerFor Web Applications, set it in weblogic.xmlOptionally, set weblogic.jsp.precompile in web.xml根据CPU的占用情况,设置 Execute Thread CountToo many threads will cause too much context switchingToo little threads will cause CPU under utilization and waiting在15, MAXIMUM)之间找到一个合适的值如果Native-I/O is 被禁用, 调整 Percent Socket Readers有多少比例的执
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 山西晋中学市榆次区重点达标名校2026年初三下第二次月考数学试题含解析
- 山东省潍坊联考2026年初三下学期期初测试物理试题含解析
- 湖北省武汉市外国语校2026届初三下学期阶段性测评(期中)语文试题含解析
- 四川省高县2026届初三中考冲刺第二次考试英语试题试卷含解析
- 江西省九江市九江有色金属冶炼厂职工子弟校2026年中考适应性月考卷(四)英语试题含解析
- 江苏省无锡市锡山区天一实验校2026届初三大练习(一)英语试题含解析
- 挖机出租合同范本
- 急性昏迷应急预案(3篇)
- 第三单元 勇担社会责任
- 610 皮带式给料机
- 债务优化服务合同范本
- 胸腔穿刺知识培训课件
- 2025年公司代收款委托书(委托第三方代收款协议书范本)
- 家庭宽带网络知识培训课件
- 智慧树知道网课《幸福家庭建设》课后章节测试满分答案
- 明朝内阁制度解读
- 索尼摄像机HDR-CX180E说明书
- 索尼黑卡5说明书
- 智慧树知道网课《创业十步》课后章节测试答案
- 西门子楼宇自控系统基本培训
- 高中英语(人教版)选择性必修二词汇表默写
评论
0/150
提交评论