-
-
Notifications
You must be signed in to change notification settings - Fork 876
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
Configurable batch size for JIRA._fetch_pages()
and dependant methods
#1394
Conversation
___ Jannik Meinecke <jannik.meinecke@mercedes-benz.com> on behalf of MBition GmbH. https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md
___ Jannik Meinecke <jannik.meinecke@mercedes-benz.com> on behalf of MBition GmbH. https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md
Required change in Jannik Meinecke (jannik.meinecke@mercedes-benz.com) on behalf of MBition GmbH. |
I'm not sure what this entails ... it seems just like offering a different way of doing the same thing 🤔 |
Maybe setting a batch size for the whole jira class seems more logical instead of adding it for quite some methods? => If you would be in dire need for a speedup quickly, probably a quick fix would be to increase the default batch size to 100 🤔? @adehad @ssbarnea some architectural guidance is welcome :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe setting a batch size for the whole jira class seems more logical instead of adding it for quite some methods? => Would there be a disadvantage for having a large batch size on shorter queries? I see your improvement from 41s to 6s is pretty significant so its definitly worth continuing this train of thought. I'm just trying to prevent tons of parameters being added to methods... It's often seen as a code smell if your parameter list is getting too large ...
If you would be in dire need for a speedup quickly, probably a quick fix would be to increase the default batch size to 100 🤔? although I like it to be configurable
@adehad @ssbarnea some architectural guidance is welcome :-)
@rynkk, thanks for this. Especially as this is one of the more convoluted areas in the code.
As suggested by @studioj I believe this batch size needs to be set at a class instance level. i.e. in here something like DEFAULT_BATCH_SIZE
Line 343 in 6789038
DEFAULT_OPTIONS = { |
I completely understand where you are coming from with wanting to set this per function. It provides the most flexibility, especially as you will likely have more issues than dashboards and therefore would want to set it differently for different resources. Also scales differently depending on how fast the server is you are working with.
A solution I would prefer if you strongly would like to set this per endpoint might look like so:
# within the DEFAULT_OPTIONS
# A dict of (Resource Type, Batch Size)
DEFAULT_BATCH_SIZE: Dict[Resource, int] = {
Issue : 500,
Resource: 100, # or 50 or whatever we want as a default now
}
...
# inside the JIRA.__init__
self.options["default_batch_size"] = DEFAULT_BATCH_SIZE
self.options["default_batch_size"].update(default_batch_sizes) # or whatever the argument name is
...
# now inside fetch pages
if maxResults:
page_params["maxResults"] = maxResults
else: # will need to set batch size to get all resources
page_params["maxResults"] = self.options["default_batch_size"].get(item_type, self.options["default_batch_size"].get(Resource))
_LOG.verbose(f"Batch size for {item_type.__name__} set to {page_params["maxResults"]}")
There might be problems with this approach too, but I feel it may be more ergonomic for advanced users such as yourself without confusing/bogging down more casual users
@adehad, @studioj, I agree, not having to specify the batch_size for every request is less error-prone and more user-friendly, while the dict-config allows the required configurability. I implemented the requested changes with some addition: I also adjusted the tests. Seems like the test for Jannik Meinecke (jannik.meinecke@mercedes-benz.com) on behalf of MBition GmbH. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great!
fetch_pages()
and the way we handle async
needs its own refactoring at some point so don't worry about it for now.
@rynkk you should also rebase/merge the latest main if you haven't already, as we've fixed some build problems |
___ Jannik Meinecke <jannik.meinecke@mercedes-benz.com> on behalf of MBition GmbH. https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md
___ Jannik Meinecke <jannik.meinecke@mercedes-benz.com> on behalf of MBition GmbH. https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md
Changes implemented, some modifications of my own, as well. Tests pass, docs do not. Some issue with not being able to map Jannik Meinecke (jannik.meinecke@mercedes-benz.com) on behalf of MBition GmbH. |
___ Jannik Meinecke <jannik.meinecke@mercedes-benz.com> on behalf of MBition GmbH. https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff, almost ready, let's see if we can fix the build
--- <sub>Jannik Meinecke (<jannik.meinecke@mercedes-benz.com>) on behalf of MBition GmbH. [Provider Information](https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md)</sub>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 1 change and then I'm happy, @studioj any further thoughts?
--- <sub>Jannik Meinecke (<jannik.meinecke@mercedes-benz.com>) on behalf of MBition GmbH. [Provider Information](https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md)</sub>
Issue-default removed, tests & docs adjusted :-) Jannik Meinecke (jannik.meinecke@mercedes-benz.com) on behalf of MBition GmbH. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, looks good to me, will wait a bit to see if @studioj has any comments.
Thanks for pushing through with this.
jira/client.py
Outdated
``{Issue: 500, Resources: None}`` will make :py:meth:`search_issues` query Issues in batches of 500, while | ||
every other item type's batch-size will be controlled by the backend. (Default: None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really excellent documentation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems pretty thourough although I'm counting on @adehad for the details :P
@@ -716,6 +730,8 @@ def _fetch_pages( | |||
page_params["startAt"] = startAt | |||
if maxResults: | |||
page_params["maxResults"] = maxResults | |||
elif batch_size := self._get_batch_size(item_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the first walrus operator we're using?
somebody has to go first :)
I must admit I'm not used to it yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an honor (for some). Just have to be very careful about braces when using it..
___ Jannik Meinecke (<jannik.meinecke@mercedes-benz.com>) on behalf of MBition GmbH. [Provider Information](https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md)
Found typos in the Jannik Meinecke (jannik.meinecke@mercedes-benz.com) on behalf of MBition GmbH. |
Hi, Jannik Meinecke (jannik.meinecke@mercedes-benz.com) on behalf of MBition GmbH. |
Sorry @rynkk haven't had much free time, am having a bit more now so will try and push this through |
JIRA._fetch_pages()
and dependant methods
Thanks again for pushing through with this |
Add
batch_size
argument toJIRA._fetch_pages
and dependant methods.This allows for significant performance improvements when trying to retrieve a lot of items using
maxResults=False
.fixes #1393
The program was tested solely for our own use cases, which might differ from yours.
Jannik Meinecke (jannik.meinecke@mercedes-benz.com) on behalf of MBition GmbH.
Provider Information
Licensed under BSD-2-Clause license