Is your code ready for the next wave in commodity computing?
Prepare yourself for multicore processing
By Humphrey Sheil, JavaWorld.com, 07/10/06
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Hardware is really just software crystallized early," says Alan C. Kay in his paper "The Early History of Smalltalk" (ACM, 1993). This quote really explains the inspiration for this article. Software developers have always been at the mercy
of hardware manufacturers, although we've had a pretty easy ride of it since the inception of the computing industry itself.
From then until now, increasing speeds of every single component that goes into the standard Von Neumann architecture have
given our software literally free increases in performance.
No longer.
All of the main hardware manufacturers (Intel, IBM, Sun, and AMD) have realized the problems inherent in jacking up the clock
speeds of CPUs and are in the process of rolling out a fundamental change in processor architecture—multicore units with more than one processing element, providing true hardware support for multiple threads of execution, instead of
simulated as in the past.
Like every other change you have come across in your career as a Java programmer, this one brings opportunities and threats
to you. In this article, I highlight these opportunities and challenges, as well as detail how to avoid the main challenges
identified.
Why parallelize?
Let's take a step back and examine the factors that have precipitated the advent of parallel computing hardware in all tiers
of IT, as opposed to specialized high-end niches. Why would we want hardware that can execute software in true parallel mode?
For two reasons: You need an application to run more quickly on a given dataset and/or you need an application to support
more end users or a larger dataset.
And if we want a "faster" or "more powerful" application, where powerful means handling more and more users, then we have
two options:
- Increase the power of the system resources
- Add more resources to the system
If we increase the power of the system resources (i.e., in some semantic sense, replace or extend the system within its original boundaries), then we are scaling the system vertically; for example, replacing a 1-GHz Intel CPU with a 2-GHz
version that is pin-compatible, which is a straight swap. If however, we choose to add to the system resources such that we
extend beyond the original boundaries of the system, then we are scaling the system horizontally; for example, adding another
node to our Oracle 10g RAC cluster to improve overall system performance.
Finally, I'd like to make one more point on the advent of parallel hardware—you may not need it or even want it for your application,
but you have no choice in the matter—CPUs that provide true hardware support for multiple threads are becoming the norm, not
the exception. Some estimates indicate that 75 percent of the Intel CPUs that ship by the end of 2007 will be multicore. Intel
itself estimates 25 percent by the end of 2006.
Let's switch gears for a moment and place ourselves in the shoes of a hardware designer. How can we feed the insatiable appetite
of software programmers for more powerful hardware? We've spent the last 20 years delivering the promise of Moore's Law, to
the extent that we are running into fundamental problems of physics. Continuing to increase the clock speed of single processing
units is not a sustainable solution moving forward because of the power required and heat generated. The next logical move
is to add more processing units to those self-same chips. But that means no more free lunch. Those software engineers will
need to explicitly take advantage of the new hardware resources at their disposal or not realize the benefit.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- There is a plethora of information on the T1000 and T2000 servers from Sun Microsystems available here (Also, be sure to Google
for blogs providing non-biased real-world benchmarks on the T1, because Sun is allowing people on the 60-day try-before-you-buy
program to do just that. This is a marked and welcome departure from other vendor attitudes on independent benchmarking.)
http://www.sun.com/servers/coolthreads/overview/learnmore.jsp
- Is it just me or does Apple just make multicore computing seem sexier? Who else would breathlessly say"So, just 'fast?' Only
for lack of a faster term."? http://www.apple.com/macbook/intelcoreduo.html
- One of the definitive nonpartisan guides on hyperthreading"Introduction to Multithreading, Superthreading and Hyperthreading,"
Jon "Hannibal" Stokes (Ars Technica, October 2002)
http://arstechnica.com/articles/paedia/cpu/hyperthreading.ars
- In particular, check out page four of "Introduction to Multithreading, Superthreading and Hyperthreading," which details the
inherent limitations to hyperthreading based on how it is implemented
http://arstechnica.com/articles/paedia/cpu/hyperthreading.ars/4
- AMD has a dedicated site to multicore technology
http://multicore.amd.com/
- For the complete AMD picture, you also need to check out AMD's HyperTransport and Direct Connect offerings, and how they team
CPUs/cores together via high-speed links
http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252_2353,00.html
- AMD Opteron Processor Key Architectural Features
http://www.amd.com/us-en/Processors/ProductInformation/0,,30_118_8796_8805,00.html
- A really great read on the early days at Xerox PARC and just some of the blue-skies computer science research undertaken there.
Although the title of the paper refers to Smalltalk, in actual fact, the author is describing fundamental problems in software
engineering that still exist today"The Early History of Smalltalk," Alan C. Kay (ACM, 1993)
http://www.smalltalk.org/smalltalk/TheEarlyHistoryOfSmalltalk_Abstract.html
- Doug Lea's Website features lots of Java concurrency links to keep you occupied
http://g.oswego.edu/dl/
- A must-read book on Java concurrencyJava Concurrency in Practice, Joshua Bloch, Joseph Bowbeer, Brian Goetz, David Holmes, Doug Lea, Tim Peierls (Addison Wesley Professional, May 2006; ISBN0321349601)
http://www.awprofessional.com/bookstore/product.asp?isbn=0321349601&rl=1#
- A guide to the HotSpot VM options, from the obvious to the esoteric
http://java.sun.com/docs/hotspot/VMOptions.html
- Flynn's taxonomy
http://en.wikipedia.org/wiki/Flynn's_taxonomy
- Amdahl's Law
http://en.wikipedia.org/wiki/Amdahl's_law
- A short overview of some of the threading issues to consider when writing Swing applications
http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
- For more on threads, read Allen Holub's JavaWorld series"Programming Java Threads in the Real World":
-
- Part 1A Java programmers guide to threading architectures (September 1998)
http://www.javaworld.com/javaworld/jw-09-1998/jw-09-threads.html?
- Part 2The perils of race conditions, deadlock, and other threading problems (October 1998)
http://www.javaworld.com/javaworld/jw-10-1998/jw-10-toolbox.html?
- Part 3Roll-your-own mutexes and centralized lock management (November 1998)
http://www.javaworld.com/javaworld/jw-11-1998/jw-11-toolbox.html?
- Part 4Condition variables and counting semaphores—filling in a few chinks in Java's threading model (December 1998)
http://www.javaworld.com/javaworld/jw-12-1998/jw-12-toolbox.html?
- Part 5Has Sun abandoned run anywhere? PlusThreads and Swing, timers, and getting around stop(), suspend(), and resume() deprecation.
(February 1999)
http://www.javaworld.com/javaworld/jw-02-1999/jw-02-toolbox.html?
- Part 6The Observer pattern and mysteries of the AWTEventMulticaster (March 1999)
http://www.javaworld.com/javaworld/jw-03-1999/jw-03-toolbox.html?
- Part 7Singletons, critical sections, and reader/writer locks (April 1999)
http://www.javaworld.com/javaworld/jw-04-1999/jw-04-toolbox.html?
- Part 8Threads in an object-oriented world, thread pools, implementing socket accept loops (May 1999)
http://www.javaworld.com/javaworld/jw-05-1999/jw-05-toolbox.html?
- Part 9More threads in an object-oriented worldSynchronous dispatchers, active objects, detangling console I/O (June 1999)
http://www.javaworld.com/javaworld/jw-06-1999/jw-06-toolbox.html?
- Also browse the Thread Programming section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-threads-index.shtml
Archived Discussions (Read only)