cs1675 microservices

Microservices

Introduction

In this project, you will implement, optimize, and evaluate the performance of a microservice-structured application. The exact application is up to you. You can build the default application, Welp, or propose and build your own.

Whichever option you pick, this project will focus on measuring and improving the performance of your application. We will focus on the application’s storage, and the impact of persistence, failures, placement, and caching on its performance.

Requirements

Summary of Deliverables

We will discuss the following aspects of your report. As in past projects, our discussion will take the format of a skeptical user or reviewer who you will convince of your report’s correctness.

In-Memory vs. Persistent Storage Performance

You should implement in-memory (i.e., ephemeral) and persistent state storage for your application.

Your implementation of persistent state storage must maintain the application’s correctness, including in cases where arbitrary application microservices crash. You should test that this works (e.g., by running kubectl -n 1675-microservices delete pod -l name=database or equivalent halfway through your test, let a kubernetes Deployment restart it automatically, and ensure no data is lost). It is allowed to use an existing off-the-shelf data store, but you are responsible for using it correctly to ensure correctness.

Your report should both quantify the difference in end-to-end performance and explain this difference with quantitative evidence. In previous projects, we used perf to generate flamegraphs for this purpose. However, running perf in Kubernetes environments is usually not possible in real deployments.

As a result, you will have to implement a different method of gathering instrumentation data. A simple implementation might modify the application to add some logging. A more complicated implementation could, for example, deploy as a dependency an eBPF monitoring tool such as Tetragon.

Service Placement

Running containers with Kubernetes raises a question: which pods should run on which nodes? By default, Kubernetes will schedule pods onto nodes by their resource use. It is possible to control pod scheduling with node labels. The idea is that your manifest can declare that a pod should run on a node with some property. When you deploy your app, you should assign labels to your Kubernetes nodes as described in the docs. You can then write a “node selector” in your pod declaration as described in the linked docs to control which pods run on which node.

Your report should evaluate the performance impact of using node selectors compared to the default Kubernetes configuration.

Implement and Deploy Cache Service

Even an optimized persistent storage implementation will have some performance overhead relative to the in-memory configuration. To optimize this further, design and deploy a cache microservice. You can either implement the cache yourself or modify an off-the-shelf implementation such as memcached.

Whichever option you pick, you should implement two different cache designs which differ in their access (e.g., look-aside vs look-through) and/or eviction (e.g., FIFO vs LRU) policies. Your report should explain your two designs and include a quantitative evaluation of their effectiveness, comparing at least the following configurations:

Evaluate both cache designs at a range of cache sizes.

Setup

wrk2 setup

We can test our application for correctness using curl. Eventually, though, we want to stress-test our implementation. Although in previous class projects we implemented the load generator ourselves, for this project we recommend wrk2, an HTTP load generator.

wrk2 uses a submodule for LuaJIT, one of its dependencies. Make sure you check out the submodule by running git submodule update --init --recursive.

To compile wrk2 (if not using Debian/Ubuntu, you’ll need the equivalent packages on your distro):

cd wrk2
sudo apt install luarocks lua5.1 liblua5.1-0-dev libssl-dev libz-dev make
sudo luarocks --lua-version 5.1 install luasocket
make

wrk2 embeds LuaJIT, which is compatible with Lua 5.1, so luasocket must be installed for Lua 5.1 (hence --lua-version 5.1). If you install it for your system’s default Lua version instead, workload scripts will fail at require("socket").

We’ve also provided a Dockerfile, at wrk2/Dockerfile, to help build wrk2. This should help those of you who need to run on macOS. Build the image from inside the wrk2 directory with docker build -t wrk2:1 .. The image does not contain your workload scripts (or, for Welp, the sample data they read), so mount them into the container when you run it. You’ll also want to run the container with --network host, so that you can send traffic from wrk2 as if it was on your host network. For example, from the root of this repository, with welp-util added as a submodule:

docker run --rm --network host -v "$PWD:/project" wrk2:1 \
    ./wrk -D const -t 1 -c 1 -d 30s -R 5 -s /project/welp-util/workloads/zipf-mixed.lua http://<ip>:<port>

On macOS, --network host only works on Docker Desktop 4.34 or later, and only after enabling host networking under Settings → Resources → Network. Without it, the container cannot reach services on your host’s localhost.

Once you can run wrk2, you can write a workload script. The welp-util repository, at https://github.com/cs1675/welp-util, includes workload scripts you can use (if building Welp); see its README for how to add it to this repository as a submodule. Otherwise, you can easily adapt the wrk2 scripts to your application’s format.

Kubernetes Setup

Kubernetes is an automated containerized application management platform used for deploying, scaling, and managing applications using containers. It makes it easier to implement common management features like configuring containers (by making the config declarative), providing resilience by automatically restarting containers when they crash, and scalability by starting new container instances in response to pre-defined criteria. Docker runs containers; Kubernetes (abbreviated k8s) manages those containers . A major part of this project is administering your compute cluster and configuring your application to run on Kubernetes.

A note on vocab: You will see the term “pod” appear below. For the purpose of this project, the Kubernetes term “pod” and the term “container” we used in class are interchangeable. You can read more about the exact difference here; basically, in some deployments, a pod can consist of multiple containers. A Kubernetes “deployment” is a set of pods to start (and re-start if they fail).

To test using Kubernetes locally, the easiest way is to use Minikube, which is a lighter-weight version of the same functionality designed for testing environments. Follow Minikube’s instructions to set it up. We also recommend using Helm, a way of installing applications in Kubernetes clusters, for this project. You can install Helm from its instructions.

Even if you are building your own application other than Welp, you may find it useful to look at our welp-util starter repository and its stub Kubernetes configuration files.

Local Running on Minikube

Other useful kubectl commands (our application runs in the 1675-microservices namespace, so pass -n 1675-microservices, or kubectl will look in the default namespace and find nothing): - kubectl -n 1675-microservices get deployments to see running deployments. - kubectl -n 1675-microservices get pods to see running pods. - kubectl -n 1675-microservices exec -it <pod-name> -- /bin/bash to enter a pod.

Evaluation on Cloudlab

Instead of running on class VMs as in previous projects, for this project you will run your own Kubernetes cluster using Cloudlab. You should make an account and request to join the class’s Cloudlab “project” (join link will be on EdStem). On Cloudlab, we won’t use Minikube, since we have multiple nodes to work with. Instead, we will run a cluster with kubeadm. The project repository has some helper scripts, in kubernetes-setup, for setting up kubeadm on a Cloudlab cluster. You can use the same Helm chart you use with Minikube to deploy on your kubeadm-controlled cluster on Cloudlab.

Remember that Cloudlab experiments automatically expire after some time (default is 16 hours, but you can request extensions). As a result, it will be very useful to write a reproducible script that handles setting up fresh Cloudlab machines with Kubernetes so you can run your experiments.