Welcome!

Machine Learning Authors: Kevin Jackson, Madhavan Krishnan, VP, Cloud Solutions, Virtusa, Pat Romanski, Elizabeth White, William Schmarzo

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.

@CloudExpo Stories
"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.
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...
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...
Agile has finally jumped the technology shark, expanding outside the software world. Enterprises are now increasingly adopting Agile practices across their organizations in order to successfully navigate the disruptive waters that threaten to drown them. In our quest for establishing change as a core competency in our organizations, this business-centric notion of Agile is an essential component of Agile Digital Transformation. In the years since the publication of the Agile Manifesto, the conn...
Enterprises are moving to the cloud faster than most of us in security expected. CIOs are going from 0 to 100 in cloud adoption and leaving security teams in the dust. Once cloud is part of an enterprise stack, it’s unclear who has responsibility for the protection of applications, services, and data. When cloud breaches occur, whether active compromise or a publicly accessible database, the blame must fall on both service providers and users. In his session at 21st Cloud Expo, Ben Johnson, C...
"We're developing a software that is based on the cloud environment and we are providing those services to corporations and the general public," explained Seungmin Kim, CEO/CTO of SM Systems Inc., 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.
Enterprises are adopting Kubernetes to accelerate the development and the delivery of cloud-native applications. However, sharing a Kubernetes cluster between members of the same team can be challenging. And, sharing clusters across multiple teams is even harder. Kubernetes offers several constructs to help implement segmentation and isolation. However, these primitives can be complex to understand and apply. As a result, it’s becoming common for enterprises to end up with several clusters. Thi...
"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.
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.
Data scientists must access high-performance computing resources across a wide-area network. To achieve cloud-based HPC visualization, researchers must transfer datasets and visualization results efficiently. HPC clusters now compute GPU-accelerated visualization in the cloud cluster. To efficiently display results remotely, a high-performance, low-latency protocol transfers the display from the cluster to a remote desktop. Further, tools to easily mount remote datasets and efficiently transfer...
"Codigm is based on the cloud and we are here to explore marketing opportunities in America. Our mission is to make an ecosystem of the SW environment that anyone can understand, learn, teach, and develop the SW on the cloud," explained Sung Tae Ryu, CEO of Codigm, 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.
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...
In his session at 21st Cloud Expo, James Henry, Co-CEO/CTO of Calgary Scientific Inc., introduced you to the challenges, solutions and benefits of training AI systems to solve visual problems with an emphasis on improving AIs with continuous training in the field. He explored applications in several industries and discussed technologies that allow the deployment of advanced visualization solutions to the cloud.
"Infoblox does DNS, DHCP and IP address management for not only enterprise networks but cloud networks as well. Customers are looking for a single platform that can extend not only in their private enterprise environment but private cloud, public cloud, tracking all the IP space and everything that is going on in that environment," explained Steve Salo, Principal Systems Engineer at Infoblox, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventio...
"We're focused on how to get some of the attributes that you would expect from an Amazon, Azure, Google, and doing that on-prem. We believe today that you can actually get those types of things done with certain architectures available in the market today," explained Steve Conner, VP of Sales at Cloudistics, 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.
"NetApp is known as a data management leader but we do a lot more than just data management on-prem with the data centers of our customers. We're also big in the hybrid cloud," explained Wes Talbert, Principal Architect at NetApp, 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.
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...
The question before companies today is not whether to become intelligent, it’s a question of how and how fast. The key is to adopt and deploy an intelligent application strategy while simultaneously preparing to scale that intelligence. In her session at 21st Cloud Expo, Sangeeta Chakraborty, Chief Customer Officer at Ayasdi, provided a tactical framework to become a truly intelligent enterprise, including how to identify the right applications for AI, how to build a Center of Excellence to oper...
"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...