<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="111702" data-post-id="111702">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="blatyo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/blatyo/120/4554_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  blatyo
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Conduit Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’ll say my impression from what I’ve seen is that there is excessive use of GenServer and it appears to be using those GenServers almost like objects. There is <a href="https://www.theerlangelist.com/article/spawn_or_not" rel="noopener nofollow ugc">this post by Saša Jurić</a> that explains why that approach isn’t so good. In addition to the excessive use of GenServer, I’d say that a project per GenServer seems excessive as well.</p>
<p>I don’t think everything in the video is horribly wrong though. The things that stand out to me as odd are the <a href="https://github.com/pragdave/dir_walker/blob/master/lib/dir_walker.ex" rel="noopener nofollow ugc">DirWalker</a> which is implemented as a GenServer that produces a stream and the HashStore as it’s own GenServer. It’s odd to me that the DirWalker is implemented as a GenServer, when it could just as likely be implemented with <code>Stream.resource/3</code> in a module with just functions. The problem being solved in the video is effectively a map &gt; reduce &gt; filter problem. So, I can imagine it being very reasonable to have multiple mappers, though it could very well be slower in this case. My implementation to this problem would likely have been:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def find_duplicate_in(tree) do
  DirWalker.stream() # this wouldn't use a GenServer, why send a blocking request to another process?
  |&gt; Task.async_stream(&amp;HashGenerator.process/1) # Why reinvent tasks?
  #or |&gt; Stream.map(&amp;HashGenerator.process/1) # Concurrency could perform worse
  |&gt; Enum.group_by(&amp;(&amp;1.hash), &amp;(&amp;1.filename))
  |&gt; Enum.filter(fn 
    {_hash, files} when length(files) &gt; 1 -&gt; true
    _ -&gt; false
  end)
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111702" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-111702" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111702"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="111845" data-post-id="111845">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pragdave" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pragdave/120/1042_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pragdave
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Programming Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If DirWalker had no process where would it keep its state: it creates the path list lazily: important on file systems with millions of files.</p>
<p>Internally the Hungry strategy uses async_stream, but it adds some stuff to it. First, it can be used in GenServers without messing up the message mailbox. It also adds convenient callbacks.</p>
<p>Finally, the overall approach above is synchronous. In want my component stuff to default to asynchronous for most uses, because that’s today’s world: event streams and reduces.</p>
<p>But, having said all this, I don’t think you’re wrong. I’m, exploring, just as everyone else is. I’m driven by this idea that things should be easier than we make them. The component abstraction is just the starting point for that exploration.</p>
<p>Cheers</p>
<p>Dave</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111845" data-batch-url="/posts/batch_likers">
                        14
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-111845" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111845"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="111864" data-post-id="111864">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="blatyo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/blatyo/120/4554_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  blatyo
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Conduit Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="pragdave" data-post="13" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pragdave/48/1042_2.png" class="avatar"> pragdave:</div>
<blockquote>
<p>If DirWalker had no process where would it keep its state: it creates the path list lazily: important on file systems with millions of files.</p>
</blockquote>
</aside>
<p>With <code>Stream.resource/3</code> you can return the list of the next items and an accumulator, which is where I would keep track of state. I agree about being lazy.</p>
<aside class="quote no-group" data-username="pragdave" data-post="13" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pragdave/48/1042_2.png" class="avatar"> pragdave:</div>
<blockquote>
<p>First, it can be used in GenServers without messing up the message mailbox.</p>
</blockquote>
</aside>
<p>I don’t think I understand what that means. Could you elaborate?</p>
<aside class="quote no-group" data-username="pragdave" data-post="13" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pragdave/48/1042_2.png" class="avatar"> pragdave:</div>
<blockquote>
<p>It also adds convenient callbacks.</p>
</blockquote>
</aside>
<p>I agree they’d be convenient in the model of components vs building your own <code>GenServer</code>. But I think, contrasting against passing just a function, I’d personally pick that.</p>
<aside class="quote no-group" data-username="pragdave" data-post="13" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pragdave/48/1042_2.png" class="avatar"> pragdave:</div>
<blockquote>
<p>Finally, the overall approach above is synchronous. In want my component stuff to default to asynchronous for most uses, because that’s today’s world: event streams and reduces.</p>
</blockquote>
</aside>
<p>I guess I would argue that the code I wrote is as asynchronous as your code is, even though you have more processes. Aside from the mapping stage, which we could easily achieve the same level of concurrency for, the places where you’re using processes, you’re effectively blocking one process to wait on another process that is synchronously doing some work. In my code, I’d argue I just removed the message pass by having it synchronously do that work. Maybe you just mean you’ve broken your code up into more concurrent primitives, but I’d argue that isn’t so important to do on the BEAM, where it has a preemption scheduler.</p>
<p>The solution I proposed does make the assumption that there aren’t going to be too many files. Were I to find it to be substantially more, I’d probably use Flow, which wouldn’t require much reworking of the initial solution.</p>
<p>I usually avoid creating bespoke GenServer’s when I can. I prefer using the functional aspect of Elixir over the actor parts. The things I think about that cause me to create processes are:</p>
<ul>
<li>Does this data have a lifecycle longer than the operation I’m performing?</li>
<li>Do I want to treat the failure of this differently?</li>
<li>Am I performing stuff sequentially that has no dependence between each other?</li>
</ul>
<aside class="quote no-group" data-username="pragdave" data-post="13" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pragdave/48/1042_2.png" class="avatar"> pragdave:</div>
<blockquote>
<p>But, having said all this, I don’t think you’re wrong. I’m, exploring, just as everyone else is. I’m driven by this idea that things should be easier than we make them. The component abstraction is just the starting point for that exploration.</p>
</blockquote>
</aside>
<p>I think the only places we disagree are where process boundaries should be and when to split code up. Most of the code you wrote, I’d probably copy verbatim if I was doing something similar. It’s also possible I’d be convinced components were a better fit solving a different problem.</p>
<p>Thanks</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111864" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-111864" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111864"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="111865" data-post-id="111865">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pragdave" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/pragdave/120/1042_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pragdave
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Programming Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="blatyo" data-post="14" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/blatyo/48/4554_2.png" class="avatar"> blatyo:</div>
<blockquote>
<blockquote>
<p>If DirWalker had no process where would it keep its state: it creates the path list lazily: important on file systems with millions of files.</p>
</blockquote>
<p>With <code>Stream.resource/3</code> you can return the list of the next items and an accumulator, which is where I would keep track of state. I agree about being lazy.</p>
</blockquote>
</aside>
<p>Sure: DirWalker uses Stream.resource internally. But it has a broader API than just streams, and so it uses a GenServer to provide that.</p>
<aside class="quote no-group quote-modified" data-username="blatyo" data-post="14" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/blatyo/48/4554_2.png" class="avatar"> blatyo:</div>
<blockquote>
<blockquote>
<p>First, it can be used in GenServers without messing up the message mailbox.</p>
</blockquote>
<p>I don’t think I understand what that means. Could you elaborate?</p>
</blockquote>
</aside>
<p>Task.async_stream sends messages to the pid that invokes it to synchronize the worker tasks. The fact that both it and gen_server receive messages on that same mailbox gets things al messed up. If you have a look at the component code, I check to see if async_stgream is being used synchronously or asynchronously. In the latter case I spawn a helper process in which the stream runs.</p>
<aside class="quote no-group" data-username="blatyo" data-post="14" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/blatyo/48/4554_2.png" class="avatar"> blatyo:</div>
<blockquote>
<p>Aside from the mapping stage, which we could easily achieve the same level of concurrency for, the places where you’re using processes, you’re effectively blocking one process to wait on another process that is synchronously doing some work.</p>
</blockquote>
</aside>
<p>Actually, I don’t think I am blocking anywhere (apart from the call into the HashStore art the end). Everything else is event driven  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111865" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-111865" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111865"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="111876" data-post-id="111876">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gregvaughn" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gregvaughn/120/954_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gregvaughn
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/pragdave" rel="nofollow">@pragdave</a> I really like this 'hungry" component abstraction and definitely plan to dig deeper.</p>
<p>But my initial question is about the <code>one_way</code> macro. I assume that maps to a <code>GenServer.cast</code>? I’ve read and watched plenty about backpressure though I don’t have much practical experience with it. One of the rules of thumb I took from that is to prefer <code>call</code> over <code>cast</code> but I heard you advocating for <code>cast</code> purely on whether the caller needed a response. Have you considered backpressure and if so, how do you approach it?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111876" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-111876" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111876"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="111880" data-post-id="111880">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="gregvaughn" data-post="16" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gregvaughn/48/954_2.png" class="avatar"> gregvaughn:</div>
<blockquote>
<p>But my initial question is about the <code>one_way</code> macro. I assume that maps to a <code>GenServer.cast</code> ? I’ve read and watched plenty about backpressure though I don’t have much practical experience with it. One of the rules of thumb I took from that is to prefer <code>call</code> over <code>cast</code> but I heard you advocating for <code>cast</code> purely on whether the caller needed a response. Have you considered backpressure and if so, how do you approach it?</p>
</blockquote>
</aside>
<p>Backpressure is handled based on message sending, so if the gen_server gets lots and lots of message then processes that send it a message get ‘slowed’ down (higher reductions used) to throttle them enough so the system doesn’t get overwhelmed.  It doesn’t matter whether call or cast is used for that.  Generally you want <code>call</code> when you want to serialize the call or <code>cast</code> to async the call.</p>
<p>Do note, I think something about the backpressure mechanism changed or is going to change in OTP recently, so this may not be accurate as of the latest version…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111880" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-111880" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111880"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="111881" data-post-id="111881">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gregvaughn" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gregvaughn/120/954_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gregvaughn
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="OvermindDL1" data-post="17" data-topic="19248">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar"> OvermindDL1:</div>
<blockquote>
<p>Backpressure is handled based on message sending, so if the gen_server gets lots and lots of message then processes that send it a message get ‘slowed’ down (higher reductions used) to throttle them enough so the system doesn’t get overwhelmed. It doesn’t matter whether call or cast is used for that. Generally you want <code>call</code> when you want to serialize the call or <code>cast</code> to async the call.</p>
</blockquote>
</aside>
<p>Right. I have heard of that mechanism, but perhaps I misunderstood how completely it handled the situation. Good to know.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111881" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-111881" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111881"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="111886" data-post-id="111886">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="JEG2" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/JEG2/120/936_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  JEG2
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Designing Elixir Systems with OTP</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m not aware of a “backpressure mechanism” in OTP.</p>
<p>One way backpressure is commonly added is to check the process’s mailbox size in the caller, before sending the message.  If the size is under some high water mark, a <code>cast</code> is performed.  If the size is at or over the same mark, a <code>call</code> is made instead.  This forces the sender to wait on the reply, thus slowing them down.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111886" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-111886" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111886"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="111887" data-post-id="111887">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="JEG2" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/JEG2/120/936_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  JEG2
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Designing Elixir Systems with OTP</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, I tend to favor <code>call</code> for the reasons you outlined.  If I don’t really need a response I just return <code>:ok</code>.  I switch to a <code>cast</code> after identifying a need:  raw speed, circular message passing, etc.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111887" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-111887" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111887"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="111889" data-post-id="111889">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="onebox allowlistedgeneric" data-onebox-src="http://erlang.org/pipermail/erlang-questions/2014-November/081843.html">
  <header class="source">

      <a href="http://erlang.org/pipermail/erlang-questions/2014-November/081843.html" target="_blank" rel="noopener nofollow">erlang.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="http://erlang.org/pipermail/erlang-questions/2014-November/081843.html" target="_blank" rel="noopener nofollow">[erlang-questions] Configuring Messaging Back Pressure</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<blockquote>
