JMeter vs LOCUST, which do you prefer ?

JMeter vs LOCUST, which do you prefer ?

JMeter? Need bit more Freedom? Here you GO “LOCUST”!

We all know Apache JMeter something we used for ages. Its good tool. As per my vision, Jmeter does not give us full freedom. Agree?

Why not Old school JMeter?

 

We all know Apache JMeter something we used for ages. Its good tool. As per my vision, JMeter does not give us full freedom to do. Agree?

What are the Limitations?

1. You cannot program the script

2. Limitation to execute a huge number of services / API’s in a single machine

3. Auto-correlation plugin It is recommended to run a load test in non-gui mode. All instances of JMeter should be closed while running a load test

4. If you are trying to copy an element, suppose a Regex Extractor, from a script open in one version of JMeter to a script open in another version, it will throw an error.

 

Here is the Magic in Locust

 

Write user test scenarios in plain-old Python

No need for clunky UIs or bloated XML—just code as you normally would. Based on coroutines instead of callbacks, your code looks and behaves like normal, blocking Python code.

 

Distributed & Scalable – supports hundreds of thousands of users

Locust supports running load tests distributed over multiple machines. Being event-based, even one Locust node can handle thousands of users in a single process. Part of the reason behind this is that even if you simulate that many users, not all are actively hitting your system. Often, users are idle figuring out what to do next. Requests per second != a number of users online.

 

Web-based UI 

Locust has a neat HTML+JS user interface that shows relevant test details in real-time. And since the UI is web-based, it’s cross-platform and easily extendable.

 

Hackable 

Locust is small and very hackable and we intend to keep it that way. All heavy-lifting of evented I/O and coroutines are delegated to gevent. The brittleness of alternative testing tools was the reason we created Locust.

 

An interesting solution made from it:

No alt text provided for this image

Locust has been used to simulate millions of simultaneous users. Battlelog, the web app for the Battlefield games, is load tested using Locust, so one can really say Locust is Battletested ;).

 

Let’s try this

 

Step one : Locust is available on PyPI and can be installed with pip.

for python 2.7

$ python -m pip install locustio

for Python 3:

python3 -m pip install locustio

If you want the bleeding edge version, you can use pip to install directly from our Git repository. For example, to install the master branch using Python 3:

$ python3 -m pip install -e git://github.com/locustio/[email protected]#egg=locustioL

to make sure you got in

locust --help

Lets do simple login function for your easiness

 

Assignment: Login function via Rest Services

from locust import HttpLocust, TaskSet, task 
from locust import clients
from locust.clients import HttpSession 
import requests
global BaseUrl 
class auth():
    
    BaseUrl = "https://[Your-server]-api.domain.co"
    #Auth API's Definitions
    def login( self,userName,passWord):
        s = HttpSession("https://[Your-server]-api.domain.co")
        response = s.post("https://[Your-server]-api.domain.co/auth/login", {"username":userName, "password":passWord})
        return response

    def getLogUser( self,accress_token):
        s = HttpSession("https://[Your-server]-api.domain.co")
        response = s.get("https://[Your-server]-api.domain.co/profile", headers={'access_token':accress_token})
        return response



These two services as you see

 

-Login request(Post) with the parameter Username and password

 

-Request(Get) to get profile information of the user

 

What we need next. send the parameter to this API and create some load 🙂

First, we need external data handling for the credentials. In my case, I kept.CSV file for store different credentials of the users. Let’s try to read and push the data to API’s

class runnerAgent(TaskSet):
    global json_data
    global accress_token
    global path
    global ccLogin
    global API_KEY
    global getAr
    global VarCD
   
    @task
    def Login(self):
        #Object from globle file 
        conf = config.config()
        path = conf.getLocation()
        #object from Admin Auth
        login = authAgent.authAgent()
        PWConbv = util.util()
        #radis Cache Initialization
        Rcache = redis.Redis(host='127.0.0.1', port=6379, db=0)
        with open('//oadTestv0.1/globe/credentials.csv') as csv_file:
            csv_reader = csv.reader(csv_file, delimiter=',')
            for row in csv_reader:
                print(" Login Agent with Username--->"+row[0]+" Who has Password --->"+row[1])
                #login Request 
                Loginresponse=login.login(row[0],row[1])
                print Loginresponse
       --> (*)  assert Loginresponse.status_code is 200, "Unexpected response code: " + Loginresponse.status_code
                json_data =json.loads(Loginresponse.text)
                accress_token =json_data['content']["access_token"] 
                ccLogin =json_data ['content']["ccLogin"]
                agentID=json_data['content']['id']
                print agentID
                ObjectAgent =json.dumps({ "UserName":row[0],"PassWord":row[1],"ccLogin":ccLogin,"id":agentID,"accress_token":accress_token})
                Rcache.set(row[0],ObjectAgent)
                API_KEY = conf.getAPI_key()
                print API_KEY
                if Loginresponse.status_code==200:
                    login.AutoLog(accress_token) 
                else:
                    login.login(row[0],EncriptedPW)
    
class LoginWithUniqueUsersTest(HttpLocust):
    task_set = runnerAgent


For initial try let’s not bother about the #radis cache or other JSON readings. Just try to assert response code — > (*)

Run the test: There are two methods you can run the test

 

-With GUI

$ locust -f locust_files/my_locust_file.py --host=http://example.com

You will the running port in your local machine :

Once you’ve started Locust using one of the above command lines, you should open up a browser and point it to http://127.0.0.1:8089 (if you are running Locust locally). Then you should be greeted with something like this:

No alt text provided for this image

A locust class represents one user (or a swarming locust if you will). Locust will spawn (hatch) one instance of the locust class for each user that is being simulated. There are a few attributes that a locust class should typically define.

You can check the real-time statistics too.

 

-Non-GUI

locust -f my_locust_file.py  --clients=02 --hatch-rate=01   --host=http://example.com  --no-web 

The console will print the summary for you.

 

References : gevent : http://www.gevent.org/

                       Locust : https://docs.locust.io/en/stable/what-is-locust.htmlhttps://locust.io/https://docs.locust.io/en/stable/index.html

 

elektrik faturası ödeme hgs bimcell tl yükleme avea tl yükleme seks malzemeleri vibratör erotik shop istanbul sex shop istanbul şişme manken realist manken sabiha gökçen araç kiralama tv reklam paketleri tv reklam e kitap indir bimcell tl yükleme