denoland / deno_core

The core engine at the heart of Deno
MIT License
295 stars 96 forks source link

Throttling of deno execution #629

Open deeprobin opened 8 months ago

deeprobin commented 8 months ago

Hey,

in my rust infra I currently schedule some Deno-"tasks". Is there a way to manually throttle the Deno execution without using OS APIs?

bartlomieju commented 8 months ago

Can you provide some more details into what kind of throttling are you looking for?

deeprobin commented 8 months ago

@bartlomieju

Can you provide some more details into what kind of throttling are you looking for?

Basically, the point is that I have an agent-like structure in certain use cases.

I then start a .js/.ts entrypoint using deno_core.

To better distribute the load or prioritise other tasks, I would like to manually throttle the execution of the JavaScript/TypeScript code and let the CPU focus more on something else.

In my opinion, it is easier to limit the memory usage. But CPU utilisation is the crux of the matter.

Do you have any ideas?

rracariu commented 8 months ago

This might be related to https://github.com/denoland/deno/issues/13654 TLDR: v8 does not offer an API for setting CPU quotas per isolate. You might need to rely on system specific APIs to do this.

bartlomieju commented 8 months ago

@deeprobin the solution for you is to use JsRuntime::poll_event_loop instead of JsRuntime::run_event_loop and schedule these polls when you have available CPU budget.