Tuesday, May 21, 2024

Clean Crusing Forward | Databricks Weblog

The Databricks Container Infra staff builds cloud-agnostic infrastructure and tooling for constructing, storing and distributing container photos. Just lately, the staff labored on scaling Harbor, an open-source container registry. Request masses on Harbor are read-heavy and bursty and it’s a essential part of Databricks’ serverless product – anytime new serverless VMs are provisioned, Harbor will get a big spike in learn requests. With the speedy development of the product, our utilization of Harbor would wish to scale to deal with 20x extra load than it may at peak.

Grafana Dashboard
Grafana dashboard exhibiting the picture pull fee at peak and the way it impacts the error fee and CPU of harbor parts.

Over the course of Q1 2023, we tuned Harbor’s efficiency to make sure it was in a position to horizontally scale out. Later we prolonged it with a brand new service known as harbor-frontend to drastically enhance scaling effectivity for Databricks workloads (learn heavy, low cardinality of photos).

Why Scale the Container Registry?

Databricks shops container photos in Harbor. Every time a buyer begins up a Serverless DBSQL cluster, they reserve some quantity of compute sources from a heat pool. If that heat pool turns into exhausted, our infrastructure will request further compute sources from the upstream cloud supplier (AWS, for instance), which can subsequently be configured, began up, and added to the nice and cozy pool. That startup course of contains pulling varied container photos from Harbor.

As our serverless product grows in scope and recognition, the nice and cozy pool will 1.) be exhausted extra ceaselessly and a couple of.) must be refilled extra rapidly. The duty was to arrange Harbor to have the ability to serve these scalability necessities.


At a excessive degree, picture pulls for a node startup undergo the next course of:

  1. Authenticate the consumer node to Harbor
  2. Fetch the mandatory picture manifests from Harbor
  3. Based mostly on the manifests, fetch signed URLs pointing to the corresponding picture layers in object storage
  4. Use the signed URLs to drag all of the picture layers from exterior object storage (e.g., S3) and mix them to get the ultimate photos

Iterating Rapidly

Earlier than we began to enhance Harbor’s efficiency, there have been two issues to know first:

  1. What is supposed by “efficiency”?
  2. How can we measure efficiency?

Within the context of scaling Harbor for serverless workloads, efficiency is the variety of node startups that may be served efficiently per time unit. Every node startup should pull some variety of photos (roughly 30) from Harbor, and every picture has some variety of layers (roughly 10). So transitively, we are able to measure Harbor efficiency with the metric “layers requested per minute (LPM).” If Harbor can serve requests at 300 LPM, we are able to enable one node startup per minute.

Given our load forecast, the goal was to allow Harbor to serve 1000 node startups per minute or 300,000 LPM. After I began, Harbor noticed extreme failure fee and latency degradation at 15-30,000 LPM. That meant we wanted a 20x enchancment in efficiency!

We spent the primary month build up the tooling we would use for the next three months: load-generation/load-testing. To measure Harbor’s efficiency, we would want dependable testing to push Harbor to its limits. We discovered an present load tester within the code base that might generate load on Harbor. We added docker packaging assist to permit us to deploy it on Kubernetes and to ratchet up the load despatched to Harbor by scaling it horizontally.

As we dove deep to know the underlying strategy of Docker picture pulls, the staff crafted a brand new load tester which, as an alternative of being bottlenecked by downloading from exterior object storage (Step 4 above), would solely carry out the steps that put the load on Harbor (Steps 1-3 above).

As soon as the newest load tester was constructed out, it was lastly time to begin enhancing our Harbor infrastructure. For distributed programs comparable to Harbor, that is what that course of seems like:

  1. Apply load till the error fee and/or latency spikes
  2. Examine to uncover the bottleneck:
    • Error logs
    • CPU utilization
    • Community connections
    • CPU throttling
    • 4xx/5xx errors, the latency on completely different parts, and so forth.
  3. Resolve the bottleneck
  4. Return to Step 1

By means of this course of, we had been in a position to determine and resolve the next bottlenecks rapidly.

Exterior Redis Cache Limits Picture Pull Fee

The registry part had many situations, all calling into the identical exterior Redis occasion – to resolve this bottleneck we eliminated the exterior occasion and made it an in-memory cache inside the registry part. It seems we did not want the exterior cache in any respect.

