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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Oliver" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Oliver/120/1167_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Oliver
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, maybe I can.</p>
<p>While I don’t have control over the CI machine, maybe I could change the job script so that pulls in the elixir tarball, builds it, and then let it use that one instead of the one we have deployed. Maybe. <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" 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="195987" 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/how-to-affect-number-of-cores-elixir-compilation-utilizes/35870/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-195987" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="195987"
                     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="330418" data-post-id="330418">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Oliver" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Oliver/120/1167_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Oliver
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Well, we eventually upgraded to 1.14.4 (OTP25), and I remember expecting it to improve because dependency analysis is said to be improved, but the load average stays at 4 for 16 virtual cores.</p>
<p>Ironically, I found this thread when trying to analyze the same problem four years later. <img src="https://forum.elixirforum.com/images/emoji/apple/stuck_out_tongue.png?v=15" title=":stuck_out_tongue:" class="emoji" alt=":stuck_out_tongue:" loading="lazy" width="20" height="20"> I just didn’t check back then when we upgraded, but I see load averages remain where they were, I guess.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="330418" 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/how-to-affect-number-of-cores-elixir-compilation-utilizes/35870/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-330418" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="330418"
                     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="330419" data-post-id="330419">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Oliver" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Oliver/120/1167_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Oliver
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Just to give a bit of an impression about the code base:</p>
<ul>
<li>700+ files</li>
<li>450K lines of elixir code</li>
<li>Biggest file, 302K lines (it’s generated) - about 380K in total in generated files.</li>
<li>Most files range between 15-150 lines, though (of the remaining 70K lines)</li>
</ul>
<p>So I guess I’ll look for a way to split the really large files, even though they would only occupy one core each, and see what happens. <img src="https://forum.elixirforum.com/images/emoji/apple/man_shrugging.png?v=15" title=":man_shrugging:" class="emoji" alt=":man_shrugging:" 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="330419" data-batch-url="/posts/batch_likers">
                        0
                      </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/how-to-affect-number-of-cores-elixir-compilation-utilizes/35870/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-330419" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="330419"
                     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="330499" data-post-id="330499">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Oliver" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Oliver/120/1167_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Oliver
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Had some fun with the compiler.</p>
<p>I had a map of maps - it was (pretty-printed) 100K lines long. So I wanted to “optimize it.”</p>
<p>Instead of this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">%{ "A_KEY" =&gt; %{ group1_key1: "blurb",
                               ....},
   "ANOTHER_KEY" =&gt; ... 
</code></pre>
<p>I decided to do this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">%{ "A_KEY" =&gt; AnotherModuleInAnotherFile.A_KEY.group,
   "ANOTHER_KEY" =&gt; AnotherModuleInAnotherFile.ANOTHER_KEY.group
   ,,,}

# and in a separate file
defmodule AnotherModuleInAnotherFile.A_KEY do

def group do
  %{ group1_key1: "blurb",
                               ....}
end

