Welcome!

Eclipse Authors: Pat Romanski, Elizabeth White, Liz McMillan, David H Deans, JP Morgenthal

Related Topics: Java IoT, Microservices Expo, Open Source Cloud, Machine Learning , Ruby-On-Rails, Python

Java IoT: Article

The Taming of the Queue

Measuring the Impact of Request Queueing

A few weeks back webserver request queueing came under heightened scrutiny as rapgenius blasted Heroku for not using as much autotune as promised in their “intelligent load balancing”. If you somehow missed the write-up (or response), check it out for its great simulations of load balancing strategies on Heroku.

What if you’re not running on Heroku? Well, the same wisdom still applies – know your application’s load balancing and concurrency and measure its performance. Let’s explore how request queueing affects applications in the non-PaaS world and what you can do about it.

Full-stack apps have full-stack problems
Rapgenius had been monitoring server-side request latency as only the time the request spent being processed in the app layer – leading to large discrepancies between what their APM tools were reporting and what the actual user experience was. The missing latency was attributable to queueing happening just before the application processed each request, which was outside the visibility of the tools being used to monitor the site.

If your application processes requests at a constant speed but receives an increasing volume of requests (generally a good problem to have), you’ll start to face request queueing.

What does this queueing look like?
(I’ll be using nginx and gunicorn as examples here because that’s what we use, but the same reasoning and analysis principles apply no matter what stack you’re running.)

To visualize this problem, let’s look at a simple test stack running nginx in front of a Python app with eight worker processes. In our case, it’s actually intelligently load balanced by gunicorn because there’s a single queue that knows which workers are busy (unlike Heroku at scale). However, we can still run into plenty of problems.

I’ve instrumented it so we watch the latency of requests moving through the full stack, starting at the load balancer:queueing

In this image, orange represents time spent queued in a webserver, while the other colors represent the components of the application (app, DB, cache).

As you can see, the application performs admirably, slowing a bit under load but never getting slower than 150 ms to process a response. If that’s all you were looking at, you’d be delighted! But the slow buildup of queue depth results in and increased amount of time spent in each request, which is shown in orange. Yikes!

Mind your Ps and Queues
In your application, there’s likely to be queueing anywhere you distribute request load over multiple backends. In the simplest app, this might be happening between your webserver and application layer, as above. Dynamic requests must be handled by the app, and if all the app workers are busy, requests will have to wait. Here’s what that might look like for a single Heroku dyno, or an app you stand up on a development server:

queueing

In fact, a common problem we see is that an app is underprovisioning app workers in production, even if the nodes they’re running on aren’t working very hard. If you see request queueing with low server load, consider running more app worker processes:

queueing

This has the great property of helping you get the most out of your frontend node, but assuming that your local app server can do intelligent load balancing like gunicorn, it also has some beneficial load distribution properties. We’ll get to those in a second.

Third scenario: you’re running single application workers on multiple frontend nodes. This is your Thin app running on a number of Heroku dynos. It will look more like this:queueing

The challenge now is that unless the remote load balancer is keeping track of which workers are busy, it will have to distribute load less intelligently.

What’s wrong with random balancing?
Random assignment sounds pretty good intuitively. Let’s say I’m going to route 100 requests to two app workers, with a 50% probability of choosing each worker each time. At the end, you’d expect me to have around 50 processed by each. Sounds fair, right?

The problem is that at any given time during the handling of those 50 requests, one node might be two or three deep while the other is empty, which is a problem for latency. Compounding this is the possibility that different requests take different amounts of time to process.

For a mathematical analysis, check out this blog post. For a simulation, I’ll cite this cool animated gif from the rapgenius analysis:

So, it seems like we want to have at least some level of intelligence in our load balancing.

Alleviating the pain of scale
Heroku’s response is that it can be difficult to keep track of which workers are busy and which are free when you’re at scale – that’s why their routing mesh degrades to semi-random behavior.  This is definitely not an easy problem, because their “load balancer” is actually a distributed system.  However, even without tackling this omnipotence problem at the top level, local intelligence under a random umbrella can be very effective.

