Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Threading Essentials course
Tips March 2004
Get rid of your performance problems and memory leaks!
Get rid of your performance problems and memory leaks!
Back to newsletter 040 contents
The Commando Pattern (Page last updated March 2004 , Added 2004-03-31, Author Jack Shirazi, Publisher JavaPerformanceTuning.com). Tips:
- The Commando pattern provides specialized optimized access to data variables and methods.
Why Capacity Planning Is Seldom Done Well (Page last updated February 2004 , Added 2004-03-31, Author Rich Schiesser, Publisher informIT). Tips:
- Assign individuals to a group to be responsible for capacity planning.
- Capacity management is a tactical activity that focuses on the present. Capacity planning is a strategic activity that focuses on the future.
Webserver + Application server configuration (Page last updated December 2003, Added 2004-03-31, Author Akash Kava, Publisher developer.com). Tips:
- Use the webserver to deliver any static content.
- Use the webserver as a proxy for the application server for dynamic content, and use webserver performance optimizations like keep-alive, compression, caching and content expiration.
Client-Side Cache Control Servlet Filter (Page last updated March 2004 , Added 2004-03-31, Author Jayson Falkner, Publisher OnJava). Tips:
- Use the HTTP response header Cache-Control, to cache unchanging data (images, etc) on the client.
- Specify timeout and other parameters of the Cache-Control header to reduce requests sent to the server.
- [Article implements a cache control servlet filter].
- Client-side cache manipulation can benefit the perceived performance of most web applications.
- Client-side caching using the Cache-Control header is one end of the spectrum of HTTP caching, it is most optimal since it prevents both the request and the response download; using the if-modified-since header to indicate the browser version of the content is valid doesn't prevent the request being sent to the server, but avoids the download of the content; caching content in a servlet filter gets both the request and response download, but does avoid regenerating dynamic content.
- An HTTP server can only handle the processing of a certain number of requests, regardless of how much content is being returned per request.
- If you are expecting to get optimal performance from your web server, it is important to avoid unneeded HTTP requests.
Data Structures (Page last updated October 2003, Added 2004-03-31, Author Scott Mitchell, Publisher Microsoft). Tips:
- The data structures used for a particular algorithm can greatly impact its performance. For example, finding an element in a collection: arrays take time proportional to the number of elements (linear time); binary search trees and SkipLists have sub-linear search times.
- When searching large amounts of data, the data structure chosen can make a difference in the application's performance that can be visibly measured in seconds or even minutes.
- Asymptotic analysis examines how the efficiency of a data structure changes as the data structure's size approaches infinity. The notation commonly used in asymptotic analysis is called big-Oh notation. The big-Oh notation to describe the performance of searching an array would be denoted as O(n). The large script O is where the terminology big-Oh notation comes from, and the n indicates that the number of steps required to search an array grows linearly as the size of the array grows. [Article briefly covers asymptotic analysis].
- Searching a sorted array can be done efficiently using a binary search to search the array in O(log n) running time, which is on par with the search times for binary search trees.
- Boxing and unboxing (as available with Java 1.5) can hamper the performance of your application.
The Queue, Stack, and Hashtable (Page last updated November 2003, Added 2004-03-31, Author Scott Mitchel, Publisher Microsoft). Tips:
- When adding data to a hash table, a collision reduces efficiency. The frequency of collisions is directly correlated to the hash function used and the distribution of the data being passed into the hash function.
- A load factor above 0.72 may degrade performance.
- Expanding a Hashtable is expensive so you should set the Hashtable's initial capacity so as to avoid unnecessary expansions.
Binary Trees and BSTs (Page last updated January 2004, Added 2004-03-31, Author Scott Mitchell, Publisher Microsoft). Tips:
- Both looking up an element and searching a binary tree takes linear time, as potentially all nodes need to be examined.
- By intelligently organizing the items in a binary tree, we can greatly improve the search time (and therefore the lookup time as well).
- A binary search tree (BST, e.g. java.util.TreeMap) is a special kind of binary tree designed to improve the efficiency of searching through the contents of a binary tree. BSTs exhibit the following property: for any node n, every descendant node's value in the left subtree of n is less than the value of n, and every descendant node's value in the right subtree is greater than the value of n. Hence a BST can be searched by eliminating half the remaining subtree at each node.
- Ordinary binary search tree efficiency depends on the element insertion order. Some orders provide a more balanced tree than others (a balanced tree has a good ratio of breadth to depth). Self balancing trees strive to maintain balance in the tree structure (e.g. java.util.TreeMap which is a red-black self-balancing binary search tree).
Better Binary Search Tree (Page last updated February 2004 , Added 2004-03-31, Author Scott Mitchell, Publisher Microsoft). Tips:
- [Article discusses AVL and Red-Black self balancing binary search trees].
- Linked lists have linear search times, like arrays, but constant insertion time. Sorted linked lists have linear insertion time.
- The primary peformance benefit of linked lists is that adding or removing items does not involve time-consuming re-dimensioning.
- Skip lists are linked lists with extra pointers between some non-adjacent nodes, allowing faster traversal. Skip lists show O(log(n)) running time for insertions, deletions, and lookups.
Concurrent Programming (Page last updated February 2004 , Added 2004-03-31, Author Cameron Hughes & Tracey Hughes, Publisher Addison Wesley). Tips:
- [Basic but thorough introduction to concurrency].
Performance Forensics (Page last updated February 2004 , Added 2004-03-31, Author Bob Sneed, Publisher Prentice Hall). Tips:
- Resolution of a performance issue can involve tuning, bug fixing, upgrading, product enhancement, or re-architecting the entire solution, but first there needs to be a working diagnosis.
- Performance business requirements has three principle categories: Performance (e.g. transactions per unit time, time per transaction, ...); Predictability (average response time may be insufficient if outliers are long enough to result in complaints of user-perceived outages); Price (Given an unlimited budget for time, equipment, and people, most business goals can be met). These three factors correlate directly with the famous engineering axiom: "Good, Reliable, Cheap?pick any two."
- It can be wasteful to optimize factors that produce no gains in business terms.
- The degree to which a workload can be skewed by monitoring depends on the intrusiveness of the tools being used and the degree to which they are used
- Types of performance monitoring are: Health monitoring (establishing norms for a workload and using them to detect when operations become abnormal); Capacity planning (gathering data to help forecast when additional capacity will be needed); Gaining insight (discovering opportunities for optimization or formulating hypotheses for making high-level architectural decisions); Diagnosing (accurately discovering the root cause of a performance problem).
- The practical difference between a 95 percent cache hit rate and a 96 percent cache hit rate is 20 percent! Cache miss rate, not hit rate, is the important factor, because miss rate is what imposes work on the application.
- one possible process-oriented high-level strategy for performance diagnosis: Is the system correctly configured; Have appropriate best practices been applied; Has appropriate research into candidate bugs been performed, and have the appropriate patches and updates been applied; Is the performance complaint based on reasonable expectations and valid experiment design, backed by good science; If a resource is saturated, can more resources be added, or are there options to decrease demand; What resources are under contention; Where is the time going; Why is the time going wherever it is going?
- A simple three-step strategy applicable to tuning is: Is the system working or waiting for something? If it is working, is it working intelligently and efficiently? If it is waiting, can the thing it is waiting for be made faster, or can you decrease dependence on that thing?
- 80 percent of performance complaints can be traced back to deviations from known best practices. Examine configuration parameters to determine if non-standard configurations are being used.
- Ensure that known bugs have been patched.
- Make a preliminary assessment that the problem is real, and establishing realistic expectations regarding performance goals.
- The general categories of root causes for computer performance issues are: Bad algorithms; Resource contention; Serialized execution (instead of paralellized execution); Latency effects; Hardware failures; Common inefficiencies, i.e. doing unnecessary work (e.g. memory leaks, repeatedly evaluating the length of a string, poorly chosen buffer sizes, too much time spent managing memory); Esoteric inefficiencies, e.g. very low level system issues.
- Be fully familiar with the logging capabilities of various components, and fully aware of how they are configured.
- Beware that the rate of diagnostic logging, the size of a log file, or contention for log file writing can easily b the root cause of a broader performance issue.
- [Article briefly covers ps, vmstat, mptstat, netstat, prstat, iostat, truss, lockstat, kstat, trapstat, busstat, cpustat, cputrack].
Back to newsletter 040 contents
Last Updated: 2020-12-28
Copyright © 2000-2020 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us