-
Notifications
You must be signed in to change notification settings - Fork 39
remove some deepcopy to speed up workflow conductor #256
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 relate 8000 d emails.
Already on GitHub? Sign in to your account
Open
guzzijones
wants to merge
34
commits into
StackStorm:master
Choose a base branch
from
guzzijones:nocopy
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
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
6a6f0b8
remove some deepcopy to speed up workflow conductor
guzzijones 0f5d374
Update tox.yml
guzzijones 73522e4
Update tox.yml
guzzijones 46c7546
Update tox.yml
guzzijones 3bff3e0
black formatting
guzzijones 3805276
add back python 3.8
guzzijones 8ce4a42
try 18.04
guzzijones 61bf846
switch back to 20.04
guzzijones bbd2ea4
remove unittest2
guzzijones cb52348
install setup.py to load entrypoints
guzzijones 7bdb543
set language
guzzijones 8fd8bb1
remove another deepcopy
guzzijones aac13bf
remove staged copy
guzzijones 4712345
remove reruns deepcopy
guzzijones f5caf3a
remove serialize parent_ctx copy
guzzijones 6478f9b
deepcopy machine.py, deepcopy graphing.py, conducting.py
guzzijones 0f58986
remove json_util
guzzijones d3541fb
need to copy staged so it isn't mutated for with items
guzzijones 6e3866a
ensure staged is deep copied
guzzijones 62a23a5
flake8 lint fix
guzzijones 1364dca
add back deepcopy for errors as they are also mutated in st2
guzzijones d9816fa
do not copy with items context; added benchmarks
guzzijones 016f825
remove comment about task render
guzzijones 8cf2ff8
add test requirements
guzzijones 3e7cfb4
fix conflicts
guzzijones eb09856
typo in benchmark vs benchmarks
guzzijones c5dbc16
add __init__.py so imports work
guzzijones 84a6aa2
remove unused import ctx_util
guzzijones a1f4685
flake8 fixes
guzzijones 3c2db2c
add license file
guzzijones 429f0e0
remove extras require
guzzijones 25cf175
more deep copy removed
guzzijones d4c848b
flake fix
guzzijones ce8fcdf
Merge branch 'master' into nocopy
guzzijones File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Copyright 2021 The StackStorm Authors. | ||
# Copyright 2019 Extreme Networks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
|
||
import orquesta.specs.native.v1.models as models | ||
|
||
from orquesta.expressions import base as expr_base | ||
from orquesta.utils import context as ctx_util | ||
|
||
|
||
WITH_ITEMS = [ | ||
[{"test": "s"}, {"test1": "s"}, {"test2": "s"}], | ||
[{"test": "s" * 10000}, {"test1": "s" * 10000}, {"test2": "s" * 10000}], | ||
[{"test": "s" * 1000000}, {"test1": "s" * 1000000}, {"test2": "s" * 1000000}], | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("fixture", WITH_ITEMS, ids=["small", "medium", "large"]) | ||
@pytest.mark.benchmark(group="no deepcopy") | ||
def test_task_spec_render(benchmark, fixture): | ||
def run_benchmark(): | ||
# Instantiate workflow spec. | ||
task_spec = models.TaskSpec( | ||
{ | ||
"action": "core.echo message=<% item() %>", | ||
"next": [{"publish": [{"items": "<% result() %>"}]}], | ||
"with": {"items": "<% ctx(xs) %>"}, | ||
} | ||
) | ||
in_ctx = { | ||
"xs": fixture, | ||
"__current_task": {"id": "task1", "route": 0}, | ||
"__state": { | ||
"contexts": [{"xs": fixture}], | ||
"routes": [[]], | ||
"sequence": [], | ||
"staged": [ | ||
{"id": "task1", "ctxs": {"in": [0]}, "route": 0, "prev": {}, "ready": True} | ||
], | ||
"status": "running", | ||
"tasks": {}, | ||
}, | ||
} | ||
# Instantiate conductor | ||
task_spec.render(in_ctx) | ||
|
||
benchmark(run_benchmark) | ||
|
||
|
||
class OldTaskSpec(models.TaskSpec): | ||
def render(self, in_ctx): | ||
action_specs = [] | ||
|
||
if not self.has_items(): | ||
action_spec = { | ||
"action": expr_base.evaluate(self.action, in_ctx), | ||
"input": expr_base.evaluate(getattr(self, "input", {}), in_ctx), | ||
} | ||
|
||
action_specs.append(action_spec) | ||
else: | ||
items_spec = self.get_items_spec() | ||
|
||
if " in " not in items_spec.items: | ||
items_expr = items_spec.items.strip() | ||
else: | ||
start_idx = items_spec.items.index(" in ") + 4 | ||
items_expr = items_spec.items[start_idx:].strip() | ||
|
||
items = expr_base.evaluate(items_expr, in_ctx) | ||
|
||
if not isinstance(items, list): | ||
raise TypeError('The value of "%s" is not type of list.' % items_expr) | ||
|
||
item_keys = ( | ||
None | ||
if " in " not in items_spec.items | ||
else items_spec.items[: items_spec.items.index(" in ")].replace(" ", "").split(",") | ||
) | ||
|
||
for idx, item in enumerate(items): | ||
if item_keys and (isinstance(item, tuple) or isinstance(item, list)): | ||
item = dict(zip(item_keys, list(item))) | ||
elif item_keys and len(item_keys) == 1: | ||
item = {item_keys[0]: item} | ||
|
||
item_ctx_value = ctx_util.set_current_item(in_ctx, item) | ||
|
||
action_spec = { | ||
"action": expr_base.evaluate(self.action, item_ctx_value), | ||
"input": expr_base.evaluate(getattr(self, "input", {}), item_ctx_value), | ||
"item_id": idx, | ||
} | ||
|
||
action_specs.append(action_spec) | ||
|
||
return self, action_specs | ||
|
||
|
||
@pytest.mark.parametrize("fixture", WITH_ITEMS, ids=["small", "medium", "large"]) | ||
@pytest.mark.benchmark(group="deepcopy") | ||
def test_task_spec_render_old(benchmark, fixture): | ||
def run_benchmark(): | ||
# Instantiate workflow spec. | ||
task_spec = OldTaskSpec( | ||
{ | ||
"action": "core.echo message=<% item() %>", | ||
"next": [{"publish": [{"items": "<% result() %>"}]}], | ||
"with": {"items": "<% ctx(xs) %>"}, | ||
} | ||
) | ||
in_ctx = { | ||
"xs": fixture, | ||
"__current_task": {"id": "task1", "route": 0}, | ||
"__state": { | ||
"contexts": [{"xs": fixture}], | ||
"routes": [[]], | ||
"sequence": [], | ||
"staged": [ | ||
{"id": "task1", "ctxs": {"in": [0]}, "route": 0, "prev": {}, "ready": True} | ||
], | ||
"status": "running", | ||
"tasks": {}, | ||
}, | ||
} | ||
# Instantiate conductor | ||
task_spec.render(in_ctx) | ||
|
||
benchmark(run_benchmark) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.