How to efficiently stress test Pod memory
Chaos Mesh includes the StressChaos tool, which allows you to inject CPU and memory stress into your Pod. This tool can be very useful when you test or benchmark a CPU-sensitive or memory-sensitive program and want to know its behavior under pressure.
However, as we tested and used StressChaos, we found some issues with usability and performance. For example, why does StressChaos use far less memory than we configured? To correct these issues, we developed a new set of tests. In this article, I'll describe how we troubleshooted these issues and corrected them. This information will enable you to get the most out of StressChaos.
Before you continue, you need to install Chaos Mesh in your cluster. You can find detailed instructions on our website.
Injecting stress into a target
I’d like to demonstrate how to inject StressChaos into a target. In this example, I’ll use hello-kubernetes
, which is managed by helm charts. The first step is to clone the hello-kubernetes
repo and modify the chart to give it a resource limit.
git clone https://github.com/paulbouwer/hello-kubernetes.git
code deploy/helm/hello-kubernetes/values.yaml # or whichever editor you prefer
Find the resources line, and change it into:
resources:
requests:
memory: '200Mi'
limits:
memory: '500Mi'
However, before we inject anything, let's see how much memory the target is consuming. Go into the Pod and start a shell. Enter the following, substituting the name of your Pod for the one in the example:
kubectl exec -it -n hello-kubernetes hello-kubernetes-hello-world-b55bfcf68-8mln6 -- /bin/sh
Display a summary of memory usage. Enter:
/usr/src/app $ free -m
/usr/src/app $ top