Giter Site home page Giter Site logo

valian / docker-nginx-test-page Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 4.0 6 KB

Smallest possible Nginx (OpenResty) image for testing load-balancing inside Docker cluster.

Home Page: https://hub.docker.com/r/valian/nginx-test-page/

License: MIT License

Shell 100.00%
nginx open-resty testing docker-alpine docker-image docker

docker-nginx-test-page's Introduction

docker-nginx-test-page

build

Smallest possible Nginx (OpenResty) image for testing load-balancing inside Docker cluster. I've created it because I wanted to stress-test Docker Swarm networking, and analyse results using ELK stack. It should work just fine with other orchestrators, like Kubernetes.

Preview

>> curl localhost
HOSTNAME=ef25379f3352
IP=12.122.122.12

>> curl localhost/recurse?count=5
12.122.122.12    04ac8923b523    Count 5
12.122.122.12    04ac8923b523    Count 4
12.122.122.12    04ac8923b523    Count 3
12.122.122.12    04ac8923b523    Count 2
12.122.122.12    04ac8923b523    Count 1
12.122.122.12    04ac8923b523    Count 0
# EXTERNAL-IP,   CONTAINER-ID,   COUNTER

# when we want to test load-balancing on a cluster:
# first, deploy this image with multiple replicas as a service, e.g. "nginx-test"
# second, make recurse request passing hostname as a target
>> curl 'cluster-ip/recurse?count=5&host=nginx-test/recurse'
12.122.122.15    f8f0e76d6e78    Count 5
12.122.122.12    04ac8923b523    Count 4
12.122.122.15    f8f0e76d6e78    Count 3
12.122.122.12    04ac8923b523    Count 2
12.122.122.15    f8f0e76d6e78    Count 1
12.122.122.12    04ac8923b523    Count 0

Features

  • Allows for creating recursive requests between containers, merging all responses
  • Logging in JSON format, ready to be shipped to e.g. logstash
  • No configuration
  • Small
  • High performance

Usage

Basic example

>> docker run --rm -it -p 80:80 valian/nginx-test-page

# in another terminal
>> curl localhost
HOSTNAME=ef25379f3352
IP=12.122.122.12

# You can try to restart container multiple times, you will always get proper containerID and public IP address.
# Not let's recurse
>> curl localhost/recurse?count=100
12.122.122.12    04ac8923b523    Count 100
12.122.122.12    04ac8923b523    Count 99
12.122.122.12    04ac8923b523    Count 98
...
12.122.122.12    04ac8923b523    Count 2
12.122.122.12    04ac8923b523    Count 1
12.122.122.12    04ac8923b523    Count 0

# Container made 100 requests to himself, because there's only one container running and there's no load balancing. 

Example using scaling in docker-compose:

# download docker-compose.yml from this repository
>> wget https://raw.githubusercontent.com/Valian/docker-nginx-test-page/master/docker-compose.yml

# run with 10 copies of a nginx-test container
>> docker-compose up --scale nginx-test=10

# in another terminal (we're using docker-compose run, because we can't scale services with open ports)
# notice different container IDs
>> docker-compose run --rm nginx-test curl 'nginx-test:80/recurse?count=100&host=nginx-test/recurse'
12.122.122.12    04ac8923b523    Count 100
12.122.122.12    2ca5192d79d9    Count 99
12.122.122.12    04ac8923b523    Count 98
...
12.122.122.12    c2be082a760c    Count 2
12.122.122.12    2ca5192d79d9    Count 1
12.122.122.12    c2be082a760c    Count 0

You can do pretty the same on a Docker Swarm or a Kubernetes cluster, to easily generate thousands of requests across containers. For example, each request to recurse?count=100 generates 100 requests between containers.

Implementation

This image is build on top of OpenResty, nginx with lua support. It's extremaly fast. This image uses capabilities of OpenResty to make recursive requests directly from nginx to nginx, without any other server. For more details, look into nginx.conf file.

Limitations

Very high values of count parameter may cause dropping connections, because it basically creates "chain" of requests, each waiting for last one to complete.

Licence

MIT

docker-nginx-test-page's People

Contributors

valian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.