denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.66k stars 5.25k forks source link

Deno RAM usage on Linux 5x higher than on Windows #25722

Open mariusheil opened 2 weeks ago

mariusheil commented 2 weeks ago

Hi, I am developing a deno application that maily uses npm:mqtt.js and a rather big generated openapi REST client to connect to a closed source webserver. Now, when I start my application on windows, it reports a ram usage of ~100Mb which is completely fine for me. However, when I start the same application on Linux (e.g. WSL2, CentOs or on a small ARM machine), the RAM usage is ~500Mb.

I could not find any information on the cause of this. Is this to be expected or can you provide me with some steps to analyze the issue? It is hard for me to share any code as I would need to completely strip the application.

Thank you, Marius

satyarohith commented 2 weeks ago

@mariusheil, are you seeing similar ram usage (~500mb) on different linux machines? I can understand it is hard for you to share code but we will not have anything actionable without reproducible code to investigate further and fix the issue. I highly appreciate if you share a short reproducible.

Is this to be expected or can you provide me with some steps to analyze the issue?

It is not expected/normal to have 5x increase in memory usage on different platforms for the same code. It's definitely a bug. I'm curious how are measuring the memory usage? Are you measuring the RSS of deno process or the JS heap as reported in --inspect?

mariusheil commented 2 weeks ago

Hello,

thanks for the quick answer. As to how I was measuring the memory, I looked in different places, which all differ slightly but show the same picture. E.g. right now, I started the exact same version of Deno (v1.46.3) with the same application once from my main machine running Windows and then with the same deno version inside WSL2 from the same directory. My application periodically logs out the result from Deno.memoryUsage().rss

I get a similar picture on multiple pure linux machines.

If you say that this is not expected, I'll try to remove modules from my application and see if I can isolate it to something.

Marius

mariusheil commented 2 weeks ago

Alright, I managed to get a reproducible example running. It all boils down to the typescript-fetch client that was generated using the official OpenApi generator (https://github.com/OpenAPITools/openapi-generator) version 7.2.0 in this case.

See the following example run for how the memory usage is different on Windows compared to Linux (in this example 3-4x):

PS C:\projects\bluerange-automate\client-typescript-deno> deno run MyTest.ts
Start
Memory 123.9296875 Mb
PS C:\projects\bluerange-automate\client-typescript-deno> bash
marius@marius-heil:/mnt/c/projects/bluerange-automate/client-typescript-deno$ deno run MyTest.ts
Start
Memory 446.2265625 Mb

Now, there are two lines in the Code which can be commented out. Commenting out the instantiation of an API call will reduce the RAM usage to around 90Mb both on Windows and on Linux. Commenting out the import statement as well will reduce the RAM usage to around 60Mb on both platforms.

The setIntervals do not perform as expected as there is some magic going on in the background which seems to allocate the memory at application start before the Api is instantiated.

I have attached a .zip file of the example application (Start with "deno run MyTest.ts"): client-typescript-deno.zip

The OpenApi client does not contain anything secret as it is only the public API of our Server.

Thanks, Marius