wasmer icon indicating copy to clipboard operation
wasmer copied to clipboard

Time and memory limits

Open jlkiri opened this issue 3 years ago • 1 comments

Summary

I am evaluating wasmer and it is very important for my project to set execution time and memory limits for an instance. I found out that limiting memory via Tunables is possible and I suppose exceeding that limit gives a MemoryError on function call invocations (correct me if I'm wrong). But is there a way to force shutdown from host when some deadline is hit?

Additional details

jlkiri avatar May 14 '22 04:05 jlkiri

Time deadlines aren't supported, but you can do a weighted instruction count and abort if that goes over some limit: https://github.com/wasmerio/wasmer/blob/master/examples/metering.rs#L51=

Since the count is only tracked/checked per basic block, this isn't too expensive, but it's also not free.

Time-wise, it's also not very precise. I've seen different compiled code use 3-8 gas per nanosecond and I suspect that wasm code designed to use as little gas as possible could go far lower (i.e. use more time with a fixed amount of gas). You might be able to do something like "give a too low amount of gas, check the time when the gas runs out, give more gas if there's still time", but that'll require changes to the metering middleware, which currently just triggers an unreachable when the gas runs out.

jcaesar avatar May 15 '22 23:05 jcaesar