Skip to content
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

feat: add option to return in order in client and streamer #5404

Merged
merged 10 commits into from Nov 18, 2022

Conversation

JoanFM
Copy link
Member

@JoanFM JoanFM commented Nov 17, 2022

Goals:
Try returning in the order of requests from Streamer

@github-actions github-actions bot added size/S area/core This issue/PR affects the core codebase labels Nov 17, 2022
@JoanFM JoanFM force-pushed the feat_return_order branch 3 times, most recently from 905fcee to fed6f31 Compare November 17, 2022 11:16
@codecov
Copy link

codecov bot commented Nov 17, 2022

Codecov Report

Merging #5404 (d9eb599) into master (38c86a1) will decrease coverage by 1.29%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #5404      +/-   ##
==========================================
- Coverage   86.99%   85.69%   -1.30%     
==========================================
  Files         101      101              
  Lines        6611     6607       -4     
==========================================
- Hits         5751     5662      -89     
- Misses        860      945      +85     
Flag Coverage Δ
jina 85.69% <100.00%> (-1.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
jina/clients/base/helper.py 83.06% <ø> (ø)
jina/clients/mixin.py 97.41% <ø> (ø)
jina/serve/runtimes/gateway/http/app.py 97.85% <ø> (-0.02%) ⬇️
jina/clients/base/grpc.py 90.66% <100.00%> (+0.52%) ⬆️
jina/clients/base/http.py 95.83% <100.00%> (ø)
jina/clients/base/websocket.py 90.19% <100.00%> (ø)
jina/serve/runtimes/gateway/grpc/gateway.py 97.26% <100.00%> (ø)
jina/serve/streamer.py 95.74% <100.00%> (-0.18%) ⬇️
jina/jaml/parsers/flow/v1.py 76.11% <0.00%> (-23.89%) ⬇️
jina/orchestrate/flow/base.py 84.12% <0.00%> (-6.65%) ⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
@JoanFM JoanFM linked an issue Nov 17, 2022 that may be closed by this pull request
@github-actions github-actions bot added area/testing This issue/PR affects testing component/type labels Nov 17, 2022
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
@JoanFM JoanFM marked this pull request as ready for review November 17, 2022 14:11
@github-actions github-actions bot added the area/docs This issue/PR affects the docs label Nov 17, 2022
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
@JoanFM JoanFM changed the title feat: add option to return in order in streamer feat: add option to return in order in client and streamer Nov 17, 2022
docs/fundamentals/client/client.md Outdated Show resolved Hide resolved
docs/fundamentals/client/client.md Outdated Show resolved Hide resolved
Co-authored-by: Alex Cureton-Griffiths <alexcg1@users.noreply.github.com>
@JoanFM JoanFM requested a review from alexcg1 November 17, 2022 16:40
alexcg1
alexcg1 previously approved these changes Nov 17, 2022
Copy link
Member

@alexcg1 alexcg1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

docs/fundamentals/client/client.md Outdated Show resolved Hide resolved
docs/fundamentals/client/client.md Outdated Show resolved Hide resolved
Comment on lines 246 to 247
responses_ids[response_request_id] = len(responses_list)
responses_list.append(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a need for responses_list here. I think we can directly put the response in the responses_ids map (actually let'ts map from ids to response objects and rename the variable)

Comment on lines 253 to 256
response_index = responses_ids[next_request_id]
del responses_ids[next_request_id]
request_ids.pop(0)
yield responses_list[response_index]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming we no more need responses_list, we can change the code like so:

Suggested change
response_index = responses_ids[next_request_id]
del responses_ids[next_request_id]
request_ids.pop(0)
yield responses_list[response_index]
request_ids.pop(0)
yield responses_ids.pop(next_request_id)

stop_yielding = False
while not stop_yielding and len(request_ids) > 0:
next_request_id = request_ids[0]
if next_request_id in responses_ids:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the next_request id is not received ? we don't yield anymore ?


@pytest.mark.parametrize('protocol', ['grpc'])
def test_return_order_in_client(protocol):
class ExecutorRandomSleepExecutor(Executor):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class ExecutorRandomSleepExecutor(Executor):
class RandomSleepExecutor(Executor):

rand_sleep = random.uniform(0.1, 1.3)
time.sleep(rand_sleep)

f = Flow(protocol=protocol).add(uses=ExecutorRandomSleepExecutor, replicas=2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f = Flow(protocol=protocol).add(uses=ExecutorRandomSleepExecutor, replicas=2)
f = Flow(protocol=protocol).add(uses=RandomSleepExecutor, replicas=2)

Comment on lines 21 to 39
def _create_topology_graph(
graph_description,
graph_conditions,
deployments_metadata,
deployments_no_reduce,
timeout_send,
retries,
):
# check if it should be in K8s, maybe ConnectionPoolFactory to be created
return TopologyGraph(
graph_representation=graph_description,
graph_conditions=graph_conditions,
deployments_metadata=deployments_metadata,
deployments_no_reduce=deployments_no_reduce,
timeout_send=timeout_send,
retries=retries,
)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of this, it seems like it is the same as just calling the constructor directly?

:yield: responses
"""
result_queue = asyncio.Queue()
request_ids = []
responses_list = []
responses_ids = {} # map from id to index in responses_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename to response_id_to_index or something like that

@@ -760,6 +760,34 @@ None

````

A Client connects to a Flow that processes Documents in an asynchronous and very distributed way. This means that the order of the Flow processing the requests may not be the same order as the Client sending the requests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to pass this parameter from a 3rd party client?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is gonna be ready in the streamer for the CustomGateway. We can add it later I would say

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly external clients do not have this streaming capability so easily implemented, so I think is not so so important

JoanFM and others added 2 commits November 18, 2022 10:28
Co-authored-by: AlaeddineAbdessalem <alaeddine-13@live.fr>
Copy link
Member

@alexcg1 alexcg1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@github-actions
Copy link

📝 Docs are deployed on https://feat_return_order--jina-docs.netlify.app 🎉

@JoanFM JoanFM merged commit d3feb66 into master Nov 18, 2022
@JoanFM JoanFM deleted the feat_return_order branch November 18, 2022 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core This issue/PR affects the core codebase area/docs This issue/PR affects the docs area/testing This issue/PR affects testing component/client size/M size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

What is the order of multi-replicas flow's result?
4 participants