Database CPU spikes to 100%

To resolve this, we vertically scaled the DB occasion kind and restricted the variety of open connections every harbor-core occasion made to the DB to maintain connection creation overhead low.

CPU throttling

Now that the DB was working easily, the subsequent bottleneck was the CPU throttling occurring on the stateless parts (nginx, core, and registry). To resolve this situation, we horizontally scaled every of them by including replicas.


Lastly, we hit the goal of 300,000 LPM. Nevertheless, at this level, we had been utilizing 30x extra CPUs and a DB occasion that was 16x extra highly effective and 32x extra expensive.

Whereas these modifications allowed us to hit our scalability goal, they value us tens of millions of {dollars} extra per 12 months in cloud companies. So we regarded for a technique to cut back prices.

Can We Sidestep the Drawback?

To optimize, I wanted to concentrate on the particular necessities of this use case. Node startups on the serverless product require solely a small set of photos to be pulled by a big set of nodes – this implies we’re fetching the identical set of keys again and again. A use case good for optimization by way of cache!

There have been two choices for caching: use one thing off-the-shelf (nginx on this case) or construct one thing completely new.

Nginx caching is proscribed as a result of it does not assist authentication. Nginx doesn’t have a built-in authentication course of that matches our use case. We experimented with completely different nginx configurations to work across the situation, however the cache hit fee merely was not excessive sufficient.

So the subsequent possibility was to construct one thing completely new – Harbor Frontend (Harbor FE).

Harbor FE acts as a write-through cache layer sitting between nginx and the opposite harbor parts. Harbor FE is just an HTTP server applied in golang that authenticates shoppers, forwards requests to harbor-core, and caches the responses. Since all nodes request the identical set of photos, as soon as the cache is heat, the hit fee stays close to 100%.

Harbor Frontend

Utilizing the brand new structure, we’re in a position to considerably cut back load to different harbor companies and the database (which is very essential since vertically scaling it’s the most possible possibility and is prohibitively costly). Most requests terminate at Harbor FE and by no means hit harbor-core, harbor-registry, or the DB. Additional, Harbor FE can serve virtually all requests from its in-memory cache, making it a extremely environment friendly use of cluster sources.

Harbor FE

With Harbor FE, we had been in a position to serve a capability of 450,000 LPM (or 1500 node startups per minute), all whereas utilizing 30x fewer CPUs at peak load than the historically scaled model.


In conclusion, the journey to enhance Harbor’s efficiency at Databricks has been each difficult and rewarding. By utilizing our present data of Docker, Kubernetes, Harbor, and golang, we had been in a position to study rapidly and make vital contributions to the Serverless product. By iterating swiftly and specializing in the correct metrics, we developed the `harbor-frontend` service, which allowed an efficient caching technique to attain 450,000 LPM, surpassing our preliminary goal of 300,000 LPM. The harbor-frontend service not solely decreased the load on different Harbor parts and the database but in addition offered further advantages comparable to larger visibility into Harbor operations, a platform so as to add options to container infrastructure, and future extensibility. Potential future enhancements embrace safety enhancements, altering the picture pull protocol, and implementing customized throttling logic.

On a private be aware, earlier than becoming a member of Databricks, I used to be informed that the corporate takes satisfaction in fostering a tradition of high-quality engineering and selling a supportive work surroundings full of humble, curious, and open-minded colleagues. I did not know the way true it might be till I joined the staff in January, missing data of the instruments essential to work together with Harbor, not to mention Harbor itself. From day one, I discovered myself surrounded by folks genuinely invested in my success, empowering my staff and me to deal with challenges with a smile on our faces.

I wish to prolong my gratitude to my mentor, Shuai Chang, my supervisor, Anders Liu, and challenge collaborators, Masud Khan and Simha Venkataramaiah. Moreover, I need to thank your entire OS and container platform staff for offering me with a very fantastic internship expertise.

Take a look at Careers at Databricks if you happen to’re occupied with becoming a member of our mission to assist knowledge groups remedy the world’s hardest issues.

Related Articles


Please enter your comment!
Please enter your name here

Stay Connected

- Advertisement -spot_img

Latest Articles