locustio / locust

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

Weight attribute on Locust class does not work #1160

Closed kob555 closed 4 years ago

kob555 commented 4 years ago

Describe the bug

Expected behavior

Actual behavior

Steps to reproduce

minimal.py

import datetime
from locust import task, TaskSet, constant, Locust

def Write(prefix):
    d = datetime.datetime.now()
    timestamp = d.strftime("%Y-%m-%d_%H-%M-%S-%f")
    directory = "C:\\TEMP"

    with open(directory + "\\" + prefix + "_" + timestamp + ".txt", "w") as text_file:
        text_file.write("")

class TaskSetA(TaskSet):
    @task
    def TaskA(self):
        print "TaskSetA started"
        Write("TaskSetA")

class TaskSetB(TaskSet):
    @task
    def TaskB(self):
        print "TaskSetB started"
        Write("TaskSetB")

class LocustA(Locust):
    weight = 1
    task_set = TaskSetA
    wait_time = constant(0.5)

class LocustB(Locust):
    weight = 9
    task_set = TaskSetB
    wait_time = constant(0.5)

Start it:

locust -f minimal.py

Go to web interface: http://localhost:8089/ Start swarming with these parameters:

Press stop after a while and count the files in the output directory:

ls -l|grep TaskSetA|wc
ls -l|grep TaskSetB|wc

There is a high discrepancy between the defined ratio 1:9 and the actual ratio of the files.

Environment settings

heyman commented 4 years ago

I'm not able to reproduce this. Here's the output I got after running this for a little while:

(locust) ~/projects/locust (master) § ls -l /tmp/locust-test | grep TaskSetA | wc -l
     303
(locust) ~/projects/locust (master) § ls -l /tmp/locust-test | grep TaskSetB | wc -l
    2707
heyman commented 4 years ago

I tested it in both Python 2.7 and Python 3.8 on Mac OS. Something windows related perhaps?

943 comes to mind.

kob555 commented 4 years ago

Thank you for your answer. It is very strange. Today, I'm not able to reproduce it anymore. For yesterday, I have many recorded test results, which show the discrepancy, but today, it works fine both on windows and inside a docker container. It could indeed be related to windows. Wouldn't be the first time.

heyman commented 4 years ago

Ok, happy it got solved somehow :).