deno_core icon indicating copy to clipboard operation
deno_core copied to clipboard

Throttling of deno execution

Open deeprobin opened this issue 1 year ago • 4 comments

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?

deeprobin avatar Mar 02 '24 11:03 deeprobin

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

bartlomieju avatar Mar 02 '24 14:03 bartlomieju

@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?

deeprobin avatar Mar 02 '24 19:03 deeprobin

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.

rracariu avatar Mar 09 '24 18:03 rracariu

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

bartlomieju avatar Mar 10 '24 01:03 bartlomieju