Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Michael Wahl
Michael Wahl

Posted on

     

Load Testing in Python with Locust.io

Once a Website, API, or App is developed, there is often a need to start testing performance. Another useful aspect of Load testing is to start building out operating cost models as you develop pricing for example.
Let's jump in and get started…
From a terminal: run
pip install locust
locust -f locust.py
loadtest % locust -f locust.py
[2021–01–06 09:58:29,316] mbp.lan/INFO/locust.main: Starting web interface athttp://0.0.0.0:8089 (accepting connections from all network interfaces)
[2021–01–06 09:58:29,322] mbp.lan/INFO/locust.main: Starting Locust 2.5.1
Open a Web browser and visit this page
http://localhost:8089/
Start a new load test
Set the number of total users to simulate
Set the spawn rate
Set the host
Start swarming
Details on the file below — locust.py
import time
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 5)
@task
def index_page(self):
self.client.get(url=”/hello”)
@task
def slow_page(self):
self.client.get(url=”/testsite”)

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

MBA, Tech and AI Leader | Strategy | 2 x AWS Certified | #AWSCommunityBuilders
  • Location
    Detroit, Michigan
  • Education
    MBA
  • Work
    VP - Technology and AI
  • Joined

More fromMichael Wahl

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp