Performance Testing of an Application via Locust
Performance Testing of an Application via Locust
Performance Testing of an Application via Locust
Are you a developer who is looking forward to performing load testing on your application?
You might have heard about tools like Apache JMeter, SmartMeter, WebLOAD, etc. All these tools require some installation efforts and also familiarity with the usage.
In case you are new to this and want to rapidly implement load testing, then Locust tool written in Python is the go-to solution for your problem. It’s a one-line installation on your Linux Terminal as shown below:
Use this single line string for the installation :
pip3 install -e git://github.com/locustio/locust.git@master#egg=locust
Once we are done with the installation you can just log out and login into you shell and verify it later by: “locust -V”.
Once verification is done, we can look for APIs in GET and POST for testing:
You need to make a file in which we can write classes involving HTTP packages for interacting with all API’s and make relevant tasks to check for all APIs, the configuration file looks like this :
As you can see I have used the locust library and relevant HttpUser packages.
You will have the IP address of your server, and you can create task annotations followed by the writing of the APIs to be tested with relevant headers, the JSON data to be passed.
Here is the link to the file.
from locust import HttpUser, task, between
class MyUser(HttpUser):
wait_time = between(5, 15)
@task
def index(self):
ip_addr="" ##your IP address
session_key="" ##your session key
self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","fromDate":0,"page":0,"paymentTypeId":0,
"size":10,"toDate":0,"url":"{ip_addr}/Pays/report/blockedAmount"},name="blocked Amount")
response=self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'}
,json={"username": "pays", "password": "pays","keykjm":"{session_key}","couponCode":"FGDFGFGFGHMZDGQQ","platForm":"iOs",
"url":"{ip_addr}/Pays/consumer/couponScanReferral"},name="coupon scan referral scan")
resp2=self.client.get("/Pays/base/entity/PaymentType/findAll",auth=("pays","pays"))
print("response for get is",resp2.content)
self.client.get("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","url":"{ip_addr}/Pays/accountDetails/pointsAccrual"},
name="points accrual transaction list")
self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","fromDate":0,"page":0,"paymentTypeId":0,"size":10,
"toDate":0,"url":"{ip_addr}/Pays/umnbv/cvocjk3"},name="OTP verification")
my_json={"deviceMfgName":"ghsdgfj","deviceOs":"android","deviceOsVersion":"ghsdgfj","dveiceModel":"ghsdgfj","deviceuuid":"ghsdgfj","sim1Carriername":"ghsdgfj","sim1CountryCode":"ghsdgfj","sim1mcc":"jk","sim1mnc":"jk","sim1Serial":"jk","sim1Phone":"jk","sim1Imei":"jk","sim2Carriername":"jk","sim2CountryCode":"jk","sim2mcc":"jk","sim2mnc":"jk","sim2Serial":"jk","sim2Phone":"jk","sim2Imei":"jk","postalCode":"7848567","administrativeArea":"hdsgj","subAdministrativeArea":"7848567","locality":"7848567","subLocality":"7848567","latitude": "7848567","longitude": "7848567","version":"1.0.7"}
response=self.client.post(url="/Pays/umnbv/versionValidate",headers = {"content-type": "application/json","Authorization": "Basic cGF5czpwYXlz"},json=my_json,auth=("pays","pays"),name="Dashboard API")
Once you have prepared the file, we can run it by using “locust -f filename.py”.
Your execution will start at port number 8089 and can be seen in the browser:
We will give the entries for emulation, like 10000 users to be spawned within every 100 seconds, also the IP address and the port number on which the webserver is running, for me it is 8880 (Apache Tomcat server).
You can monitor different types of charts for checking out the response times of the APIs:
Along with this, you can parallelly check for failures and also the CPU utilization of your server by using “htop”:
Once you feel that the CPU is handling the application load very well, you can go forward confidently.
For any further queries or anything related to DevOps or troubleshooting or load testing in Python, you can DM me on Linkedin or Instagram. id=acanubhav94.
Are you a developer who is looking forward to performing load testing on your application?
You might have heard about tools like Apache JMeter, SmartMeter, WebLOAD, etc. All these tools require some installation efforts and also familiarity with the usage.
In case you are new to this and want to rapidly implement load testing, then Locust tool written in Python is the go-to solution for your problem. It’s a one-line installation on your Linux Terminal as shown below:
Use this single line string for the installation :
pip3 install -e git://github.com/locustio/locust.git@master#egg=locust
Once we are done with the installation you can just log out and login into you shell and verify it later by: “locust -V”.
Once verification is done, we can look for APIs in GET and POST for testing:
You need to make a file in which we can write classes involving HTTP packages for interacting with all API’s and make relevant tasks to check for all APIs, the configuration file looks like this :
As you can see I have used the locust library and relevant HttpUser packages.
You will have the IP address of your server, and you can create task annotations followed by the writing of the APIs to be tested with relevant headers, the JSON data to be passed.
Here is the link to the file.
from locust import HttpUser, task, between
class MyUser(HttpUser):
wait_time = between(5, 15)
@task
def index(self):
ip_addr="" ##your IP address
session_key="" ##your session key
self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","fromDate":0,"page":0,"paymentTypeId":0,
"size":10,"toDate":0,"url":"{ip_addr}/Pays/report/blockedAmount"},name="blocked Amount")
response=self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'}
,json={"username": "pays", "password": "pays","keykjm":"{session_key}","couponCode":"FGDFGFGFGHMZDGQQ","platForm":"iOs",
"url":"{ip_addr}/Pays/consumer/couponScanReferral"},name="coupon scan referral scan")
resp2=self.client.get("/Pays/base/entity/PaymentType/findAll",auth=("pays","pays"))
print("response for get is",resp2.content)
self.client.get("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","url":"{ip_addr}/Pays/accountDetails/pointsAccrual"},
name="points accrual transaction list")
self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","fromDate":0,"page":0,"paymentTypeId":0,"size":10,
"toDate":0,"url":"{ip_addr}/Pays/umnbv/cvocjk3"},name="OTP verification")
my_json={"deviceMfgName":"ghsdgfj","deviceOs":"android","deviceOsVersion":"ghsdgfj","dveiceModel":"ghsdgfj","deviceuuid":"ghsdgfj","sim1Carriername":"ghsdgfj","sim1CountryCode":"ghsdgfj","sim1mcc":"jk","sim1mnc":"jk","sim1Serial":"jk","sim1Phone":"jk","sim1Imei":"jk","sim2Carriername":"jk","sim2CountryCode":"jk","sim2mcc":"jk","sim2mnc":"jk","sim2Serial":"jk","sim2Phone":"jk","sim2Imei":"jk","postalCode":"7848567","administrativeArea":"hdsgj","subAdministrativeArea":"7848567","locality":"7848567","subLocality":"7848567","latitude": "7848567","longitude": "7848567","version":"1.0.7"}
response=self.client.post(url="/Pays/umnbv/versionValidate",headers = {"content-type": "application/json","Authorization": "Basic cGF5czpwYXlz"},json=my_json,auth=("pays","pays"),name="Dashboard API")
Once you have prepared the file, we can run it by using “locust -f filename.py”.
Your execution will start at port number 8089 and can be seen in the browser:
We will give the entries for emulation, like 10000 users to be spawned within every 100 seconds, also the IP address and the port number on which the webserver is running, for me it is 8880 (Apache Tomcat server).
You can monitor different types of charts for checking out the response times of the APIs:
Along with this, you can parallelly check for failures and also the CPU utilization of your server by using “htop”:
Once you feel that the CPU is handling the application load very well, you can go forward confidently.
For any further queries or anything related to DevOps or troubleshooting or load testing in Python, you can DM me on Linkedin or Instagram. id=acanubhav94.
Are you a developer who is looking forward to performing load testing on your application?
You might have heard about tools like Apache JMeter, SmartMeter, WebLOAD, etc. All these tools require some installation efforts and also familiarity with the usage.
In case you are new to this and want to rapidly implement load testing, then Locust tool written in Python is the go-to solution for your problem. It’s a one-line installation on your Linux Terminal as shown below:
Use this single line string for the installation :
pip3 install -e git://github.com/locustio/locust.git@master#egg=locust
Once we are done with the installation you can just log out and login into you shell and verify it later by: “locust -V”.
Once verification is done, we can look for APIs in GET and POST for testing:
You need to make a file in which we can write classes involving HTTP packages for interacting with all API’s and make relevant tasks to check for all APIs, the configuration file looks like this :
As you can see I have used the locust library and relevant HttpUser packages.
You will have the IP address of your server, and you can create task annotations followed by the writing of the APIs to be tested with relevant headers, the JSON data to be passed.
Here is the link to the file.
from locust import HttpUser, task, between
class MyUser(HttpUser):
wait_time = between(5, 15)
@task
def index(self):
ip_addr="" ##your IP address
session_key="" ##your session key
self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","fromDate":0,"page":0,"paymentTypeId":0,
"size":10,"toDate":0,"url":"{ip_addr}/Pays/report/blockedAmount"},name="blocked Amount")
response=self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'}
,json={"username": "pays", "password": "pays","keykjm":"{session_key}","couponCode":"FGDFGFGFGHMZDGQQ","platForm":"iOs",
"url":"{ip_addr}/Pays/consumer/couponScanReferral"},name="coupon scan referral scan")
resp2=self.client.get("/Pays/base/entity/PaymentType/findAll",auth=("pays","pays"))
print("response for get is",resp2.content)
self.client.get("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","url":"{ip_addr}/Pays/accountDetails/pointsAccrual"},
name="points accrual transaction list")
self.client.post("",headers = {"content-type": "application/json","Authorization": "Basic" + 'cGF5czpwYXlz'},
json={"username": "pays", "password": "pays","keykjm":"{session_key}","fromDate":0,"page":0,"paymentTypeId":0,"size":10,
"toDate":0,"url":"{ip_addr}/Pays/umnbv/cvocjk3"},name="OTP verification")
my_json={"deviceMfgName":"ghsdgfj","deviceOs":"android","deviceOsVersion":"ghsdgfj","dveiceModel":"ghsdgfj","deviceuuid":"ghsdgfj","sim1Carriername":"ghsdgfj","sim1CountryCode":"ghsdgfj","sim1mcc":"jk","sim1mnc":"jk","sim1Serial":"jk","sim1Phone":"jk","sim1Imei":"jk","sim2Carriername":"jk","sim2CountryCode":"jk","sim2mcc":"jk","sim2mnc":"jk","sim2Serial":"jk","sim2Phone":"jk","sim2Imei":"jk","postalCode":"7848567","administrativeArea":"hdsgj","subAdministrativeArea":"7848567","locality":"7848567","subLocality":"7848567","latitude": "7848567","longitude": "7848567","version":"1.0.7"}
response=self.client.post(url="/Pays/umnbv/versionValidate",headers = {"content-type": "application/json","Authorization": "Basic cGF5czpwYXlz"},json=my_json,auth=("pays","pays"),name="Dashboard API")
Once you have prepared the file, we can run it by using “locust -f filename.py”.
Your execution will start at port number 8089 and can be seen in the browser:
We will give the entries for emulation, like 10000 users to be spawned within every 100 seconds, also the IP address and the port number on which the webserver is running, for me it is 8880 (Apache Tomcat server).
You can monitor different types of charts for checking out the response times of the APIs:
Along with this, you can parallelly check for failures and also the CPU utilization of your server by using “htop”:
Once you feel that the CPU is handling the application load very well, you can go forward confidently.
For any further queries or anything related to DevOps or troubleshooting or load testing in Python, you can DM me on Linkedin or Instagram. id=acanubhav94.