6 ms·
Not OP, but I'm confused how this would be helpful. You're saying for example, he can use this function to create a coroutine out of a function, begin it, and i
by 9d 1y ago
Not OP, but I'm confused how this would be helpful. You're saying for example, he can use this function to create a coroutine out of a function, begin it, and if the function fails by e.g. running out of memory, you can give the module more memory and then resume the coroutine? If so, how is that different than what naturally happens? Does wasm not have try/catch? Also, wouldn't the module then need to back up manually and retry the malloc after it failed? I'm so lost.
- huem0n 1y ago> Does wasm not have try/catch Not currently. There's an accepted proposal, but its in progress.
- herobird 1y agoGreat question! Wasmi's fuel metering can be thought of as is there was an adjustable counter and for each instruction that Wasmi executes this counter is decreased by some amount. If it reached 0 the resumable call will yield back to the host (in this case the OS) where it can be decided how to, or if, the call shall be resumed. For efficiency reasons fuel metering in Wasmi is not implemented as described above but I wanted to provide a simple description. With this, one is no longer reliant on clocks or on other measures to provide each call its own time frame by providing an amount of fuel for each Wasm app that can be renewed (or not) when it runs out of fuel. So this is useful for building a Wasm scheduler.
- 112233 1y agoIs it deterministic? I.e. would running the same function "time out" at the exactly same state, if run in different environments?
- jazzyjackson 1y agoPossibly answered one sibling next to you, https://news.ycombinator.com/item?id=44230721 https://news.ycombinator.com/item?id=44230721
- herobird 1y agoYes, Wasmi's fuel metering is deterministic.
- 9d 1y ago> Great question! Thanks! I have lots more too. Are there directions in space? What kind of matter is fire made of? If you shine a laser into a box with one-way mirrors on the inside, will it reflect forever? Do ants feel like they're going in regular motion and we're just going in slow motion? Why do people mainly marry and make friends with people who look extraordinarily similar to themselves? How do futures work in Rust? Why is the C standard still behind a paywall? Let me know if you need any more great questions.
- lukan 1y ago"If you shine a laser into a box with one-way mirrors on the inside, will it reflect forever?" No, because each reflection comes at a cost (some light transformed to heat) "Why do people mainly marry and make friends with people who look extraordinarily similar to themselves?" To not get so much surprises and have a more stable life. (I didn't choose that path.) (But I feel it would be too much OT answering the other questions and don't want to distract from this great submission or the interesting Wasmi concept)
- 9d 1y agoNo, I do not accept this. There must be a way. What if the mirror box has a high enough heat? Would it work then? The box could be made of a heat resistant material, like fiberglass.
- Bjartr 1y agoIt's not that the mirror or box is damaged by heat, it's that each bit of heat energy comes from a bit of light energy. Eventually the light bounces enough times that there's no energy left in it.
- 9d 1y agoI understand, but what I mean is, what if there is no more opportunity for the light to emit heat, because the surrounding environment is already saturated with so much heat that it can't accept more? Is this a possible way to prevent the light from emitting heat and therefore prevent the light from decreasing its luminousness? There must be a way!
- pimeys 1y agoWe used fuel metering with wasmtime, but that made everything quite slow, certain things veeery slow. How is the performance when using fuel with wasmi? We are considering to use epoch counter, but for now we just turned fuel off.
- 9d 1y agoI had no idea what fuel is until this discussion. What's the rationale? Just preventing infinite loops from hanging the host? If the inefficiency is the counter, what if you just calculated an instruction offset - start < threshold every once in a while? This probably makes no sense, ignore it, I'm way in over my head. [1] https://github.com/bytecodealliance/wasmtime/issues/4109 https://github.com/bytecodealliance/wasmtime/issues/4109 [2] https://github.com/bytecodealliance/wasmtime/blob/main/examples/fuel.rs https://github.com/bytecodealliance/wasmtime/blob/main/examp...
- herobird 1y agoYes, rational is to provide a pragmatic and efficient solution to infinite loops. There is a variety of ways to implement fuel metering with varying trade-offs, e.g. performance, determinism and precision. In this comment I roughly described how Wasmi implements its fuel metering: https://news.ycombinator.com/item?id=44229953 https://news.ycombinator.com/item?id=44229953 Wasmi's design focuses on performance and determinism but isn't as precise since instructions are always considered as group.
- conradev 1y agoI first encountered this with gas in the Ethereum VM. For Ethereum, they price different operations to reflect their real world cost: storing something forever on the blockchain is expensive whereas multiplying numbers is cheap I’m not sure what it’s used for in this context or how instructions are weighted
- pimeys 1y agoLet's consider that you create a serverless platform which runs wasm/wasi code. The code can do an infinite loop and suck resources while blocking the thread that runs the code in the host. Now, with a fuel mechanism the code yields after a certain amount of instructions, giving the control back to the host. The host can then do things such as stop the guest from running, or store the amount of fuel to some database, bill the user and continue execution.