nikiiv
Elixir memory model question
I am trying to get a list of gotchas for my prototype of an OMS for fun.
Given that Elixir (probably more of a BEAM question of course) is immutable, how does this exactly play within one process.
Lets say I have a struct for Customer and Product. Each one takes approx 10KB of memory
Then we have a struct for Order, that contains both keys for Customer and Product. Lets say with those two properties/fields set to nil an Order would occupy 1KB.
Say we have 1000 Customers and 10000 Products
If we combine each Customer and each Product into an Order, so 1_000_000 orders what is the expectation of the memory used within one process
1M by 21K each or 1M with 1K each plust two references to the 2x1000x10K (customers and products weight before combined into orders).
Given immutability I expect that Order would have reference and only if we mutate a field in the nested structure, we get a new memory allocation.
I expect atoms will be re-used, but lets for the sake of the question assume that no atoms are used in any of the 3 structs.
Technically an OMS (Order Management System) uses a lot of props that are static during the business day and data (say accounts) is changed after order execution which is a multi-step process, so it is important to know what to expect, when some of the props related to orders are re-used among multiple orders.
I can go ETS but… do I really have to?
Any good blog posts or reads on the topic?
Thanks in advance
Most Liked
LostKobrakai
How much of your data is binary data >64 bytes? Such binaries are put on a shared heap and reference counted instead of having multiple copies around.
For everything else Memory Usage — Erlang System Documentation v27.0 and :erts_debug.size are your friend.
benwilson512
Why guess when you can measure!
Check out :erts_debug.size to get the size (I think in words) of a given term.







