Skip to content

Add example of execution limits using fuel consumption#2869

Merged
alexcrichton merged 6 commits into
bytecodealliance:mainfrom
ryanpbrewster:rpb/fuel-example
May 4, 2021
Merged

Add example of execution limits using fuel consumption#2869
alexcrichton merged 6 commits into
bytecodealliance:mainfrom
ryanpbrewster:rpb/fuel-example

Conversation

@ryanpbrewster
Copy link
Copy Markdown
Contributor

This is a quick example of using the "fuel consumption" logic introduced in #2611.

It computes larger and larger Fibonacci numbers (using the expensive recursive algorithm) until the computation requires more than 10k fuel.

Copy link
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks for this!

Comment thread examples/fuel.wat
@alexcrichton
Copy link
Copy Markdown
Member

Ah it looks like CI is failing when it's running the examples, as it expects that all examples pass successfully. Could the example be updated to not return a failure code? (e.g. catch the error)

Also I think our CI verifies that all examples are available in both C and Rust, so I think that at least a stub program will be needed for a C example?

@ryanpbrewster
Copy link
Copy Markdown
Contributor Author

ryanpbrewster commented May 3, 2021

Ah, that could be it. Thanks for the pointer, adding a C stub now.

EDIT: This may take a bit, figuring out how to build and run the C examples on a mac now.

@ryanpbrewster
Copy link
Copy Markdown
Contributor Author

ryanpbrewster commented May 3, 2021

Added a C example. I'm not particularly confident in the error handling and cleanup code there. I think I handle the error codes from wasm_store_add_fuel (I manually checked that if the config does not enable fuel consumption that those calls fail and exit).

I'm not sure about the semantics of the bool that wasm_store_fuel_consumed returns, so I just ignored it. Should I be asserting that it's true?

@alexcrichton
Copy link
Copy Markdown
Member

That all looks great to me, thanks!

@alexcrichton alexcrichton merged commit 2145855 into bytecodealliance:main May 4, 2021
@ryanpbrewster ryanpbrewster deleted the rpb/fuel-example branch May 4, 2021 16:14
mchesser pushed a commit to mchesser/wasmtime that referenced this pull request May 24, 2021
…nce#2869)

* Add example of execution limits using fuel consumption

* run rustfmt

* Use a more naive WAT implementation

* Catch error and return cleanly

* Add a C example to demonstrate fuel consumption

* Add error handling for add_fuel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants