ringods

ringods

I would like to pass on incoming file upload as separate chunks down a GenStage, but I would like some expert advice/confirmation on my thinking. I also would like to know of anything Elixir might handle differently.

When reading the binary chunks from the Plug connection, I want to create a tuple per chunk. The binary chunk is one of the message tuple fields. When a message is sent from one process to another, the message is copied and then linked into the mailbox of the target process according this and this page.

The documentation on Erlang binaries mention that the real binary data is handled off-heap, with a ProcBin wrapper on-heap.

So, if I create a tuple message containing a binary, am I right that only the tuple with the ProcBin wrapper is copied into the target mailbox and the real binary data is not?

Showing Posts 1 to 5

NobbZ

NobbZ

Assume that everything is copied, unless you can guarantee that the receiver is on the same Node.

If they are on the same Node the binheap will be used for binaries larger than a threshold, but I’m not sure how large this threshold is.

ringods

ringods OP

@NobbZ I can guarantee that the receiver is on the same Node as I am the one starting the aformentioned GenStage when a new file upload is triggered on the Node.

If I look at the documentation (see link in initial post), I see a difference between Heap binaries and Refc binaries on a threshold of 64 bytes. Is that the threshold you are referring to?

rvirding

rvirding

Creator of Erlang

While that section is of course correct it does manage to hide some of the basics. So small binaries, less than 64 bytes, are stored on the process heap and are copied when sent in messages, while large binaries, greater than 64 bytes, are store off the process heaps in the refc memory and are not copied when sent in messages. This is completely transparent to the user. It also means that Erlang is usable for streaming large amounts of data and has been used for video streaming applications.

There are a few caveats though:

  • Seeing binaries in the refc memory can be referenced by many processes it can take a longer time for then to be garbage collected which can cause problems.
  • If you make a sub-binary, however small, of a large binary in refc memory then you will keep a reference to the large binary which means that it will not be collected. See binary:copy for a solution.

Everything is a trade-off. :wink:

I prefer to think of refc memory as the large binary space.

ringods

ringods OP

@rvirding is there any way I can get notified at runtime when refc binaries are copied? Log messages, profiler, … ?

michalmuskala

michalmuskala

Additionally, starting in OTP 20, “literals” are not copied. Literals are any constant compile-time values - lists, tuples, strings, maps, etc. All components of a tuple/list/map have to be literals as well, so [1, 2] is a literal, while [1, foo] is not.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews