Alright, so you want to test how your application fares with questionable network reliability. If you can get your application running in a docker container, this write-up will have you covered.
We're going to utilize linux's tc
to control the outbound network connection. There's no easy way to do inbound yet. From that we'll be able to throttle and drop packets outbound which should give you a fair test of unreliable networks.
This dockerfile utilizes the ubuntu
image which was necessary for my purposes, but can be generalized to other docker imagers as per your use case.
FROM ubuntu
RUN apt-get update
RUN apt-get install -y ca-certificates iproute2
# -----
# The rest of your docker file
# -----
The important bit to notice here is that we install iproute2
(and, depending on whom you're communicating with, you may need ca-ceritifcates
for certain SSL connections) onto the container. This installs tc
.
Download the excellent tool pumba. Set it up on your path.
Assuming that you build your image with
docker build . -t my_image
you can run
docker run --name=network_test my_image
Once this is working, initiae your test. Use the pumba command to begin your network throttling:
pumba netem --duration 5m delay --time 3000 loss --percentage 30 corrupt --percent 30