10

How can I limit Deno RAM and CPU usage when running js/ts scripts?

deno run https://deno.land/[email protected]/examples/welcome.ts 
2
  • 2
    Is running it in a docker container an alternative you could consider? Since limiting memory and cpu usage is one of the benefits with containers. Commented Feb 18, 2021 at 16:28
  • 5
    @Jonas Yes, this is an alternative. Yesterday I found that you can limit memory usage by using v8 flags, for example: deno run --v8-flags=--max-old-space-size=4 --allow-read fill-mem.js Commented Feb 19, 2021 at 9:56

1 Answer 1

9

Besides using the container as sugessted in comments:

 --max-old-space-size (max size of the old space (in Mbytes)) type: size_t default: --max-old-space-size=0 --max-heap-size (max size of the heap (in Mbytes) both max_semi_space_size and max_old_space_size take precedence. All three flags cannot be specified at the same time.) type: size_t default: --max-heap-size=0 

As suggested by Luke Davis in comments:

deno run --v8-flags='--max-heap-size=50,--max-old-space-size=50' \ https://deno.land/[email protected]/examples/welcome.ts // OR export V8_FLAGS="--max-heap-size=50,--max-old-space-size=50"; deno run --v8-flags="${V8_FLAGS}" ./deno_example.ts 
Sign up to request clarification or add additional context in comments.

2 Comments

I get Found argument '--max-heap-size' which wasn't expected, or isn't valid in this context in deno 1.17.0. Seems these config options are no longer available?
Seems the following syntax is required for newer deno versions: deno run --v8-flags=--max-heap-size=50,--max-old-space-size=50'.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.