Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Is the Glass Half Full or Half Empty?

Threads, amdahl, and a very big machine

In this column over the years, I have spent a considerable amount of time talking about contention and locking in the database tier. At the end of the day, the endless conversations about scaling the application tier boil down to less than a bag of beans if a scaled application can't go any faster because the database has hit a limit.

Sometimes, the "database hitting a limit" involves a limit to the physical capacity of the database to service requests for data, which usually leads to purchase of a larger database server, or some kind of partitioning or tuning work. Other times, the database server is not too busy, but the data itself is the problem (or at least, the pattern of access to the data) - remembering back to ACID transactions and the rules for using them, the most golden of golden rules is that transactions should be as short in duration as possible, to ensure that the system does not grind to a halt. The reason a system with lots of long transactions in it might grind to a halt is that an ACID transaction is associated with a bunch of locks in the database; therefore, the longer the transaction is active, the higher the probability that several pieces of the application will try to obtain the same lock - resulting in the application being bogged down in contention for the same piece of data. In this situation no amount of hardware can help; while data accesses do not touch each others' locks, they can fly through the database as fast as the server can access its disks. As soon as multiple pieces of the application want to touch the same data, things are not so free and easy.

This is all well understood stuff, at the database tier. A lot of effort has gone in over the years to remove lock contention wherever possible. In particular, optimistic locking has become a well-established technique to reduce data contention. With optimistic locking, the database will give its locks out to multiple accessors simultaneously, on the assumption that they will not make conflicting updates to the data. At the time the transaction commits, if it turns out the two accessors did actually trample on each other, one of the transactions will be rolled back with an exception, since it has turned out that the database's optimism was unfounded and the access really needed to be serialized in the more traditional pessimistic way. The success of this technique in increasing throughput is not magic; clearly, it works because what is being contended for is only the lock - not the data itself (this being the key optimistic assumption). If the actual data were being contended for a majority of the time, optimistic locking would actually result in a net slowdown, brought about by the endless collisions and retrying.

So why am I rambling at high speed through this resume of transaction design and database lock management?

"You cannot change the laws of physics!"
Well, it turns out that the same principles apply in other tiers - surprise surprise, these are "laws of physics" after all... So why haven't we heard the analogue to this tale of lock-related pain and trickery in the application tier? Well, it all comes down to what there is a lot of, and what there is not much of. In the database view, there is just one database, and a desire for throughput that leads to many concurrent accessors. It is as you try to drive the concurrency up that you get more and more likely to hit locking issues in your database. So where is that pattern in the application tier? Well, one of the features of the Java language is easy threadedness so there are likely to be many threads, as anyone who has designed a Java application will know of the "singleton" design pattern because it is often used to represent something that there is only one of in a given JVM - a log singleton, a hashmap of reference data, you name it... everywhere there are apps, there are singletons!

So, you say, apps are full of singletons; Java in general and Java application servers in particular have a capacity for running lots of threads through them, so why hasn't every highly threaded java application ground to a halt long ago? Amdahl's law (the particular "law of physics" in question), after all, states that you can only parallelize an application to the degree that the threads can be run independently - what gives!

The answer turns out to be in the hardware that is running the software virtual machine. In a typical environment, eight CPUs constitute a pretty large machine, and it is more common to have deployed many smaller servers, with one or two CPUs each. Therefore, in this environment, if you code a Java application that spawns a number of threads that all access a single hashmap as part of their work, you will not see much difference to the throughput if you compare it with and without the hashmap as you increase the number of threads from, say 50 to 5,000. The reason for that is that even if you spawned 5,000 threads, they are still getting scheduled over the eight CPUs (or however many you have), so the level of parallelism you are achieving is much less than you expected - only eight threads can really physically run at once. This points up a fundamental scaling issue with Java on traditionally architected machines. The "thing there is not much of" - the place where contention will limit your throughput - is not the hashmap, it's the CPU itself. This is one of the reasons why Java applications typically end up deploying over a pretty large set of machines - that way you get enough CPUs to really physically run things in parallel and have a hope of meeting your throughput goals and other SLAs. It is a shame about the running costs of the resulting complex, partitioned system.

