Coder Social home page Coder Social logo

Comments (6)

justjake avatar justjake commented on June 9, 2024

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.

BartTactick avatar BartTactick commented on June 9, 2024

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.

justjake avatar justjake commented on June 9, 2024

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.

BartTactick avatar BartTactick commented on June 9, 2024

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."

https://stackoverflow.com/a/7335965

from quickjs-emscripten.

justjake avatar justjake commented on June 9, 2024

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.

BartTactick avatar BartTactick commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.