<p>erts_use_sender_punish is a flag hard coded to 1 (true), when it is true<br>
a process sending messages to another process will have its reduction<br>
count reduced by the number of messages in the receivers message queue<br>
multiplied by four.  Sending messages to processes with zero messages in<br>
the queue is free in terms of reductions, but sending messages to load<br>
queues is very expensive and will lead the scheduler to context switch<br>
to another process more often.</p>
</blockquote>
<p>I.E. reductions are reduced based on the mailbox size of the receiver process.</p>
<p>It’s not designed to ‘save’ a system, just allow it to handle load better.  If you runaway by spamming messages that the receiver can’t go through fast enough then you will still eventually run out of memory, you should use <code>call</code> if that’s possible, thus causing a synchronization point, however not even call will save you if a process is being spawned (like a web request) to make that <code>call</code>, you can still run out of memory that way, but backpressure will still ‘slow it down’ so it won’t happen quite as fast (and in fact in these short-lived process cases then <code>cast</code> could be better as the process could die sooner, saving memory).  The BEAM’s built-in backpressure works best with many sending to few processes many times.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>EDIT:  Also, as a side note, using <code>call</code> instead of <code>cast</code> is not backpressure, it is forcing a queue size of 1 instead of N between those two processes, which only helps when one process is sending a lot of messages to another, not when a lot of processes are sending a message to one (which it can hurt).</p>
<p>EDIT2:  Oh hey, OTP 19 added a flag (<code>max_heap_size</code>) to set the maximum size of the entire process, including its mailbox, before OTP will kill the process so you can set that to prevent entire VM death.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>EDIT3:  You know, the new <code>:atomics</code> module would make it quite nice to make a wrapper to pretend the mailbox of a process is self-limitating, or perhaps pretend it’s like a bounded queue so the caller can do ‘something else’ if it is getting overloaded…  This could be a good and cheap pattern for pretending that some messages are allowed to be lossy in certain situations…  ^.^</p>
<p>EDIT4:  Oh hey, <a class="mention" href="/u/ferd" rel="nofollow">@ferd</a> has a webpage about all kinds of different backpressure patterns and ways to handle overload via a variety of different ways for a variety of different circumstances, it looks pretty comprehensive.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p><aside class="onebox allowlistedgeneric" data-onebox-src="https://ferd.ca/handling-overload.html">
  <header class="source">
      <img src="https://ferd.ca/static/img/favicon.ico" class="site-icon" alt="" width="16" height="16">

      <a href="https://ferd.ca/handling-overload.html" target="_blank" rel="noopener nofollow ugc">ferd.ca</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://ferd.ca/handling-overload.html" target="_blank" rel="noopener nofollow ugc">Handling Overload</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111889" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pragdave-s-new-component-library-his-preferred-way-of-building-apps/19248/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-111889" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111889"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/19248/load_more?page=3">Load more posts (24 remaining)</a>
</div></template></turbo-stream>