Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Introducing Mesos-Native Health Checks in Apache Mesos (Part 2)

DZone's Guide to

Introducing Mesos-Native Health Checks in Apache Mesos (Part 2)

In this article, take a deep dive to really learn about and reach the scaling limits of Marathon and Mesos-native health checks.

· Big Data Zone
Free Resource

Free O'Reilly eBook: Learn how to architect always-on apps that scale. Brought to you by Mesosphere DC/OS–the premier platform for containers and big data.

In part one of this series, we introduced you to the brave new world of Mesos-native health checks.

In part two, join us as we take a deeper dive to reach the scaling limits of Marathon and Mesos-native health checks.

Setup

We ran scale tests against single-master DC/OS clusters running on m3.xlarge (4 vCPUs and 15 GiB RAM) instances on Amazon EC2. Our goal was to find out how a cluster with health checked tasks behaves under load.

Mesos health checks will be supported in DC/OS 1.9, so we created a custom DC/OS build with Marathon v1.4.0-RC1 and a version of Mesos with support for HTTP and TCP health checks.

How We Tested

We wanted to see how both Mesos and Marathon behave as we scale up the number of tasks being probed.

The test tasks run nc to test TCP health checks, and python -m SimpleHTTPServer to test HTTP health checks. We used the following configuration for all health checks (full Marathon Application Definitions):

gracePeriodSeconds: 20
intervalSeconds: 1
maxConsecutiveFailures: 3
delaySeconds: 0

We then wrote a Python script that tries to scale the application up, while plotting a chart to keep track of the state of all the tasks.

The script polls Marathon every two seconds to fetch the state of the app. If it is already being scaled up, it will group the tasks by their state and add them to a stacked bar chart.

If the target instance count has already been reached, it will automatically request Marathon to scale the app up by n instances.

The generated charts look like this:

The X axis represents the request number, the Y axis the number of tasks – so each complete bar represents all the tasks contained in a Marathon API response, and each segment in the bar represents the percentage of tasks in a particular state. The title mentions the type of health check, the number of agents in the cluster, and the timeout: the amount of time to wait for the health check to complete.

We defined the following task states:

Image title

Results

Baseline

We first set out to find out how many tasks with Mesos/Marathon probes can be started on a single agent. We wanted to be able to start as many tasks as possible, so we requested only 0.001 CPU and 64MB of RAM for each one. Each agent has 13.7 GB RAM and 4 CPUs available to Mesos, so memory should be the limiting resource, meaning that we should be able to start up to 219 tasks per agent.

Our initial tests were performed with a health check timeout of one second, this means that a health check is considered as failed if it takes longer than 1 seconds to probe the task. Using this setting, it was possible to start all the 219 tasks using Marathon health checks:

But when we switched to Mesos health checks, we noticed that Mesos was not able to cope with more than 121 tasks before starting to report tasks that were healthy as unhealthy:

These failed health checks were caused by timeouts — it took us some digging (details in the last section) to find out that these health check failures can be attributed to the time spent in context switching.

Hundreds of small (in term of requested CPU resources) tasks with short-lived health checks are not what Mesos-native health checks are optimized for. Also, health check timeout should be long enough to prevent false negatives caused by blips related to garbage collection cycles, context switches, I/O spikes, etc.

So we decided to use a more realistic value of five seconds. Doing this allowed us to saturate a one-agent cluster with 219 tasks regardless of the type of health checks used:

But… Does It Scale?

Having found a good baseline, we decided that it was time to pay Amazon for a bigger cluster and see how well the different kinds of health checks scale.

We first ran the tests against a cluster with 10 agents. We were able to saturate the memory of the agents, starting 2190 tasks using Marathon TCP and Mesos HTTP/TCP checks. But when using Marathon HTTP checks, we found out that Marathon started to report health failures and return errors to the API requests when the cluster reached the 1,900 tasks mark — the first manifestation of the bottleneck mentioned in part one of this blog post series.

Marathon was still able to cope with all the tasks when using Marathon TCP health checks, so we drank more Fanta, paid more money to Amazon, and added more agents to the cluster, running the tests against 20 agents.

Marathon could handle only up to 3700 tasks with Marathon TCP health checks before excluding the health check results from the API responses and eventually becoming completely unresponsive. This is visible in the next chart – the bars turn blue instead of red, because Marathon stops including the tasks’ health status in its API response.

As you can see, even though Marathon TCP health checks are cheaper than Marathon HTTP health checks, Marathon can’t manage to probe enough tasks to fill a 20 agent cluster.

We wanted to confirm that Mesos-native health checks are able to scale horizontally, so we rebuilt the cluster and ran the tests with Mesos TCP and HTTP health checks. In both cases we were able to fill all the agents with 4380 tasks:

Investigating Timeout-Induced Health Check Failures

As mentioned above, we observed frequent health check failures on saturated nodes with a one-second health check timeout. We felt upset, hurt and decided to dig in to better understand the reasons.

The Setup

Vagrant-based Virtualbox Ubuntu Trusty machines, 2 CPUs 4GB RAM, used for Mesos: 2CPUs 2929MB RAM. Mesos master and agent launched on different machines 12. We run nc tasks with 1s Mesos TCP health checks.

With the task asking for 0.001 CPU and 32MB RAM, the agent is able to host 91 tasks. Executors consume extra resources, but Mesos currently does not account them towards the task’s share, which in this case leads to overcommit resources (see MESOS-1718).

Short Experiment

We launched 90 instances of that simple nc task using Mesos TCP health checks with one-second timeout, 10 instances at a time, with sysdig capturing data in the background. Pretty soon health checks began to fail:

Analyzing Traces

We generated a trace for a single instance (pid=23457) of the helper binary (mesos-tcp-connect) for TCP health checks. We can see in the compacted version (filtering out mmap and mprotect events), that the process starts at 14:39:53.67 and exits at 14:39:55.87. This is obviously more than 1s. Moreover, the process doesn’t try to establish a TCP connection until 14:39:55.86 (event 1628396), over two seconds after having been launched! The TCP handshake did not stand a chance to finish in time.

After several moments of meditation over the trace, it becomes clear that context switches contribute the most to the overall command run time.

Understanding Reasons

Why does the TCP checker command receive such a small amount of CPU time? Let’s do some back-of-the-envelope calculations.

We have 90 tasks with three processes per task:

  1. The executor (mesos-executor).
  2. The task payload (nc).
  3. The health checking process (mesos-tcp-connect).

These processes are spread across 2 CPUs. We assume nothing else other than tasks is eating CPU cycles, which is very optimistic: at least sysdig and mesos-agent processes are busy collecting data and processing task status updates respectively.

Such an optimistic calculation yields: 2 / 270 = 0.0074mesos-tcp-connect’s CPU share.

Sysdig data for this particular instance suggests that the total amount of time mesos-tcp-connect spent in other contexts is 2.17864s3, while the total run time is 2.32s4.

That means that the TCP checker did meaningful work only during 1% of the overall run time (0.0174s, or 0.0079 CPU share, looks familiar, right?)!

Note that enabling CFS on the Mesos Agent (--cgroups_enable_cfs) improves things a little bit:

Easily deploy & scale your data pipelines in clicks. Run Spark, Kafka, Cassandra + more on shared infrastructure and blow away your data silos. Learn how with Mesosphere DC/OS.

Topics:
big data ,apache mesos ,mesos native ,health checks

Published at DZone with permission of Gaston Kleiman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}