locustio / locust

Write scalable load tests in plain Python 🚗💨
https://locust.cloud
MIT License
25.06k stars 2.99k forks source link

Run results show tasks action ratio may be incomprehensible。 #1003

Closed zhu-xiangtao closed 5 years ago

zhu-xiangtao commented 5 years ago

Description of issue

In Locust tasks class,define some specific tasks(just use ‘seq_task’ decorate, not use 'task' decorate),also use 'tasks' attribute associate these specific tasks,run results show tasks action ratio may be incomprehensible。

Environment settings

Steps to reproduce (for bug reports)

Locust tasks class as below:

class WebsiteTasks(TaskSequence):

def on_start(self):
    print "start hello imooc..."

@seq_task(1)
def hello_imooc(self):
    self.client.get("/imooc")

@seq_task(2)
def hello_imooc_1(self):
    self.client.get("/imooc_1")

@seq_task(3)
def hello_imooc_2(self):
    self.client.get("/imooc_2")

tasks = {hello_imooc:1, hello_imooc_1:4, hello_imooc_2:2}

Locust user class as below:

class WebsiteUser(HttpLocust): """test""" task_set = WebsiteTasks host = "http://www.imooc.com"

run in window cmd as below:

locust -f demo.py --logfile=111.log

In web use 1 uses and 1 hatch rate, run a moment, I found task 'hello_imooc' 、'hello_imooc_1'、‘helo_imooc_2’ requests ratio about 1:2.375:1.125,I think the raito may be about 1:4:2

In Locust.core.TaskSetMeta.init , I print some information

print "old_tasks: {}".format(new_tasks) for item in six.itervalues(classDict): print "item: {}".format(item) print hasattr(item, "locust_task_weight") if hasattr(item, "locust_task_weight"): print "item lociust task weight: {}".format(item.locust_task_weight) for i in xrange(0, item.locust_task_weight): new_tasks.append(item) print new_tasks

    print "new_tasks: {}".format(new_tasks)

In log file:

old tasks list, 'hello_imooc' 、'hello_imooc_1'、‘helo_imooc_2’, raito is 1:4:2

[2019-04-21 13:14:12,914] PC-20190216VJAU/INFO/stdout: old_tasks: [<function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc at 0x0000000004F20F28>, <function hello_imooc_2 at 0x0000000004F3B048>, <function hello_imooc_2 at 0x0000000004F3B048>]

new taks list, every task add one , raito is 2:5:3, as web run result。 [2019-04-21 13:14:12,914] PC-20190216VJAU/INFO/stdout: new_tasks: [<function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc at 0x0000000004F20F28>, <function hello_imooc_2 at 0x0000000004F3B048>, <function hello_imooc_2 at 0x0000000004F3B048>, <function hello_imooc_2 at 0x0000000004F3B048>, <function hello_imooc_1 at 0x0000000004F20F98>, <function hello_imooc at 0x0000000004F20F28>]

In Locust.core.seq_task, if task have no locust_task_weight attribute,will be assignment default value 1

def seq_task(order): def decorator_func(func): func.locust_task_order = order if not hasattr(func, 'locust_task_weight'): func.locust_task_weight = 1 return func

return decorator_func

I just think the weight raito should be make clear。 thanks

cgoldberg commented 5 years ago

can you be much more clear? I really have no idea what this issue report is about.