LoginSignup
1
0

More than 5 years have passed since last update.

OpenRestyのDockerイメージを使って重いバックエンドをシミュレートする

Posted at

EnvoyなどのCircuit Breakerの検証のために、重いバックエンドをシミュレートしようと思ってます。nginx系のOpenRestyのコンテナイメージを使えば容易に実現できそうです。

起動

nginxでnon-blocking sleep - Qiita の記載を参考に、下記のような docker-compose.yml ファイルを用意、 docker-compose up する。

$ docker-compose up
docker-compose.yml
version: '3'
services:
  frontend:
    image: openresty/openresty:alpine
    command:
    - /bin/sh
    - -c
    - >
      echo '
      server {
        listen       8080;
        location / {
          proxy_pass http://heavy_backend:8081;
        }
      }
      '
      > /etc/nginx/conf.d/default.conf
      && /usr/local/openresty/bin/openresty -g 'daemon off;'
    ports:
    - "8080:8080"
  heavy_backend:
    image: openresty/openresty:alpine
    command:
    - /bin/sh
    - -c
    - >
      echo '
      server {
        listen       8081;
        location / {
          content_by_lua_block {
            ngx.sleep(1.234)
            ngx.say("Heavy")
          }
        }
      }
      '
      > /etc/nginx/conf.d/default.conf
      && /usr/local/openresty/bin/openresty -g 'daemon off;'

確認

$ time curl -i http://localhost:8080/
HTTP/1.1 200 OK
Server: openresty/1.13.6.2
Date: Thu, 23 Aug 2018 01:43:18 GMT
Content-Type: application/octet-stream
Content-Length: 6
Connection: keep-alive

Heavy

real    0m1.262s
user    0m0.007s
sys 0m0.007s

約1.234秒かかっていることが確認できた。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0