tj0

tj0

I have been running 1.15 locally for a while and 1.14 in production. I just upgraded production to 1.15.7 and noticed that the “code” size is different between dev/prod. I’m not sure what the expected behaviour is nor do I know what “code” memory means. I’m naively assuming it’s the size of the beam file AST in memory? Is this supposed to be static based on the deploy size or something else entirely? Erlang manual says:

The total amount of memory currently allocated for Erlang code. This memory is part of the memory presented as system memory.

So I would have assumed prod < dev actually. Anyone have any idea why this is different between dev / prod? Screenshots below.

Locally, 1.15.7 and OTP 26 gives 30MB of code size.

But on production, we have 48MB of code in memory.

Edit:
Also, a sidenote, trying to search for what memory code netted me this awesome post by @hauleth :rofl:

Also, an interesting note about binary memory:

Showing Posts 1 to 7

LostKobrakai

LostKobrakai

Releases default to preloading all modules, mix defaults to loading modules on demand to increase startup performance in favor of slightly slower first time response when a new module is used. That‘s likely the difference you see between prod and dev.

tj0

tj0 OP

Thanks, I did not realize that.

says code preloading is enabled by default, but there doesn’t seem to be a way to disable it?

I’m trying to tune the base memory configuration to be as low as possible, “code” should probably be 30MB even after loading everything, not 50MB.

LostKobrakai

LostKobrakai

If you want to lower memory footprint you likely want to cut out what you don’t need – not disable preloading. What you actually need will eventually be loaded, so your footprint wouldn’t actually get smaller.

tj0

tj0 OP

True. Perhaps my assumptions are wrong again.

I am assuming that it loads only the required functions dynamically. The example given to show why to preload was for Enum.map.

1.15 enabled code pruning, so I also assume that is the function, not module level?

Then on disk the beam files only take 30MB, but code. taking 50MB. :thinking:

Suffice to say, I don’t understand the internals. :sweat_smile:

josevalim

josevalim

Creator of Elixir

Search for RELEASE_MODE in the docs. :slight_smile: interactive mode was slower to boot but that’s not necessarily the case from Erlang/OTP 26.

LostKobrakai

LostKobrakai

There is no automatic prunning of modules or functions. The feature added in 1.15 is around code paths, which brings mix projects closer to how releases are built by excluding everything but explicit dependencies mostly to otp applications. Previously all of OTP would be available for loading on demand.

To get a smaller codebase you’d need to lessen the (number of) applications you depend on, as there’s also nothing manual for pruning code at the module or function level.

tj0

tj0 OP

Thank you @LostKobrakai @josevalim .

Code path pruning
I had skipped a rather important word when reading about code path pruning.

Code memory usage
Turns out running mix release.init creates rel/env.sh.eex which has the RELEASE_MODE option right at the top . I migrated from distillery, so it wasn’t obvious what I was looking for. Anyone starting off with a fresh project would easily find this option.

rel/env.sh.eex

# # Set the release to load code on demand (interactive) instead of preloading (embedded).
# export RELEASE_MODE=interactive

Also, this may not affect startup time in OTP 26.

Final results
Using interactive mode after going thru all the routes has reduced the memory:

Production is running at 23MB right now, but I expect it will grow to at least 30MB. Embedded mode which preloads everything had code memory usage at 48MB. Super-helpful when running on lower memory nodes. A MB saved is a MB earned. :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
subsaharancoder
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews