Locust adalah sebuah tools yang dapat digunakan seorang Software QA Engineer untuk melakukan load testing aplikasi berbasis website. Load Testing dilakukan untuk mengetahui seberapa kemampuan system yang digunakan, berapa concurrent user dan berapa request per detik yang mampu dihandel oleh aplikasi tersebut.
Start new Locust swarm
Locust akan optimal jika berjalan di Unix Machine, tetapi untukā¦
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
ā Live Streamingā Interactive Chatā Private Showsā HD Quality
Anya is LIVE right now
FREE
Free to watch ⢠No registration required ⢠HD streaming
Locust: A python based distributed testing framework.
This blog post just summarizes my understanding of the framework. Refer documentation to see snippets to understand the notes below better.
Main features:
1) EventDriven Non-Blocking:
Locust helps achieve concurrency of higher rates than that can be achieved when using multiple threads or light weight process as in java. As each LWP uses some ram and the concurrency is limited by ram and cpu. The CPUās IO wait time increases and chokes the load average of the system.
In case of locust its built on gevent which in turn is built using greenlet and is tightly couple libevnt kernel lib (/dev/epoll) that propagates events. This event driven approach enables multiple task to execute in a single thread. Similar to javascript single thread event based loop execution.
Hence a greater concurrency or request can be achieved on smaller configuration of ram and cpu.
gevent over greenlet wraps callback structure of libevent to simpler synchronized constructs that can be used to make programming simple and avoid callback hell.
Note: More info of getevn and greenlet will be inĀ separateĀ blog post
2) RealTime metrics:
Locust also enables realtime view of request and response outcome, throughput etc.. unlike other test framework where post test is when we find reports of the test.
Installation:
Note: Ensure you have libeven installed
pip install locustio
orĀ
easy_install locustio
Note: using virtualenv is better to work with different lib and version of python
Distributed load testing in locust is achieved by pyzmq (ZeroMQ)
The intercommunication across test running in different boxes is through pyzmq
Distributed mode involves master running just the UI and orchestrating the slaves rather than actually running the test. master takes care of dividing the load and number of users across slaves equally and collects statics from the slaves
Master runs a server on its hosts on port 5997(default can be changed) and the slaves when started are specified the host and port of master to connect to
starting master and slave is as simple as
locust -f <path to locust file> --master
locust -f <path to locust file> --slave master-host=<master host ip>Ā
Main Framework classes:
Locust - Parent class that represents a User
So based on the run (Number of Users and spawn rate i.e. number of instance of users created per second which is number of instance of Locust class created) that many Locust Instances are created
Now Locust framework manages instantiation of Locust Instances and specific core attributes
taskset-> this attribute binds a Locust class to a TaskSet class.
This is one to One.. One locust class binds only to one TaskSet
min_wait and max_wait define time to wait betweenĀ taking actions defined inside the taskset mapped to it. Note(These can be overidden in taskset class implementation
Incase of HttpLocust and implementation of Locust.. client variable is associated to this which is a wrapper of HttpSession client that manages all cookie based http session logged token between request.
HttpLocust also defines other attributes like host etc..
TaskSetĀ - ParentĀ classĀ that representsĀ Users behavior
TaskSet is a collection of tasks.
collection of task can be defined by tasks= [task] array
or tasks={task:weight..} map
or @task(weight) anno above the task method
Note that by first approach no weight is implied
A task inside taskset can be a method def sometask(taskSetRef):
or can be another TaskSetClass (class defining sequential behavior
Incase of sequential behavior the other TaskSet can be external class implementing TaskSet and added to parent TaskSet tasks=[OtherTaskSet]
or a subclass defined inside ParentTaskSet with @task anno.
NestedTaskSet enable sequential execution as task inside one taskset run in random order based on weightage
When building nested TaskSet its essential to build one task as
def stop(self):
Ā self.interrupt(); // this quits the execution of child taskset and returns to parent
self inside the callables of each task refer to taskset Instance and have the following default attributes
self.locust - represent the locust running this taskset
self.parent - can be locust in case of the parent taskset else the parent taskset of the child taskset
Other classes include:
web - a wrapper over Flask python api to build controllers
Events in locusts.events to listen to success, failure, hatch events.
HttpLocust specific classes like HttpSession and HttpSessionManager with catching exceptions and making rest calls.Ā