There’s a lot of app servers that support this. For instance, if you’re running Unicorn for Ruby, or gunicorn for Python, each app server has a pool of workers which have a local queue and are routed to intelligently. So, your setup looks more like this:

queueing

This actually makes a big impact on performance. If you replace each single-worker dyno with a two-worker intelligently-routed app server, you get much-improved performance.

However, that assumes evented workers, where the cost of adding a second worker to a node is minimal. What if you’re using non-evented threads or processes, so you care about the total CPU and memory consumption of your workers?

To answer that question, and to try out R for the first time, I modified the rapgenius simulations to look at the effects of scaling the overall number of workers and workers-per-node, on request queueing:

queueing

(source on github)

Queueing performance improves quite well with the number of workers on each naively-balanced endpoint. (The shelf in the eight-worker line is due to the fact that 10 and 15 are both < 16). You can see that, in fact, two naively-routed pairs of eight-worker (intelligently-routed) nodes are better than 100 naively-routed one-worker nodes. See the pattern? The lines are converging on a single, fully intelligently-routed cluster.

This is possible with app worker processes or threads on each node, but if you’re running evented workers, each individual worker is capable of handling quite a number of requests simultaneously!

How do I know if I have this problem?
Okay, so it’s an interesting problem to think about, but really the practical question is, “Is queuing affecting my application’s responsiveness?” Monitoring the full stack is the best way to stay on top of performance problems – webserver queueing among many others.

You can usually get an isolated look at webserver queueing from your load balancer and/or app server. For instance, if you’re running FCGI on lighttpd, you can check the queue depth of each worker.

But the ultimate determinant of the success or failure of your load balancing is the impact on latency and concurrency. Check out this 3-minute video on understanding webserver queueing.

Related Articles

More Stories By Dan Kuebrich

Dan Kuebrich is a web performance geek, currently working on Application Performance Management at AppNeta. He was previously a founder of Tracelytics (acquired by AppNeta), and before that worked on AmieStreet/Songza.com.

@ThingsExpo Stories
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
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...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
SYS-CON Events announced today that Ryobi Systems 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. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
Amazon is pursuing new markets and disrupting industries at an incredible pace. Almost every industry seems to be in its crosshairs. Companies and industries that once thought they were safe are now worried about being “Amazoned.”. The new watch word should be “Be afraid. Be very afraid.” In his session 21st Cloud Expo, Chris Kocher, a co-founder of Grey Heron, will address questions such as: What new areas is Amazon disrupting? How are they doing this? Where are they likely to go? What are th...
High-velocity engineering teams are applying not only continuous delivery processes, but also lessons in experimentation from established leaders like Amazon, Netflix, and Facebook. These companies have made experimentation a foundation for their release processes, allowing them to try out major feature releases and redesigns within smaller groups before making them broadly available. In his session at 21st Cloud Expo, Brian Lucas, Senior Staff Engineer at Optimizely, will discuss how by using...
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japanese 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. Ruby Development Inc. builds new services in short period of time and provides a continuous support of those services based on Ruby on Rails. For more information, please visit https://github.com/RubyDevInc.
As businesses evolve, they need technology that is simple to help them succeed today and flexible enough to help them build for tomorrow. Chrome is fit for the workplace of the future — providing a secure, consistent user experience across a range of devices that can be used anywhere. In her session at 21st Cloud Expo, Vidya Nagarajan, a Senior Product Manager at Google, will take a look at various options as to how ChromeOS can be leveraged to interact with people on the devices, and formats th...
SYS-CON Events announced today that Yuasa System 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. Yuasa System is introducing a multi-purpose endurance testing system for flexible displays, OLED devices, flexible substrates, flat cables, and films in smartphones, wearables, automobiles, and healthcare.
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/.
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.
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 b...
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 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 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.
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...
SYS-CON Events announced today that TidalScale 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 is the leading provider of Software-Defined Servers that bring flexibility to modern data centers by right-sizing servers on the fly to fit any data set or workload. TidalScale’s award-winning inverse hypervisor technology combines multiple commodity servers (including their ass...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
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.