The worst thing I did in Rust was using unbounded asynchronous channels. It took days to figure out that my program had backpressure, and channels ate up all RAM.
So, since then, I have always used sync_channel or bounded channels from Crossbeam.
The worst thing I did in Rust was using unbounded asynchronous channels. It took days to figure out that my program had backpressure, and channels ate up all RAM.
So, since then, I have always used sync_channel or bounded channels from Crossbeam.
For further actions, you may consider blocking this person and/or reporting abuse
Joshua Nussbaum -
Hanzla Baig -
finger -
finger -
Top comments (3)
Your "post" fits in a Tweet: I don't think it's very useful as it is.
But it has a lot of potential. Writing a post explaining the problems and showing a solution with the relevant code could be much more useful to readers.
Could you please elaborate on unbounded asynchronous channels? They're not described in The Rust Programming Language, I could only find them mentioned in Rust by Example. And by "backpressure" you mean that the channels were steadily growing...? P.S.: I'm a Rust newbie.
You are right. I created a channel using the std::sync::mpsc::channel function. So the channel can grow until my computer is out of memory. I knew this before I wrote my code. However, after my program became more complex, there were many assumptions why the program took more than 32GB of memory after running for one week. It took me days to figure out that a producer among many of them sent much more data than a consumer can finish processing in time.
These days, I use a bounded channel from the Crossbeam library instead.
A bounded channel will block a producer if the channel reaches the limit, and it will unblock if the channel has some space. So the program won't use up the memory.