8000 [Async] Implement asynchronous event processing in python runtime by rokatyy · Pull Request #3461 · nuclio/nuclio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Async] Implement asynchronous event processing in python runtime #3461

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

Merged
merged 40 commits into from
Feb 11, 2025

Conversation

rokatyy
Copy link
Contributor
@rokatyy rokatyy commented Jan 20, 2025

Within this PR:

  • Implemented separation between old and new python wrappers (and new wrapper itself implemented)
  • Added new trigger configuration trigger.mode which could be either sync(default) or async
  • Implemented ConnectionAllocator (now allocates only 1 connection, multiple connection support to be added in following pr)

Jira:

@rokatyy rokatyy requested a review from TomerShor January 26, 2025 13:09
Comment on lines 155 to 156
# logger isn't available yet
print('Failed to connect to ' + socket_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

(I know it's unrelated to your changes) I think that the logger is available, according to https://github.com/nuclio/nuclio/pull/3461/files#diff-725534bace834296150d3e0c0525fd5ef3ec7b57ddaa193e5cc98ed5d062e2eaR180-R182

Comment on lines 87 to 88
# make a writeable file from processor
self._control_sock_wfile = self._control_sock.makefile('w')
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this is not really needed (never was)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TomerShor actually, i'm not sure here. Why do you think it's not needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not used anywhere.
Unlike the event socket wfile, which is used here for logging.

@@ -56,6 +57,7 @@ type Configuration struct {
TriggerKind string
WorkerTerminationTimeout time.Duration
ControlMessageBroker *controlcommunication.AbstractControlMessageBroker
Mode functionconfig.TriggerWorkMode
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed both here and in the trigger configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TomerShor user configures on trigger level and then we just propagate it to all workers of given trigger

@rokatyy rokatyy requested a review from TomerShor February 3, 2025 13:13
Copy link
Contributor
@liranbg liranbg left a comment

Choose a reason for hiding this comment

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

Very well, Id add more doc comments to critical path to explain the story. mainly on _nuclio*_wrapper.py

🚀


// Use retryable dial for the first connection
if i == 0 {
conn, err = retryableDial(ca.serverAddress, 30, 1*time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

when does it try to start? after the runtime is started? in parallel? perhaps it might take some time to the runtime to start (e.g loading large model)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liranbg that's a good point. We indeed want to be able to wait much more. What I'm thinking about is that we can avoid having a timeout. Instead, we can use wrapperInitialized message from control message socket. Not for this PR as there are too many changes already. What do you think about this idea @TomerShor?

Comment on lines +115 to +116
except KeyboardInterrupt:
self._logger.info("Shutting down server")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just for tests right?
Termination signal will not actually break the while loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rokatyy rokatyy requested review from liranbg and TomerShor February 4, 2025 17:24
Copy link
Contributor
@TomerShor TomerShor left a comment

Choose a reason for hiding this comment

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

Great job 👏

@rokatyy rokatyy marked this pull request as ready for review February 11, 2025 15:52
@TomerShor TomerShor merged commit 7c8736d into nuclio:development Feb 11, 2025
14 checks passed
@dberardo-com
Copy link

Quick question here what is a potential use case for an async handler? Why would one want to add one?

@rokatyy
Copy link
Contributor Author
rokatyy commented Apr 7, 2025

@dberardo-com async handlers are very useful if you have something to await and it takes quite a time. For instance, your handler request external api.

@TomerShor
Copy link
Contributor

@dberardo-com this essentially enables your function to process multiple events asynchronously, instead of processing them one after the other.

@dberardo-com
Copy link

Alright, is this valid also within mqtt triggered functions? Can they be processed in parallel?

@rokatyy
Copy link
Contributor Author
rokatyy commented Apr 11, 2025

@dberardo-com currently async mode is only available for http trigger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0