end
</code></pre>
<p>The map had basically 155 sub-maps which I put into separate files.</p>
<p>My expectation was that this would be a way to split this huge map sensibly. The sub-maps were completey constant so I expected the implementations of the <code>group/1</code> functions to simply return a pointer or reference to term storage and this to become super-cheap in terms of compilation. (And to be done in parallel.)</p>
<p>Instead I learned of a new compiler-error:</p>
<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/1/b/1b5dd2126db2a122fdc78f28a9d6d13142c6c90d.png" data-download-href="https://forum.elixirforum.com/uploads/default/1b5dd2126db2a122fdc78f28a9d6d13142c6c90d" title="image" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/original/3X/1/b/1b5dd2126db2a122fdc78f28a9d6d13142c6c90d.png" alt="image" data-base62-sha1="3U5TSYa16aFJwJA4yKkjIm08RYN" width="606" height="107"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">606×107 10.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
<p>The supposedly complex instruction was described as: <code>{call_ext,0,{extfunc,'Elixir.MyModule.MY_KEY',group,0}}</code></p>
<p>Also, compilation expanded from roughly 90s (for a total of 300K lines) into more than ten minutes when it got killed by a supervision process.</p>
<p>So much for my assumptions of how to make code compile in parallel. <img src="https://forum.elixirforum.com/images/emoji/apple/laughing.png?v=15" title=":laughing:" class="emoji" alt=":laughing:" loading="lazy" width="20" height="20"></p>
<p>So I kept the huge maps, but split the file in three parts, and that’s what I can sensibly do here, I guess.</p>
<p>Alternatively I could instead put all the 155 entries into <code>:persistent_term</code> instead with 155 generated <code>put/2</code> calls and use that. The map literal is just a module attribute used by a function for lookup. So, it could also simply refer to <code>:persistent_term.get/1</code> without changing the interface.</p>
<p>I guess in that case the compiler would not be forced to resolve it the same way. (I assume the compiler simply tried to resolve the map literal just the same as before, but the ext functions made its work more complex…)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="330499" data-batch-url="/posts/batch_likers">
                        0
                      </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/how-to-affect-number-of-cores-elixir-compilation-utilizes/35870/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-330499" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="330499"
                     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="330500" data-post-id="330500">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benwilson512" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/120/1457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benwilson512
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Craft GraphQL APIs in Elixir with Absinthe</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ever since persistent term there isn’t really any need to bake constants into macro generated code literals anymore. It’s way faster to write into, and you get the same (and sometimes better) performance for reads. And it’s way easier to use.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="330500" 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/how-to-affect-number-of-cores-elixir-compilation-utilizes/35870/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-330500" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="330500"
                     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="330583" data-post-id="330583">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Something to note. Average core load of 4 does not mean only 4 cores are used</p>
<p>It could be that 16 are used but they spend most of their time on IO or idling or blocked by a lock somewhere. This is a not too rare thing to happen.</p>
<p>CPU load is a pretty flawed metric these days to evaluate how much you saturate the number of cores.</p>
<p>See <a href="https://www.brendangregg.com/blog/2017-05-09/cpu-utilization-is-wrong.html" class="inline-onebox" rel="noopener nofollow ugc">CPU Utilization is Wrong</a> and <a href="https://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html" class="inline-onebox" rel="noopener nofollow ugc">Linux Load Averages: Solving the Mystery</a> as starting points</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="330583" 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/how-to-affect-number-of-cores-elixir-compilation-utilizes/35870/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-330583" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="330583"
                     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="373291" data-post-id="373291">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I came here looking for an answer after observing a simple <a href="https://github.com/akoutmos/beam_basket_talk" rel="noopener nofollow ugc">livebook example</a> focused on PartitionSupervisor which is supposed to show the best use of all cores. However in my case (<code>[smp:12:12]</code>) it was only utilizing 4 cores.</p>
<p>Note that the example for some reason sets <code>max_concurrency: 2000</code> which I don’t have an explanation for. I was using it with <code>max_concurrency: System.schedulers_online()</code> instead. Going with much larger value expectedly reduces the throughput.</p>
<p>With this setup I was getting around 160K events per second, however my OS monitor was only showing 4 cores intermittently utilized. Notably, setting the <code>max_concurrency: 4</code> or even <code>3</code> did not change the throughput at all which confirms the setup is not CPU-bound.</p>
<p>Following the previous comments it might be reasonable to assume the message copying between the processes and the associated memory IO is the culprit. I haven’t investigated deeper myself, but maybe someone would have an explanation to this behavior now that a reproducible code is available.</p>
<p>It seems to me even with a high memory IO due to message passing, in the presence of a scheduler per core the cpu utilization should be better. And then, what is the benefit of PartitionSupervisor if CPU is not the bottleneck?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="373291" data-batch-url="/posts/batch_likers">
                        0
                      </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/how-to-affect-number-of-cores-elixir-compilation-utilizes/35870/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-373291" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="373291"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>