How to run 150 instances of edge application

The dev team faced recently a problem of handling to many requests at once. It happens in the largest factory during the shift change. Whenever a new brigade starts the duty they simply switch on their machines which ends up as requests flood coming at the weak and fragile central server.

To find a solution they first needed to run around 150 instances of the edge application at once in a lab environment. Obviously they couldn’t bring 150 machines from the factory into the office.

And here comes my approach based on Docker. I have put their edge app into an image and I have written a little script that brings up as many containers as they wish. This made them happy however a drawback of this approach appeared pretty quickly – all request from all containers arrived at the central server sourced from the same IP address and this obviously does not represent the actual behavior of the factory.

OK lets tweak this.

First we can bring up as many IP aliases on a single network interface as we wish. Then we can bind each container to specific IP of the host. We can do this with well known -p switch as follows

docker run -p host_address:host_port:container_port image_name 

You can test this by yourself.

In this example my WiFi interface wlp0s20f3 already has an IP Let’s bring up two aliases

ifconfig wlp0s20f3:0 up
ifconfig wlp0s20f3:1 up

This way my PC gained two additional IP’s .154 and .155

wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet  netmask  broadcast
wlp0s20f3:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet  netmask  broadcast

wlp0s20f3:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet  netmask  broadcast

Lets use nginx for the sake of simlicity. Starting three containes and binding them individually to certain IP address looks like this

docker run -p -v ${PWD}:/usr/share/nginx/html nginx
docker run -p -v ${PWD}:/usr/share/nginx/html nginx
docker run -p -v ${PWD}:/usr/share/nginx/html nginx

Pay attention that I use port 8080 three times here. It would fail if the IP binding would’t be successful. I also attach three different index.html per each container to observe that the response differs depending on the requested IP address.

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany.