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: Concurrency, Threading, GC, Advanced Java and more ...
Tips August 2005
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 057 contents
http://weblogs.java.net/blog/kirillcool/archive/2005/07/how_to_create_s.html
Scalable icons with Java2D (Page last updated July 2005, Added 2005-08-29, Author Kirill Grouchnikov, Publisher java.net). Tips:
- [Article shows how to draw a graphic icon of any required size rather than use a set of packaged pre-sized icons or re-sizing a graphic].
http://weblogs.java.net/blog/jfarcand/archive/2005/06/grizzly_an_http.html
Grizzly: An HTTP Listener Using Java Technology NIO (Page last updated June 2005, Added 2005-08-29, Author Jean-Francois Arcand, Publisher java.net). Tips:
- Thread management issues makes it impossible for a non-NIO Java HTTP server to scale to thousands of users
- Scalability is always limited to the number of available threads, and when HTTP keep-alive is required, without NIO scalability suffers from the one thread per connection paradigm.
- Alternatives to scaling non-NIO based servers are clustering or using multiple proxy servers.
- An I/O server framework shoudl provide pluggable support for any kind of thread pool.
- With NIO non blocking and HTTP you never know when all the bytes have been read - with blocking, you just wait on the socket's input stream until it is closed. With non-blocking, you cannot wait on the socket input stream because it will return as soon as you have read all the available data, but that doesn't means you have received all the request bytes.
http://weblogs.java.net/blog/hiheiss/archive/2005/06/exposing_java_t.html
Java Technology Performance Myths (Page last updated June 2005, Added 2005-08-29, Author Janice J. Heiss, Clifford Click, Publisher java.net). Tips:
- "final" won't make your code run faster
- Don't put try/catches in very tight array loops. Otherwise it's more or less free.
- Run-Time Type Info makes for really ugly code - it is fast though, so only use it if you're desperate for that last bit of performance.
- synchronization is not free, but it's no longer so expensive.
- Use object pooling only for expensive to create objects.
- Enums, autoboxing and varargs are mostly free [I disagree, autoboxing is very expensive compared to directly using the primitive datatypes - there's been a few studies that showed this you can see them in other tips].
- There is a problem with enums in Tiger in that the values() method closes an array on every call. If you don't move the values() call to a point outside of your loop so it only runs once, you can take a big performance hit.
- There are still scaling problems with large heaps
- modern JVMs favor common usage patterns and clean code
http://www.stickyminds.com/BetterSoftware/magazine.asp?fn=cifea&id=66
High Performance Testing (Page last updated May 2005, Added 2005-08-29, Author Scott Barber, Publisher Better Software Magazine). Tips:
- Specifying page display time (e.g. under x seconds) is insufficient; such goals must also consider client connection speed, number of people accessing the site, and types of activities those people are performing, all variables that affect page response time.
- An example of a fully specified page display time performance target is: Using the ?peak order? workload model, under a 500-hourly user load, static pages will display in under x seconds, dynamic pages in under y seconds, and search/order pages in under z seconds, 95 percent of the time with no errors when accessed via corporate LAN.
- Review the performance plans and deliverables and ask: will this lead to a better experience for the end-user; Is this representative of the actual production environment; Is useful for tuning; Is each specific requirement, goal, or service level agreement addressed?
- Before functional testing is possible, performance planning should create User Community Models and test data and gather statistics on: Network and/or Web server throughput limits; Individual server resource utilization under various loads; Search speeds, query optimization, table/row locking, and speed versus capacity measurements for databases; Load balancing overhead/capacity/effectiveness; Speed and resource cost of security measures.
- Releasing the software is no reason to stop performance testing.
- Without actual data to go on, it is equally as likely that doubling the number of servers will degrade performance rather than improve it.
http://www.javaspecialists.co.za/archive/Issue111.html
What is faster - LinkedList of ArrayList? (Page last updated July 2005, Added 2005-08-29, Author Heinz Kabutz, Publisher JavaSpecialists). Tips:
- LinkedList is slower than ArrayList for modifications at the end or middle of the list.
- For a long list that works as a FIFO queue, the LinkedList should be faster than the ArrayList. However, even faster is an ArrayBlockingQueue or the CircularArrayList.
http://www.theserverside.com/articles/article.tss?l=J2EEClustering
J2EE Clustering (Page last updated August 2005, Added 2005-08-29, Author Wang Yu, Publisher TheServerSide). Tips:
- Scalability is a system?s ability to support increasing numbers of users or concurrent sessions handled by a server.
- Scalability is often addressed by adding resources (memory, CPU or hard disk) to a system, or by clustering which allows a group of servers to share the heavy tasks, and operate as a single server logically.
- Clustering is a solution to achieving high availability by providing redundant servers in the cluster for failover.
- Load balancing is a key technology in clustering, to obtain high availability and better performance by dispatching incoming requests to different servers.
- A fault tolerant service always guarantees strictly correct behavior despite a certain number of faults (e.g. a session would continue uninterrupted even if the server handling fails).
- Idempotent methods are methods that can be called repeatedly with the same arguments and achieve the same results - these are important for ensuring high performance failover systems.
- You should ask more such basic questions as "what types of objects can be clustered?" and "where will load balancing and failover happen in my J2EE code?"
- Because the HTTP protocol is itself stateless, session state needs to be stored somewhere and associated with your browsing session.
- When load balancing, it is the best choice to dispatch the request to the same server instance as the last time for a certain browser session - this is called a sticky session.
- Session failover of sticky sessions is possible by having the session data available from another location, e.g. database, replication server, distributed sessions, etc.
- If backup actions take place too frequently, the performance will be impacted sharply; But the longer the interval between two backup actions, the more session information you will lose if a server failure happens during the interval.
- Two popular session backup times are: at the end of each request; or at constant intervals.
- When backing up sessions, you can backup changes instead of full session data for higher performance.
- You should prepare for J2EE clustering at the beginning of your projects in order to build a large scale system.
http://www-128.ibm.com/developerworks/java/library/j-tiger07195/index.html
The Collections Framework in Tiger (Page last updated July 2005, Added 2005-08-29, Author John Zukowski, Publisher DeveloperWorks). Tips:
- With java.util.Collections.unmodifiable*(), you get back a read-only view of the specified collection.
- Three java.util.Collections.empty*() methods, emptySet(), emptyList(), and emptyMap(), generate empty immutable collections, providing empty, read-only collections in an optimal way.
- Use the offer() method to add elements to a Queue; if a sized queue is full, offer() returns false, not causing you to deal with exceptions when full (the add() method would throw an unchecked exception on failure).
- LinkedList has been retrofitted with the Queue interface with JDK 5.0, and PriorityQueue has been added along with implementations ArrayBlockingQueue, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, PriorityBlockingQueue, and SynchronousQueue.
- With PriorityQueue, when a Comparator isn't available the natural ordering of the elements (using Comparable) is used to determine priority.
http://monkey.workarea.jp/lb/archive/2005/8-08.html
XML Performance Checklists (Page last updated August 2005, Added 2005-08-29, Author Atsushi Eno, Publisher monogatari). Tips:
- [Weblog provides a checklist for ensuring optimal XML performance, admittedly for .NET, but pretty much most apply to Java too].
http://java.sys-con.com/read/111252.htm
JDBC 4.0 (Page last updated July 2005, Added 2005-08-29, Author John Goodson, Publisher JavaDevelopersJournal). Tips:
- Pooling is great - except it's not very tunable, it's hard to map end users back to connections in the pool, and if a connection ever becomes invalid inside the pool, expunging only that connection from the pool is nearly impossible. JDBC 4.0 addresses all these drawbacks.
- It's likely that an application will have a certain set of SQL statements that are re-executed multiple times and a few SQL statements that might only be executed once or twice during the life of the application. JDBC 4.0 provides a more granular level of statement pooling by letting applications hint to the pool manager about whether a SQL statement should be pooled.
- The preparedStatement interface has been expanded by the addition of two new methods: isPoolable() and setPoolable() (by default, a statement is poolable when it's created). Applications can specifically request that a statement not be pooled by calling setPoolable(false).
- Queries that are reused should be pooled for optimal performance, and queries that are used infrequently should not be pooled.
- To assist JDBC monitoring, JDBC 4.0 has added setClientInfo() and getClientInfo() to the Connection interface. After connecting, an application can call setClientInfo() to associate client-specific information to the JDBC connection object to help pinpoint where any problem may be.
- The Connection.isClosed() method is sometimes mistakenly thought to check if a connection is still valid, but the intent of isClosed() is to check and see if a connection is open or closed, not whether the connection is still usable.
- If a connection pool manager decides that a connection is invalid or is suspect (through whatever proprietary means is available), the most common technique used is for the pool manager to terminate all the connections in the pool and re-initialize it. This is extremely expensive in terms of performance. A new method on the Connection interface, isValid(), has been added so pool managers can check if a connection is still usable - if it is invalid, the pool manager can discard only the marred connection and not the contents of the entire pool.
- New SQLNonTransientException and SQLTransientException allow you to know which exceptions can be usefully re-tried.
Jack Shirazi
Back to newsletter 057 contents
Last Updated: 2025-01-27
Copyright © 2000-2025 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.
URL: http://www.JavaPerformanceTuning.com/news/newtips057.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us