- 浏览: 748218 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
hsl313:
源码还有得下载吗?
利用AMF数据封装与Flash 进行Socket通讯 -
zhang5476499:
已看,谢谢讲解。
Mock单元测试 -
Buydeful:
...
关于JSP或HTML的命名规范 -
lliiqiang:
单一登陆最好采用踢掉方法,如果忘记退出,可以从别的地方控制方式 ...
Jquery选择器大全 -
lliiqiang:
web代码由后台动态生成,这种动态方式多种多样,多提供几种标准 ...
Jquery选择器大全
http://www.ibm.com/developerworks/web/library/wa-aj-perform/
An Ajax application's performance is based on several aspects of a Web application:
- Server response time
- Network transfer time
- Client JavaScript processing time
In traditional Web application development, server response time is the primary focus for performance analysis. Most performance analysis measures the application server's ability to quickly handle requests, carry out necessary application logic, and generate a response. In Ajax application development, this is still a critical aspect of the application's performance but is generally well understood, so this article focuses on the other parts of performance
To understand what aspects of a Web application you need to improve, you must properly analyze the components of the application. This article looks at how you can use the Firebug extension to Firefox and the YSlow add-on to instrument a Web application. After you install these tools, connect to the site that you are developing and click YSlow on the Firefox status bar. This opens the YSlow interface in Firebug. Now click the Performance button. YSlow performs an analysis of your application and provides a report on the different parts of the network transfer time of your application
In most Web applications, network transfer time is the biggest bottleneck. With a YSlow report, you can analyze the different aspects of the network transfer to understand what can be done to decrease the transfer time.
Every HTTP request requires some time for the request to be sent to the server and the response to be retrieved. Even when responses are small, there is still the baseline roundtrip time, which is referred to as latency. YSlow provides a grade based on how many HTTP requests are made. A large number of requests results in significantly slower load times. You can reduce HTTP requests by simplifying the page so that fewer components need to be loaded. You can reduce image requests by using CSS sprites. Tools that generate CSS sprites are available (see the Resources section). To reduce script and CSS requests, include them inline in the page or combine multiple scripts or CSS files together.
You can reduce HTTP requests by providing HTTP cache expiration headers with future dates that allow browsers to cache components. It is important that as a user navigates from page to page, or returns to visit your site, that components can be cached and do not need to be downloaded each time your site is visited. Proxies can also cache frequently loaded content if proper expiration headers are provided. An expiration header looks like this:
Expires: Wed, 10 Mar 2009 10:00:00 GMT
Remember that if you use far future expiration dates, browsers will still cache your content even when you have changed it. You may want to reduce the expiration to a day in the future. You can also change filenames when you version them so that new URLs are requested when a new version is released, and the browser has to make a new request. You can configure Apache to add expiration headers with an ExpiresDefault
directive:
ExpiresDefault "access plus 10 years"
With YSlow, you can also look at the total download size of your page by clicking the Stats button. YSlow shows the size of the page for a first-time visitor (with nothing cached) and for subsequent page visits (when caching can be used).
HTTP requests can involve more than a just a roundtrip to your server. If there are multiple host or domain names used by resources, the browser may need to do additional Domain Name System (DNS) lookups. YSlow alerts you if multiple names must be looked up. However, it is important to note that multiple DNS names can actually be a performance benefit as well. Most browsers only allow two connections per host name. But with multiple host names, more connections -- and consequently, more concurrent downloading -- can take place.
Reducing the size of component transfers
In addition to reducing the number of HTTP requests, it is also advantageous to reduce the size of the components that are requested. Techniques can be applied to compress certain formats. YSlow indicates what techniques can be successfully applied to reduce response size.
You can shrink JavaScript code, CSS, and HTML by eliminating unnecessary whitespace and comments. You can further compress JavaScript code by renaming variables. Packer and YUI compressor are effective tools for JavaScript compression, and YUI compressor supports CSS compression as well. You can compare minifiers with The JavaScript CompressorRater (see the Resources section).
One of the most effective ways to compress resources is by enabling gzip (short for GNU zip) for text-based resources. Using gzip, you can generally reduce content size by about 70%. Do not use gzip to compress resources that are already compressed, such as images and movies. Good candidates for gzip include CSS, HTML, JavaScript code, XML, and JavaScript Serialized Object Notation (JSON). Apache 1.3 supports gzip with mod_gzip
and Apache 2.0 uses mod_deflate
.
Not only is it important to minimize the size of HTTP responses in terms of resource size, but it is also important to minimize the size of HTTP requests. For many Internet users, upload speeds can be significantly slower than downloads, and so performance can be more sensitive to request size. Large URLs, large post data, and excessive headers can also increase the size of a request. In Firebug, you can go to the Net tab to view your requests, as Figure 2 shows. For each request, you can expand the request to see the request headers. One of the most common sources of unnecessarily large header sizes is large cookies. Cookies are included in the header on every request, and, therefore, large cookies add a lot of extra overhead.
Java™ 2 Platform, Enterprise Edition (J2EE) applications can apply several of these performance improvements (caching expiration date, gzip, and JavaScript compression) with a simple filter called Resource Accelerate. You can also use the pack:tag JavaServer Pages (JSP) tag library to compress resources. There are other options for different technologies. See the Resources section for more information.
Other network transfer performance improvements
Another YSlow recommendation is to use a content delivery network (CDN). A CDN provides a distributed network of servers with content that is closer to your end users for faster response times.
You can also improve the speed of rendering your Web pages by properly ordering your CSS and scripts. YSlow analyzes the position of your CSS and script declarations to provide information on how to improve the ordering. It is recommended that CSS declarations be at the top of the page so the CSS can immediately be used for rendering, and the scripts be at the bottom of the page so the page can render before loading the JavaScript code for interaction.
After your Web page is successfully generated by the server and transferred to the browser, Ajax applications generally rely on JavaScript code for interactivity with the user. Most users are prepared to wait a little while for a page to fully download, but quality interaction depends on rapid feedback, so quick response to various components on your page can be the most important aspect of an enjoyable user experience. Also, browsers are usually still responsive when waiting for resources to download, but if JavaScript code is executing continuously, it can completely lock up the browser.
Firebug comes with a profiling tool. To use the profiler, go to the Console tab and click Profile to start the profiler. It may help to understand what part of your Web application makes heavy use of JavaScript code. The profiler also yields more accurate results if you can repeat the activity you are testing several times. For example, if there is a significant amount of JavaScript code that is executed when the page loads, you may want to do several page loads. If there are JavaScript hover event handlers, you may want to move the mouse around the page for a while to let the profiler collect a decent amount of information. When you finish your activity, you can click the Profile button again to display the profile results, as Figure 3 shows.
The profile result lists all the function calls that took place during the profile. Each entry shows the number of times that the function was called and statistics on the processing time for the function call. There is a Time column that indicates the total amount of time spent waiting for the function to return, and there is an Own Time column that indicates the total amount of time spent waiting for the function to return minus the time the function spent waiting for calls it made to return. Own time is generally the most important time because it represents where the majority of the expensive processing is taking place, and this time is what the values in the Percent column are based on. By default, Firebug sorts on the Percent column, with the highest values at the top. This is a convenient way to read the profile because the most expensive calls are on top, and you can focus your efforts on improving the performance of these functions. With Firebug, it is easy to go to the function source; you can simply click on the entry in the list to go to the function.
When evaluating the performance of your JavaScript functions, it is also important to note the number of times the function was called. If it is called a large number of times, the function itself may not necessarily be slow (you can see the average processing time for the function), but it may simply be called too frequently. Sometimes poor performance can be a result of a function being used more frequently than expected. Hover event handlers such as onmousemove
often produce a large number of events.
If you can determine that a certain function is taking an excessive amount of time in processing, you may want to look at your JavaScript code for possible problems. Table 1 lists some JavaScript operations that are known to be slow. For more information about benchmarks, see the Resources section.
Table 1. Slow JavaScript operations
Interaction with the DOM is usually slower than normal JavaScript code. Interaction with the DOM is usually inevitable, but try to minimize it. For instance, dynamically creating HTML with strings and setting the innerHTML is usually faster than creating HTML with DOM methods. |
Whenever possible, avoid the eval method because significant overhead is involved in script evaluation. |
Using with statements creates additional scope objects that slow variable access and create ambiguities. |
Traverse arrays use the traditional for (var i=0; i<array.length;i++) instead of for-in loops. Unfortunately, most JavaScript environments have a slow implementation of for-in loops. |
Firefox with Firebug and YSlow is certainly the best choice for profiling. For Safari on Mac OS X, you can also use Web Inspector to analyze HTTP requests. For JavaScript performance profiling, you can use manual techniques to gauge the performance of certain functions. To instrument a function manually, you can measure the execution time with the Date
function, as Listing 1 shows:
function myFunctionToTest() { var start = new Date().getTime(); ... // body of the function var totalTime = new Date().getTime() - start; }
One particular problem that can plague performance is the poor memory management of Windows® Internet Explorer®. Unpatched Internet Explorer 6 and prior versions exhibit progressively slower behavior as more objects and properties are created. As a general rule, if you have more than 5000 objects, old versions of Internet Explorer will be considerably slower.
Using Firebug and YSlow, you can thoroughly analyze your Web applications to make educated changes to improve performance. YSlow provides detailed information to assist in reducing network transfer times. Firebug provides detailed JavaScript profiling analysis to determine critical areas of code to improve. Together, these tools can help you build Web applications with performance that provides the highest level of user experience.
发表评论
-
转:Node.js 究竟是什么?
2011-09-05 09:19 1002简介 如果您听说过 ... -
Cache Insight
2011-05-25 17:31 1223http://www.iteye.com/topic/2172 ... -
Asynchronous innerHTML
2009-06-02 10:39 1089A recent question on Stack Over ... -
Fastest way to build an HTML string
2009-06-02 10:28 1152You have a massive array of ite ... -
JS字符串加不同浏览器比较
2009-05-06 09:03 1856function StringBuffer() { ... -
kestrel项目
2009-05-02 01:58 1563kestrel项目,用于MQ,twitter实现 scala语 ... -
Tomcat6安装版本参数修改
2009-04-14 13:41 1516tomcat6w.exe //ES//Tomcat6 -Xr ... -
jvm之JSTAT
2008-12-23 16:02 2985http://java.sun.com/javase/6/do ... -
jvm之JPS
2008-12-23 10:45 1652PARAMETERS options ... -
jvm之JSTATD
2008-12-23 10:26 2612PARAMETERS options ... -
JVM监控工具介绍
2008-12-15 10:43 2994http://hqman.iteye.com/blog/167 ... -
java6性能
2008-12-10 10:55 1697J2SE 6(代号:Mustang野马 ... -
ApacheBench测试工具使用指南
2008-12-01 15:46 2267服务器负载太大而影响程序效率也是很常见的,Apache服务器自 ... -
关于fastcgi的一些摘录
2008-12-01 14:17 1495原讨论帖:http://www.iteye.com/topic ... -
基于等待的性能调优
2008-11-20 12:40 1092性能调优曾经是“艺术性”多于“科学性”,但是通过结合抽象分析和 ... -
Web 图片服务器
2008-08-25 14:11 2968http://www.yatan.com/group/topi ... -
图片加速
2008-08-18 11:43 1907不要GZIP图片,设置Cache 图片已经是压缩保存了的,GZ ... -
HashMap和List的线程安全
2008-03-24 08:54 4620Map m =Collections.synchronized ... -
HTTP协议:304
2008-01-24 17:59 5932var r = new XMLHttpRequest(); ... -
【摘录】缓存
2008-01-21 10:37 1446robbin: 1、对象缓存 Java ...
相关推荐
内容包括:Application Architecture Analysis、Creating the Data Model、Design Database Schema、Programming Stored procedures、Web Application Design、App Setting、 Log in Design、 Security、 ...
内容包括:Application Architecture Analysis、Creating the Data Model、Design Database Schema、Programming Stored procedures、Web Application Design、App Setting、 Log in Design、 Security、 ...
内容包括:Application Architecture Analysis、Creating the Data Model、Design Database Schema、Programming Stored procedures、Web Application Design、App Setting、 Log in Design、 Security、 ...
内容包括:Application Architecture Analysis、Creating the Data Model、Design Database Schema、Programming Stored procedures、Web Application Design、App Setting、 Log in Design、 Security、 ...
内容包括:Application Architecture Analysis、Creating the Data Model、Design Database Schema、Programming Stored procedures、Web Application Design、App Setting、 Log in Design、 Security、 ...
8. **Performance Center**(仅限高级版):对于大型企业,LoadRunner Performance Center提供了一个集成的平台,用于计划、执行和监控性能测试,并进行团队协作和报告。 9. **TruClient Protocol**:LR9.0引入了...
He specializes in large-scale Web sites, distributed computing, transactional systems, and performance analysis. Bowen has been an architect and developer for more than 15 years at companies such as ...
With the surge of unstructured customer feedback data, manual analysis is inefficient, necessitating the automatic extraction of key information from such non-structured text data using artificial ...
Python\OReilly Social Network Analysis for Startups.mobi Python\Packt Django 1.1 Testing and Debugging.mobi R\NoStarch The Art of R Programming.mobi R\OReilly Data Mashups in R.mobi R\OReilly Machine ...
6. **报表和统计分析**: The system should generate reports and conduct statistical analysis to help managers understand usage patterns, identify trends, and make informed decisions regarding vehicle ...
- **Caching Strategies:** Implementing caching at various levels (e.g., database queries, pages, fragments) can significantly improve performance. - **Load Balancing:** Distributing incoming network ...
- **Analysis**: 数据分析工具,展示测试结果,帮助识别性能瓶颈。 - **Runner Agents**: 分布式运行Vuser的进程,可部署在多台机器上以实现大规模并发。 3. **脚本录制与编辑** - **LR脚本语言**: LR支持LR VU...
Version 6.0 gives developers the ability to add error bars to bar charts, which offers additional statistical information regarding the data on the chart for more in depth analysis. (Part of the ...
创建于: 许可证: 谢谢: 灵感: Brendan Gregg的参考实现马克·普莱斯(Mark Price)的分析结果可视化依存关系:(仅测试代码)(仅测试代码) Jasmine-Ajax (演示仅在文档/表示) reveal.js 可视化效果: 火焰...
西蒙 直观的可远程访问的系统性能监视和任务管理工具,用于服务器和无头Raspberry Pi设置 好消息! ...异步定期AJAX调用的简化实现以获取信息 统计期间服务器的开销相对较低(在Python 3运行时使用
8. **Performance Optimization**:考虑到音频处理可能消耗大量资源,优化策略如使用流式加载、预加载、音频缓冲等技术可以提高用户体验。 9. **Error Handling**:处理加载失败、解码错误等异常情况,确保程序的...