-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce SimpleTaskSet, a way to make super simple locust files without having to define a Locust class #1274
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1274 +/- ##
==========================================
+ Coverage 77.52% 77.82% +0.30%
==========================================
Files 20 20
Lines 1984 2002 +18
Branches 313 316 +3
==========================================
+ Hits 1538 1558 +20
+ Misses 368 364 -4
- Partials 78 80 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #1274 +/- ##
==========================================
- Coverage 80.16% 80.04% -0.12%
==========================================
Files 23 23
Lines 2067 2080 +13
Branches 319 323 +4
==========================================
+ Hits 1657 1665 +8
- Misses 332 336 +4
- Partials 78 79 +1
Continue to review full report at Codecov.
|
Interesting! I like that this can be done with pretty few changes. Here are some initial thoughts:
I'm not sure if I think it should be the default in the docs. Locust's power does not come from very small Apache Bench-like load tests, but rather from the ability to create realistic load by simulating real user behaviour. I think that this simplified approach is worse at communicating that. Especially since there's an implicit wait_time of 0. The typical real Locust test isn't 10, 20 or even a 100 lines of code. Therefore I'd say that the current "overhead" is almost negligible, and I think it can be negative if the typical real use-case is very different from the ones presented in examples to new users. |
Yes, that sounds like a very good plan, I will do that!
Sure, but if I manage to convince you (see below) that it should be the first introduction in the documentation I think it should be part of locust module.
I think most people start by making a very small tests and then expands from there (either because they thought the AB-like test would be enough and then change their minds, or just because that is a natural first step in developing a scenario). I think Locust needs to be documented primarily with the beginner in mind (because most of our users are not professional load testers), but allow for growth. I think the documentation can start out with simple_task but move on to the more complex cases later on. The good thing about the simple_task implementation is that it allows for this growth, without creating special cases. In my experience test plans start out small but can grow pretty big (although I'd say I average around 100 loc, and I still have never used nested tasksets and only rarely more than one Locust class in the same test :) But of course, the benefit of simple_task is not decreasing the lines of code but decreasing the complexity and cognitive load on the new locust user. |
Hmm, another alternative (which I believe you've suggested before), would be to allow task declarations directly on the Locust user class: class User(Locust):
@task
def t1(self):
pass What I like about that approach is that it is similar to the default way of declaring tasks, compared to introducing a new approach (with a |
Hmm.. but I thought you didnt like that? :) I guess that could work, but I think it would require more changes under the hood. But I guess it could be done. It would have to be a different decorator than the usual But what would the self reference point to? The task set instance? That would be very weird (because you are defining it on the locust) The locust? That would be ok, but very different from the normal behaviour. And could be hard to implement.
Hmm... I tried that but couldnt get it to work. The tasks need to be defined before calling |
I guess I would be ok with this though, if you think it is better, and worthy of making it the "default" :) (we can always just throw a descriptive exception if someone mixes the two) |
I'm not sure that I do, though I still might prefer it to introducing an additional approach for declaring tasks. The more I think about it, the more I feel skeptical about having two different ways of declaring tasks, and allowing
Yes, that's all things that we would need to consider, and it's very much part of the reasons why I'm not sure if it's a good idea. I think that the only logical thing would be to have
I think that it should be possible to do it with the same decorator. |
…et added to SimpleTaskSet.tasks, which is a little weird. But I havent found a way to know inside the decorator whether we are adding tasks to SimpleTaskSet or some other TaskSet
hmm... that last commit broke stuff... will try to fix it... |
…ly subtask SimpleTaskSet, and it will automatically set SimpleHttpLocust to be the locust class, and set SimpleHttpLocust.task_set to use the correct TaskSet.
So I'm quite happy with the change now. What could make it even easier for the user is if we just made this the default (so that it happens even when subclassing TaskSet, instead of SimpleTaskSet) If we had just made constant(0) the default sleep time when it was introduced it would have been one less hacky thing to do in main.py :) |
I think this would be a great simplification for new users of locust and I want it in as part of 1.0 (I'll update the docs too of course) Maybe @max-rocket-internet or @timran1 want to weigh in? |
…oduce-simple_task
@heyman Pretty please with sugar on top? :P I really think this change will do a lot of good for Locust's usability (for myself personally it doesnt matter much, I'm fine with having a couple of lines of extra code, and I know what it is used for, but I dont want to have to keep explaining to new users why they need to define a Locust class that in most basic cases doesnt really do anything) |
Closing this in favour of #1304 |
This allows you to define a locust plan like this:
I havent updated documentation yet, but I think this can be the default in the documentation, because it is 100 times less fuss & unnecessary settings for a new user :)
You could argue that SimpleTaskSet should default to FastHttpLocust instead of HttpLocust, if that is "the future"
I spent a lot of time implementing this but in the end the change is so small, I almost feel bad :)
This relates to #1264