Way to use locust.io by supplying user list

前端 未结 4 2009
小蘑菇
小蘑菇 2020-12-23 10:00

I need to stress-test a system and http://locust.io seems like the best way to go about this. However, it looks like it is set up to use the same user every time. I need eac

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 10:33

    I took a slightly different approach when implementing this for a distributed system. I utilized a very simple flask server that I made a get call to during the on_start portion of the TaskSet.

    from flask import Flask, jsonify
    app = Flask(__name__)
    
    count = 0    #Shared Variable
    
    @app.route("/")
    def counter():
        global count
    
        count = count+1
        tenant = count // 5 + 1
        user = count % 5 + 1
    
        return jsonify({'count':count,'tenant':"load_tenant_{}".format(str(tenant)),'admin':"admin",'user':"load_user_{}".format(str(user))})
    
    if __name__ == "__main__":
        app.run()
    

    In this way I now have an endpoint I can get at http://localhost:5000/ on whatever host I run this. I just need to make this endpoint accessible to the slave systems and I wont have to worry about duplicate users or some type of round robin effect caused by having a limited set of user_info.

提交回复
热议问题