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
Add Compile command. #248
Add Compile command. #248
Conversation
de0497d
to
eb73b2c
Compare
Thanks for the great PR! I think the ideal workflows should be the following:
Based on these assumptions, the Thoughts? |
@Hywan that means that you need the wasm file where you compile and where you execute the module, that's not always the same servers. |
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.
@calavera this seems like your use case:
- Compile wasm to cache file with Wasmer, cache is ouput somewhere accessible
- persist cache for later...do something else...kill some time...send it over the network etc.
- Load the cache back into Wasmer (maybe on a different machine) and run it
This seems like a valid use case. This is an ahead-of-time compilation workflow for hot runs. I think the addition of the Compile
subcommand and the --from-cache
option is fine. The confusing part about --from-cache
is that we require a wasm file for the Run
command. Ignoring the required option seems confusing. Maybe a dedicated subcommand for running from a cache?
I thought about that too, and it would make sense because this feature is dependent on the cache. Do you have any suggestions for the subcomand name @xmclark ? What about this?
|
My opinion is that we provide two cache subcommands:
and
|
I'm also realizing that this might need the wasm path, or at least a name for the module to be executed. I'm thinking about what's the best way to solve that. |
I like this suggestion |
76c27d3
to
42e3a68
Compare
@lachlansneff, @xmclark I've implemented those two subcommands, tell me if this makes sense:
I can write documentation for those subcommands if this is a good way to implement this. |
42e3a68
to
82b88bf
Compare
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.
Looks great!
src/bin/wasmer.rs
Outdated
.map_err(|e| format!("Can't execute module from cache: {:?}", e))?; | ||
|
||
let name = String::from(options.module_name.to_str().unwrap()); | ||
run_wasm_module(&module, name, &options.args) |
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.
A small nitpick: the module_name
is unecessary on the CLI. Can you pass the hash as a string to run_wasm_module
in place of the name? This will allow us to remove the module_name
field from CacheRun
too.
This way all we have to type is:
$ wasmer cache run VERY_LONG_HASH -- -c /opt/nginx/config
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.
I can do that, I was not sure if it'd be ok 👍
bors try |
I've removed that extra argument in the |
8b69eb2
to
b2c143a
Compare
@xmclark @lachlansneff it looks like Circle failed to download a dependency, and I cannot trigger a new job. |
@calavera Seems like a Cargo.lock issue? Try resetting it? |
This command allows people to compile a wasm module to machine code ahead of time. It dumps the data in the cache, so future runs can use it. Signed-off-by: David Calavera <david.calavera@gmail.com>
This is more flexible than using the WasmHash as the key. Signed-off-by: David Calavera <david.calavera@gmail.com>
After a module is compiled, it can be loaded from the cache without providing a wasm object. Signed-off-by: David Calavera <david.calavera@gmail.com>
Signed-off-by: David Calavera <david.calavera@gmail.com>
Signed-off-by: David Calavera <david.calavera@gmail.com>
- `wasmer cache generate` to generate a machine object. - `wasmer cache run` to run a cached object. The run command requires two arguments. The first one is the name of the program to run, to pass it as args[0] to the module, and the key for the object in the cache. It also allows to send extra arguments to pass them to the module. Example: ``` $ wasmer cache run nginx VERY_LONG_HASH -- -c /opt/nginx/config ``` Signed-off-by: David Calavera <david.calavera@gmail.com>
10134a9
to
545421c
Compare
it looks like rebasing master did the trick @lachlansneff 🎊 |
bors try |
tryBuild failed |
Use the module key in the cache as the name. Signed-off-by: David Calavera <david.calavera@gmail.com>
545421c
to
250fd92
Compare
bors try |
🔒 Permission denied Existing reviewers: click here to make calavera a reviewer |
bors try |
A small update on this PR: we are gathering more feedback (and learnings) about the compilation/caching runtime needs, to make sure we expose the right API for it. We will comment here as soon as we are 100% clear on it (hopefully soon!) |
We are on the final steps of rewriting Wasmer from scratch and this issue is now solved in the refactor (we have a |
Hi @calavera! We finally added support for precompiling wasm files to native object files (or JIT). Compile:
Run:
Note: if you use the native engine, the startup time to load them is just in the order of nanoseconds even for big wasm files. |
This command allows people to compile a wasm module to machine code ahead
of time. It dumps the data in the cache, so future runs can use it.
It also changes the Cache trait to use Strings as keys, so it's more flexible than using the WasmHash object directly.
I've added a --from-cache flag to the Run command to allow loading modules directly from the cache without having access to the wasm or wat files. I'm not super sold on this flag.
I'm super open to suggestions and other options.
Enjoy this doggo taking a bath: