-
Notifications
You must be signed in to change notification settings - Fork 271
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
Support for context Cancelation and Timeout in func executions #1108
Conversation
cc @pims! |
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
f13ec45
to
485aa8d
Compare
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Gave this a try with the wasi-python example I had and it works well ⛽ ! |
@evacchi I think it would be great if you could review 👍 |
// Insert the exit code check on the loop header, which is the only necessary point in the function body | ||
// to prevent infinite loop. | ||
// | ||
// Note that this is a little aggressive: this checks the exit code regardless the loop header is actually | ||
// the loop. In other words, this checks even when no br/br_if/br_table instructions jumping to this loop | ||
// exist. However, in reality, that shouldn't be an issue since such "noop" loop header will highly likely be | ||
// optimized out by almost all guest language compilers which have the control flow optimization passes. | ||
if c.ensureTermination { | ||
c.emit(OperationBuiltinFunctionCheckExitCode{}) | ||
} |
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.
this is the key
Will do! |
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.
Excellent job! so many have asked about this, it is great to have a chance prior to 1.0!
Main thing I wonder is if this should be called RuntimeConfig.WithCloseOnContextCancel
because I believe at the end of the day, all these things end up as cancelation causes. In the very least it should be obvious by name that this is about context integration because the other ways (e.g. someone calling module.Close()` already exist w/o this feature.
happy for other ideas, too. Besides the name bike shedding I only had some questions about edge cases, specifically to know if someone wraps a context things will still work.
or |
@ncruces thoughts on this one? |
@daixiang0 @ItalyPaleAle @yaron2 so this means wasm middleware can stop based on incoming context. I'm not sure if it is routine to use context-cancelation in dapr, but we can integrate it once this feature is cut if so. |
I will go with |
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
@codefromthecrypt I made a quick pass over the code, but not enough to make detailed comments. From my experience, I'm unlikely to use it with SQLite (outside of tests?) because, although calling I'm likely to use it with |
Thank you folks, enjoy! 🍻 |
Thank YOU @mathetake 🙇🏻 |
We're building context cancellations for most components now so this would certainly become useful. |
Closes #509 and #422. The latter is slightly different, but I believe almost all use cases will be covered by this since
in any way exact CPU usage measurement is impossible. Timeout and Cancelation can effectively be used by
users to limit the execution times approximately. That is exactly the same as the concept of "fuel" where fuel is an abstractive thing and no one can interpret how 1 fuel corresponds to exactly how much CPU cycles are used across multiple platforms.
Notably, this adds
WithCloseOnContextDone
option for RuntimeConfig as below:With this, the following code works like a charm:
The only use case I think this cannot cover is that relative fuel consumption - users might want to compare how much Wasm instructions are used among different module function invocations. It can be used, for example, to bill Wasm function owners depending on the consumed fuel * pre determined price per fuel. In that case "exact" CPU cycles are not necessarily needed. This use case is out-of-scope until anyone asks since the implementation will be much more complex and different than this context integration. In any case, that can be implemented later.
Signed-off-by: Takeshi Yoneda takeshi@tetrate.io