Prequisite :
1. Install python
To check installed version of Python python -V
sudo yum install python-pip
pip --version
sudo pip install --upgrade pip
sudo pip install locustio
locust --help
Note : Locust installation is same for master and slave , use the below command to make the machine as master and slave .Copy load testing script in all machines
To start the Master
locust -f loadtest.py --master --host=master-ip --port 8089
[2018-08-27 16:19:10,216] /INFO/locust.main: Starting web monitor at *:8089
[2018-08-27 16:19:10,219] /INFO/locust.main: Starting Locust 0.8.1
To start the slave
Sample script :loadtest,py
***********************************************************
#!/usr/bin/python
import socket
import time
import datetime
import random
from locust import Locust, events, task, TaskSet
class SimpleClient(object):
def __init__(self):
self.host="ip address"
self.port=9003
self.counter=1
self.lat = 26.590706
self.lon= 74.913704
def execute(self,name):
start_time = time.time()
try:
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host,self.port))
dec_lat = random.random()/100
dec_lon = random.random()/100
x=datetime.datetime.now()
data="#Tamil,"+str(x.strftime("%Y%m%d%H%M%S"))+","+ str(self.lat+dec_lat)+","+str(self.lon+dec_lon)+","+str(self.counter)+"^\n";
sock.sendall(data)
self.counter +=1
except Exception as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(request_type="execute", name=name, response_time=total_time, exception=e)
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="execute", name=name, response_time=total_time, response_length=0)
class SimpleTasks(TaskSet):
@task
def simple_task(self):
self.client.execute('IP address:portno')
class SimpleUser(Locust):
def __init__(self, *args, **kwargs):
super(Locust, self).__init__(*args, **kwargs)
self.client=SimpleClient()
task_set=SimpleTasks
min_wait=1000
max_wait=10000
***********************************************************
In the example I have started locust on 2 slaves you can 2 slaves in the below image
1. Install python
To check installed version of Python python -V
sudo yum install python-pip
pip --version
sudo pip install --upgrade pip
sudo pip install locustio
locust --help
Note : Locust installation is same for master and slave , use the below command to make the machine as master and slave .Copy load testing script in all machines
To start the Master
locust -f loadtest.py --master --host=master-ip --port 8089
[2018-08-27 16:19:10,216] /INFO/locust.main: Starting web monitor at *:8089
[2018-08-27 16:19:10,219] /INFO/locust.main: Starting Locust 0.8.1
To start the slave
locust -f loadtest.py --slave --master-host=master-ip
Sample script :loadtest,py
***********************************************************
#!/usr/bin/python
import socket
import time
import datetime
import random
from locust import Locust, events, task, TaskSet
class SimpleClient(object):
def __init__(self):
self.host="ip address"
self.port=9003
self.counter=1
self.lat = 26.590706
self.lon= 74.913704
def execute(self,name):
start_time = time.time()
try:
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host,self.port))
dec_lat = random.random()/100
dec_lon = random.random()/100
x=datetime.datetime.now()
data="#Tamil,"+str(x.strftime("%Y%m%d%H%M%S"))+","+ str(self.lat+dec_lat)+","+str(self.lon+dec_lon)+","+str(self.counter)+"^\n";
sock.sendall(data)
self.counter +=1
except Exception as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(request_type="execute", name=name, response_time=total_time, exception=e)
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="execute", name=name, response_time=total_time, response_length=0)
class SimpleTasks(TaskSet):
@task
def simple_task(self):
self.client.execute('IP address:portno')
class SimpleUser(Locust):
def __init__(self, *args, **kwargs):
super(Locust, self).__init__(*args, **kwargs)
self.client=SimpleClient()
task_set=SimpleTasks
min_wait=1000
max_wait=10000
***********************************************************
you can check the UI of locust from browser
In the example I have started locust on 2 slaves you can 2 slaves in the below image
http://masterip:8089

No comments:
Post a Comment