Comments (6)
Hey @BartTactick,
how do you expect this to work? There’s an option to run a function periodically that can interrupt execution. You can probably use that to implement the time-based semantics you need. There’s an example of a deadline based interrupt in the README, see shouldInterrupt: …
here: https://github.com/justjake/quickjs-emscripten#safely-evaluate-javascript-code
You can add this to a Runtime using setInterruptHandler
: https://github.com/justjake/quickjs-emscripten/blob/main/doc/classes/QuickJSRuntime.md#setinterrupthandler
from quickjs-emscripten.
Hey @justjake ,
Basicly the way Cloudflare workers work: https://developers.cloudflare.com/workers/platform/pricing/
So lets say your doing a heavy loop it will count how long you have used the CPU.
But when the CPU is idle (for example waiting for a network response or something) it wont count anything.
In the end you would have a the MS that the script has ran.
And based on that you could dispose the execution/script.
from quickjs-emscripten.
To clarify, you want to count the wall-clock time taken by every call to a VM function that executes code in the VM, and possibly interrupt execution once a certain limit is reached, but when the VM exits because it’s awaiting a host Promise (ie, IO inside an async loop running in the VM) you don’t want to count that time?
I think this is very doable without changes to the library today. The VM does not block the host thread while it is awaiting. And, you always control when the VM resumes execution after a host promise resolves a VM promise. So you can save a time stamp before every call into the VM and after every call into the VM exits, and use those to account for the CPU time spent. Additionally, you could use the interrupt handler to interrupt if (timeSoFar + (Date.now() - startTimeOfThisCall) > MAX_TIME)
.
from quickjs-emscripten.
Im pointing towards CPU time or user-cpu time if your looking at this stackoverflow post:
"The user-cpu time and system-cpu time are pretty much as you said - the amount of time spent in user code and the amount of time spent in kernel code."
from quickjs-emscripten.
I think my previous post describes a way to capture user-cpu time if you define user-cpu time as “evaluating code in the vm”, which I think seems reasonable.
from quickjs-emscripten.
I think my previous post describes a way to capture user-cpu time if you define user-cpu time as “evaluating code in the vm”, which I think seems reasonable.
I will look into it. Thank you so far!
from quickjs-emscripten.
Related Issues (20)
- Tests fail on s390x machines HOT 5
- Proxy log receiver blocking error HOT 1
- Async Regression "TypeError: Object not disposable" in v0.26.0 HOT 4
- wish to add a new api (QuickJSHandle.keepAlive) HOT 2
- `getQuickJS()` callback never resolves? HOT 3
- [vite - MIME type Error]It's cannot work in vite HOT 2
- How to access wasm module's Memory? HOT 3
- Feature request: Expose GetModuleExport APIs HOT 4
- Timeout not working HOT 6
- [feature request] Upgrade to v2024-01-13 HOT 3
- TypeError: Failed to construct 'URL': Invalid URL HOT 7
- Loading WasmMemory into module HOT 11
- Determinism of the library HOT 2
- Distributed packages have no license HOT 2
- `evalCode` won't return error in ES module mode HOT 3
- Can't run cloudflare example HOT 1
- `Out of bounds memory access` Error only on ARM Safari HOT 10
- Having troubles with ArrayBuffer HOT 1
- Inconsistent behavior when running in browser (and web worker) HOT 3
- In context of `QuickJSAsyncRuntime` and `QuickJSAsyncContext`, the `callFunction()` not working as expected HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quickjs-emscripten.