Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Distributed Load Testing Using Locust and Kuber...

Aditya Satrya
November 23, 2019

Distributed Load Testing Using Locust and Kubernetes

This deck is presented at PyCon Indonesia 2019.

Aditya Satrya

November 23, 2019
Tweet

More Decks by Aditya Satrya

Other Decks in Technology

Transcript

  1. Lead to decisions 9 ▷ Does the server have enough

    resources (CPU, memory, etc.) to handle the anticipated load? ▷ Does the server respond quickly enough to provide a good user experience? ▷ Is our application running efficiently? ▷ Do we need to scale up our server hardware, or scale out to multiple servers? ▷ Are there any pages or API calls that are particularly resource intensive?
  2. 11 ▷ Open source (MIT license) ▷ Supports Python 2.7,

    3.5, 3.6, 3.7, 3.8 ▷ https://locust.io/ ▷ https://github.com/locustio/locust
  3. What I like about Locust 12 ▷ Define user behaviour

    in Python code ▷ Distributed ▷ Run in command line or from UI ▷ Exportable result to CSV
  4. What is Kubernetes? 17 ▷ Open-source system for automating: ◦

    deployment ◦ scaling ◦ management of containerized applications
  5. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers
  6. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers
  7. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest
  8. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest
  9. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest frontend: 4/5 X
  10. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest frontend: 4/5
  11. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest frontend: 5/5
  12. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest Run 3 instances of backend:latest
  13. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest Run 3 instances of backend:latest Run 10 instances of analytics:latest analytics: 7/10 frontend: 4/5 backend: 3/3
  14. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest Run 3 instances of backend:latest Run 10 instances of analytics:latest
  15. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest Run 3 instances of backend:latest Run 10 instances of analytics:latest
  16. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    Master 1 Master 2 Master 3 Workers Run 5 instances of frontend:latest Run 3 instances of backend:latest Run 10 instances of analytics:latest analytics: 10/10 frontend: 5/5 backend: 3/3
  17. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    10.x.x.x label: analytics Services
  18. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    10.x.x.x label: analytics 10.x.x.x label: backend 10.x.x.x label: frontend Services
  19. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    10.x.x.x label: analytics 10.x.x.x label: backend 10.x.x.x label: frontend Services Internet
  20. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    10.x.x.x label: analytics 10.x.x.x label: backend 10.x.x.x label: frontend Cloud Load Balancer Services Internet
  21. Worker 1 Worker 2 Worker 3 Worker 4 Worker 5

    10.x.x.x label: analytics 10.x.x.x label: backend 10.x.x.x label: frontend Cloud Load Balancer stats.example.com api.example.com example.com Services Internet
  22. Target URLs 41 ▷ /profile ▷ /login ▷ /article/1 ▷

    /article/2 ▷ /article/3 ▷ /article/4 ▷ /article/5 ▷ /article/6 (will return 404) ▷ /article/7 (will return 404) ▷ /bottleneck (slow endpoint)
  23. Integrate with CI/CD (not in demo yet) 42 ▷ Setup

    cluster ▷ Deploy Locust master & slaves ▷ Run test ▷ Wait ▷ Stop test ▷ Read the result
  24. 43 # setup cluster # ... commands here … #

    start test curl -X POST -F 'locust_count=4' -F 'hatch_rate=4' http://locust-master:8089/swarm {"success": true, "message": "Swarming started"} # run test for 2 minutes sleep 2m # stop test curl http://locust-master:8089/stop {"success": true, "message": "Test stopped"} # download result curl http://locust-master:8089/stats/requests/csv # cleanup cluster gcloud container clusters delete locust-cluster