Performance engineering


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Eden Space: The pool from which memory is initially allocated for most objects. Survivor Space: The pool containing objects that have survived the garbage collection of the Eden space. Tenured Generation: The pool containing objects that have existed for some time in the survivor space. Permanent Generation: The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas. Code Cache: The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code. Survivor Space: The pool containing objects that have survived the garbage collection of the Eden space.
  • Performance engineering

    1. 1. Performance Engineering by Franz See (DevCon Java Roadshow) (ValueCommerce) [email_address]
    2. 2. UI Performance Page Loading Optimization
    3. 3. Best Practices <ul><li>Optimizing caching — keeping your application's data and logic off the network altogether </li></ul><ul><li>Minimizing round-trip times — reducing the number of serial request-response cycles </li></ul><ul><li>Minimizing request size — reducing upload size </li></ul><ul><li>Minimizing payload size — reducing the size of responses, downloads, and cached pages </li></ul><ul><li>Optimizing browser rendering — improving the browser's layout of a page </li></ul>
    4. 4. Optimize caching HTTP caching allows these resources to be saved, or cached, by a browser or proxy. Once a resource is cached, a browser or proxy can refer to the locally cached copy instead of having to download it again on subsequent visits to the web page. Thus caching is a double win: you reduce round-trip time by eliminating numerous HTTP requests for the required resources, and you substantially reduce the total payload size of the responses. Besides leading to a dramatic reduction in page load time for subsequent user visits, enabling caching can also significantly reduce the bandwidth and hosting costs for your site.
    5. 5. Optimize caching <ul><li>Leverage browser caching - Setting an expiry date or a maximum age in the HTTP headers for static resources allows the browser to load previously downloaded resources from local disk rather than over the network. </li></ul><ul><li>Leverage proxy caching - Enabling public caching in the HTTP headers for static resources allows the browser to download resources from a nearby proxy server rather than from a remoter origin server. </li></ul>
    6. 6. Minimize round-trip times Round-trip time (RTT) is the time it takes for a client to send a request and the server to send a response over the network, not including the time required for data transfer. That is, it includes the back-and-forth time on the wire, but excludes the time to fully download the transferred bytes (and is therefore unrelated to bandwidth). For example, for a browser to initiate a first-time connection with a web server, it must incur a minimum of 3 RTTs: 1 RTT for DNS name resolution; 1 RTT for TCP connection setup; and 1 RTT for the HTTP request and first byte of the HTTP response. Many web pages require dozens of RTTs.
    7. 7. Minimize round-trip times <ul><li>Minimize DNS lookups - Reducing the number of unique hostnames from which resources are served cuts down on the number of DNS resolutions that the browser has to make, and therefore, RTT delays. </li></ul><ul><li>Minimize redirects - Minimizing HTTP redirects from one URL to another cuts out additional RTTs and wait time for users. </li></ul><ul><li>Combine external JavaScript - Combining external scripts into as few files as possible cuts down on RTTs and delays in downloading other resources. </li></ul>
    8. 8. Minimize request size Every time a client sends an HTTP request, it has to send all associated cookies that have been set for that domain and path along with it. Most users have asymmetric Internet connections: upload-to-download bandwidth ratios are commonly in the range of 1:4 to 1:20. This means that a 500-byte HTTP header request could take the equivalent time to upload as 10 KB of HTTP response data takes to download. The factor is actually even higher because HTTP request headers are sent uncompressed. In other words, for requests for small objects (say, less than 10 KB, the typical size of a compressed image), the data sent in a request header can account for the majority of the response time.
    9. 9. Minimize request size <ul><li>Minimize cookie size - Keeping cookies as small as possible ensures that an HTTP request can fit into a single packet. </li></ul><ul><li>Serve static content from a cookieless domain - Serving static resources from a cookieless domain reduces the total size of requests made for a page. </li></ul>
    10. 10. Minimize payload size The amount of data sent in each server response can add significant latency to your application, especially in areas where bandwidth is constrained. In addition to the network cost of the actual bytes transmitted, there is also a penalty incurred for crossing an IP packet boundary. (The maximum packet size, or Maximum Transmission Unit (MTU), is 1500 bytes on an Ethernet network, but varies on other types of networks.) Unfortunately, since it's difficult to know which bytes will cross a packet boundary, the best practice is to simply reduce the number of packets your server transmits, and strive to keep them under 1500 bytes wherever possible.
    11. 11. Minimize payload size <ul><li>Enable gzip compression - Compressing resources with gzip can reduce the number of bytes sent over the network. </li></ul><ul><li>Remove unused CSS - Removing or deferring style rules that are not used by a document avoid downloads unnecessary bytes and allow the browser to start rendering sooner. </li></ul><ul><li>Minify JavaScript - Compacting JavaScript code can save many bytes of data and speed up downloading, parsing, and execution time. </li></ul>
    12. 12. Minimize payload size <ul><li>Defer loading of JavaScript - Deferring loading of JavaScript functions that are not called at startup reduces the initial download size, allowing other resources to be downloaded in parallel, and speeding up execution and rendering time. </li></ul><ul><li>Optimize images - Properly formatting, sizing, and losslessly compressing images can save many bytes of data. </li></ul><ul><li>Serve resources from a consistent URL - It's important to serve a resource from a unique URL, to eliminate duplicate download bytes and additional RTTs. </li></ul>
    13. 13. Optimize browser rendering Once resources have been downloaded to the client, the browser still needs to load, interpret, and render HTML, CSS, and Javascript code. By simply formatting your code and pages in ways that exploit the characteristics of current browsers, you can enhance performance on the client side.
    14. 14. Optimize browser rendering <ul><li>Use efficient CSS selectors - Avoiding inefficient key selectors that match large numbers of elements can speed up page rendering. </li></ul><ul><li>Avoid CSS expressions - CSS expressions degrade rendering performance; replacing them with alternatives will improve browser rendering for IE users. This best practices in this section apply only to Internet Explorer 5 through 7, which support CSS expressions. </li></ul><ul><li>Put CSS in the document head - Moving inline style blocks and <link> elements from the document body to the document head improves rendering performance. </li></ul><ul><li>Specify image dimensions - Specifying a width and height for all images allows for faster rendering by eliminating the need for unnecessary reflows and repaints. </li></ul>
    15. 15. Tips and Tricks <ul><li>Remove all 404 resources. </li></ul><ul><ul><li>Access logs to check 404 resources. </li></ul></ul><ul><ul><li>grep 'HTTP/1.1&quot; 404' access.log </li></ul></ul><ul><li>Put CSS at the top, and CSS first before JS </li></ul><ul><ul><li>Put JS at the end of the page </li></ul></ul><ul><li>Set a reasonable buffer size for JSP for eager loading if possible divisible by 1500 bytes. <%@ page buffer=&quot;36kb&quot; %> </li></ul>
    16. 16. Tips and Tricks <ul><li>Enable GZIP using GZIP filter for text content types </li></ul><ul><ul><li>Pre GZIP Text static resources (Custom ant task) </li></ul></ul><ul><ul><li>Compress images </li></ul></ul><ul><ul><li>Page speed provides you with the compressed image </li></ul></ul><ul><ul><li> </li></ul></ul><ul><li>Minify JavaScript, CSS or even dynamic (JSP) contents </li></ul><ul><ul><li>YUI compressor from Yahoo! </li></ul></ul><ul><ul><li>Closure Tools from Google </li></ul></ul><ul><ul><li>Combining of external JavaScript and CSS resources </li></ul></ul><ul><ul><li>Custom ant tasks </li></ul></ul><ul><ul><li>CSS sprites </li></ul></ul><ul><ul><li> </li></ul></ul>
    17. 17. Tips and Tricks <ul><li>Browser caching using http header </li></ul><ul><ul><li>Cache-Control response header with at least one month expiration </li></ul></ul><ul><ul><li>Ideally for static resources, and can be done also on get Ajax calls </li></ul></ul><ul><ul><li>Caching of asynchronous call results (page scope) </li></ul></ul><ul><li>Progressive loading using Ajax </li></ul><ul><li>Deferred loading </li></ul>
    18. 18. Tips and Tricks <ul><li>Use performance analyzer tools </li></ul><ul><ul><li>Yslow! from Yahoo! </li></ul></ul><ul><ul><li>Page speed from Google </li></ul></ul>
    19. 19. Possible UI Performance Drawback <ul><li>Maintainability </li></ul><ul><ul><li>Support for JavaScript debugging is now impossible </li></ul></ul><ul><ul><ul><li>Minify JavaScript and CSS resources </li></ul></ul></ul><ul><ul><ul><li>Combining of external JavaScript and CSS resources </li></ul></ul></ul>
    20. 20. References <ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul>
    21. 21. Back End Performance Engineering
    22. 22. Problems? Slow down Out of Memory
    23. 23. What are they? Profiler A form of Dynamic Program Analysis for Improving performance Heap Analysis Tool Tool for analyzing heap dumps
    24. 24. Example
    25. 25. Example
    26. 26. Example
    27. 27. Popular Profiling Tools <ul><li>Paid </li></ul><ul><ul><li>JProfiler </li></ul></ul><ul><ul><li>YourKit </li></ul></ul><ul><li>Free </li></ul><ul><ul><li>Eclipse TPTP </li></ul></ul><ul><ul><li>Netbeans Profiler </li></ul></ul><ul><ul><li>Visual VM (comes with java 6u7) </li></ul></ul>
    28. 28. Popular Heap Analysis Tools <ul><li>Jhat </li></ul><ul><li>Eclipse Memory Analyzer Tool </li></ul><ul><li><Profiling tools> </li></ul>
    29. 29. Common Profiling Views Self Tree Telemetry CPU Duration Per Method Call Tree CPU Load Memory Size per object of type Dominator Tree Memory Load Thread Duration per thread (---) (---)
    30. 30. Heap Analysis <ul><li>Quick recap of the Java Memory Model </li></ul><ul><li>Learning to generate heap dumps (hprof) </li></ul><ul><li>Setting up the Eclipse Memory Analyzer Tool </li></ul><ul><li>The 3 basic reports – Overview, Leak Suspects, and Top Components </li></ul><ul><li>The 'other' features </li></ul>
    31. 31. Java Memory Model <ul><li>Heap </li></ul><ul><ul><li>Young GEn </li></ul></ul><ul><ul><ul><li>Par Eden Space </li></ul></ul></ul><ul><ul><ul><li>Par Survivor Space </li></ul></ul></ul><ul><ul><li>CMS Old Gen </li></ul></ul><ul><li>Non-Heap </li></ul><ul><ul><li>Code Cache </li></ul></ul><ul><ul><li>CMS Perm Gen </li></ul></ul>More info: ... ...technotes/guides/management/jconsole.html
    32. 32. Generate HPROF <ul><li>-XX:+HeapDumpOnOutOfMemoryError </li></ul><ul><li>jmap -heap:format=b <pid> </li></ul><ul><li>jmap.exe -dump:format=b,file=HeapDump.hprof <pid> </li></ul>More info :
    33. 33. Setup Eclipse MAT <ul><li>Home Page : </li></ul><ul><li>Download Page : </li></ul><ul><li>Quick Start: </li></ul>
    34. 34. 3 Basic Reports <ul><li>Overview </li></ul><ul><li>Leak Suspects </li></ul><ul><li>Top Components </li></ul>
    35. 35. <ul><li>The 'other' features. </li></ul><ul><li>Histogram </li></ul><ul><li>Dominator Tree </li></ul><ul><li>OQL </li></ul>
    36. 36. OQL
    37. 37. Histogram
    38. 39. Last Tips & Tricks 1.) Premature Optmization is the source of all evil 2.) Validate Assumptions 3.) Avoid blind fixes as much as possible 4.) Differentiate between CPU & IO 5.) Work Together
    39. 40. Thank You Questions? [email_address]