This latter partitioning problem is one of those that Azul is addressing by manufacturing 384 processor SMP boxes to allow truly big Java virtual machines to run - removing the complexity of having to artificially break the application up into small pieces. "AHA!" you cry - now that lock thing in the singleton will kill you! You now have many truly concurrent threads all contending for those singletons. It turns out that there is a solution to this problem supported in the hardware (here's an advantage of designing hardware explicitly to execute virtual machines), and it's called Optimistic Thread Concurrency or OTC for short.

As the name suggests, the system's behavior using OTC is the same as (or at least analogous to) the behavior of a database doing optimistic locking: the virtual machine allows many threads to pass through a lock on the assumption that bad things won't happen (that's the optimism part). If bad things do happen and data (rather than just the lock) is actually contended for, then the contending thread is reverted to the state it was in before it acquired the lock and it proceeds forward again - none the wiser, with the integrity of the data intact, and all with no change to the application code itself.

The trick is knowing which locks to be optimistic about - if a particular lock protects a piece of data that is nearly always written to, all that rolling back will hurt, not help, performance. In other cases, for data that is read very frequently but seldom written such as reference data, optimism will be the best policy. In order to tune the OTC system for these different eventualities (which will doubtless coexist in a single app) there are three types of lock that are implemented internally by Azul's virtual machine. Thick locks are the usual pessimistic locks through which access will be serialized, and thin locks are the cheapest form of lock. If a thin lock experiences contention, it must be promoted to either a thick lock or a speculative lock, which is the type of lock that sits between thin and thick and allows multiple threads through, using the hardware to check that there is no contention, and, importantly, to drive the rollbacks if contention occurs. Throughout the life of a virtual machine, data is kept about all the locks. Locks that are frequently contended will be thick, those that are never contended will be thin, and those that are "mostly" uncontended will be speculative. As usage patterns change, heuristics in the VM move individual locks between these three states, thus providing optimum parallelization, and hence throughput, for the application at run time.

Not only does this scheme just improve parallelism with no code changes, but it also allows simpler code to be used. Often, programmers in search of the ultimate throughput end up coding complex nested locking schemes, which are difficult to code, and even more difficult to debug and maintain. With OTC, the locking can be coded in a coarse-grained manner (and therefore can be simple to code and maintain) without impacting throughput - for once the developers get to have their cake and eat it too.

So, fill your glass with OTC. You may find that that old glass of yours holds more than you think, if you deploy it on Azul! For more details about OTC, you can download the whitepaper from the Azul Web site, at www.azulsystems.com/products/whitepaper_abstracts.html.

More Stories By Peter Holditch

Peter Holditch is a senior presales engineer in the UK for Azul Systems. Prior to joining Azul he spent nine years at BEA systems, going from being one of their first Professional Services consultants in Europe and finishing up as a principal presales engineer. He has an R&D background (originally having worked on BEA's Tuxedo product) and his technical interests are in high-throughput transaction systems. "Of the pitch" Peter likes to brew beer, build furniture, and undertake other ludicrously ambitious projects - but (generally) not all at the same time!

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
SYS-CON Australia News Desk 02/17/06 07:07:44 PM EST

In this column over the years, I have spent a considerable amount of time talking about contention and locking in the database tier. At the end of the day, the endless conversations about scaling the application tier boil down to less than a bag of beans if a scaled application can't go any faster because the database has hit a limit.

@ThingsExpo Stories
Organizations do not need a Big Data strategy; they need a business strategy that incorporates Big Data. Most organizations lack a road map for using Big Data to optimize key business processes, deliver a differentiated customer experience, or uncover new business opportunities. They do not understand what’s possible with respect to integrating Big Data into the business model.
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, will discuss some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he’ll go over some of the best practices for structured team migrat...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, will discuss how from store operations...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, will discuss how they bu...
SYS-CON Events announced today that Dasher Technologies will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Dasher Technologies, Inc. ® is a premier IT solution provider that delivers expert technical resources along with trusted account executives to architect and deliver complete IT solutions and services to help our clients execute their goals, plans and objectives. Since 1999, we'v...
SYS-CON Events announced today that TidalScale, a leading provider of systems and services, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale has been involved in shaping the computing landscape. They've designed, developed and deployed some of the most important and successful systems and services in the history of the computing industry - internet, Ethernet, operating s...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities – ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups. As a result, many firms employ new business models that place enormous impor...
SYS-CON Events announced today that Taica will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Taica manufacturers Alpha-GEL brand silicone components and materials, which maintain outstanding performance over a wide temperature range -40C to +200C. For more information, visit http://www.taica.co.jp/english/.
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
As hybrid cloud becomes the de-facto standard mode of operation for most enterprises, new challenges arise on how to efficiently and economically share data across environments. In his session at 21st Cloud Expo, Dr. Allon Cohen, VP of Product at Elastifile, will explore new techniques and best practices that help enterprise IT benefit from the advantages of hybrid cloud environments by enabling data availability for both legacy enterprise and cloud-native mission critical applications. By rev...
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant tha...
SYS-CON Events announced today that Datera will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datera offers a radically new approach to data management, where innovative software makes data infrastructure invisible, elastic and able to perform at the highest level. It eliminates hardware lock-in and gives IT organizations the choice to source x86 server nodes, with business model option...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.
Digital transformation is changing the face of business. The IDC predicts that enterprises will commit to a massive new scale of digital transformation, to stake out leadership positions in the "digital transformation economy." Accordingly, attendees at the upcoming Cloud Expo | @ThingsExpo at the Santa Clara Convention Center in Santa Clara, CA, Oct 31-Nov 2, will find fresh new content in a new track called Enterprise Cloud & Digital Transformation.
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp emp...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
SYS-CON Events announced today that Avere Systems, a leading provider of hybrid cloud enablement solutions, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere Systems was created by file systems experts determined to reinvent storage by changing the way enterprises thought about and bought storage resources. With decades of experience behind the company’s founders, Avere got its ...
SYS-CON Events announced today that Avere Systems, a leading provider of enterprise storage for the hybrid cloud, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere delivers a more modern architectural approach to storage that doesn't require the overprovisioning of storage capacity to achieve performance, overspending on expensive storage media for inactive data or the overbui...