-
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
Handle task weights efficiently in TaskSet
s
#2820
Open
bakhtos
wants to merge
9
commits into
locustio:master
Choose a base branch
from
bakhtos:task-weights
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error is raised when the 'tasks' attribute is parsed if it is not a list or a dict And during the run() function
add: abstract _setup_tasks() method which processes tasks after filtering tags and is executed at run()
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
github-actions
bot
added
the
stale
Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
label
Sep 30, 2024
This PR was closed because it has been stalled for 10 days with no activity. |
cyberw
removed
the
stale
Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
label
Oct 11, 2024
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
github-actions
bot
added
the
stale
Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
label
Dec 11, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
stale
Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2651
After realising that my initial idea of storing a dictionary of task weights in
TaskSet
would not work due to incompatibility withSequentialTaskSet
and the rest of the code (many things in the codebase assumetasks
is a list, refactoring which will be too much work), I started from scratch compared to #2741 and here are the changes:TaskSet
andSequentialTaskSet
now use the same metaclass, which uses the sameget_tasks_from_base_classes
methodSequentialTaskSet
is moved to thetask.py
, since keeping it in a separate file is no longer sensibleget_tasks_from_base_classes
method will process all tasks in order they are declared and put them in a list (only one of each), adding alocust_task_weight
attribute with the corresponding weight if it is missing (which now all tasks are thus guaranteed to have)TaskSet
andSequentialTaskSet
will process this list of tasks as they need, adding necessary data structures (in new_setup_tasks()
method, see belowTaskSet
will calculate the cumulative weights necessary forrandom.choices
SequentialTaskSet
will expand thetasks
list into a list where tasks are duplicated according to the weight and make a cycle out of it@task
decorator can now receive also afloat
as a weightTo facilitate these changes, also inheritance of classes is changed:
AbstractTaskSet
class, which keeps most of the functionality that was previously in theTaskSet
(init, run, wait_time etc);TaskSet
,SequentialTaskSet
andDefaultTaskSet
all inherit this class_setup_tasks()
andget_next_task()
which concrete classes need to implement_setup_tasks()
is necessary since the originaltasks
attribute can be filtered using tags after class instantiation, so the actual preparation of additional data structures needs to happen later; this method is called byrun()
(also, some tests needed to call it explicitly since they check some things without callingrun()
, but this should not be a problemget_next_task()
is the method that provides the next task torun()
. Arguably, this is where the specialized logic of a newTaskSet
class would be implementedtasks
is empty is now the responsibility ofrun()
during its start. It is, after all, only necessary to do once and not on every call toget_next_task()
. If there are no tasks,LocustError
is raised. It is also raised byget_tasks_from_base_classes
iftasks
is not a dict or a list. Tests are also modified to check for this specific error rather thanException
.Test are modified to account for these changes.
I think this refactoring makes it easier to introduce new specialized Task Sets, since there is now a unified data model/interface that they should accommodate.