Welcome!

Apache Authors: Pat Romanski, Liz McMillan, Elizabeth White, Christopher Harrold, Janakiram MSV

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
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
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, discussed how from store operations and ...
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix 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. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...