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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi there - benchee creator here,</p>
<p>to be clear this is absolutely intended behaviour on the side of benchee.</p>
<p>The <code>parallel</code> option is there to exercise more load on the system or gather more data samples in the same time. Benchee is concerned with measuring and providing data about the time it takes individual function calls to execute. The function takes 10 seconds to execute hence an average of 1 and an ips of one is the correct behaviour.</p>
<p>I’ll edit the <a href="https://github.com/bencheeorg/benchee/wiki/Parallel-Benchmarking" rel="noopener nofollow ugc">parallel benchmarking wiki page</a> to highlight this property even more.</p>
<p>Cheers,<br>
Tobi</p>
<p>PS: I haven’t read the original thread (yet), I will and I have something of note to say I’ll add a new post</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143898" data-batch-url="/posts/batch_likers">
                        7
                      </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/looking-for-help-with-poor-ecto-query-performance/25476/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-143898" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143898"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="143908" data-post-id="143908">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Okay I do have some more input here <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p>
<p><a class="mention" href="/u/benwilson512" rel="nofollow">@benwilson512</a> <a class="mention" href="/u/scouten" rel="nofollow">@scouten</a> there is a second misconception here, <code>:parallel</code> doesn’t really batch in that sense.</p>
<blockquote>
<p>If <code>parallel: 4</code> then 4 processes will be spawned that all execute the <em>same</em> function for the given time. When these finish/the time is up 4 new processes will be spawned for the next scenario</p>
</blockquote>
<p>The 4 processes just dutifully call their function for the specified <code>:time</code> - each as often as they can, no waiting nothing. The <em>new scenario</em> refers to if there’s either another input or another function being benchmarked. So there’s no “waiting” effect to account for.</p>
<p>At it’s core benchee uses the most naive parallel map for this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def map(collection, func) do
    collection
    |&gt; Enum.map(fn element -&gt; Task.async(fn -&gt; func.(element) end) end)
    |&gt; Enum.map(&amp;Task.await(&amp;1, :infinity))
  end
</code></pre>
<p>And later on they are simply flat_map’ed:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    run_times = Enum.flat_map(measurements, fn {run_times, _} -&gt; run_times end)
    memory_usages = Enum.flat_map(measurements, fn {_, memory_usages} -&gt; memory_usages end)
</code></pre>
<p>As for how do we get to the total “throughput” - just multiplying the IPS with the number of parallel processes should be more or less okay. It will be slightly inaccurate due to different abort times but with a high enough sample size it shouldn’t matter.</p>
<p>If you really wanted to see your parallel throughput in my opinion <em>you</em> should provide the parallelism, because that’s a crucial part performance wise. Our naive implementation works for us but as I said it’s rather naive, things like <a href="https://hexdocs.pm/elixir/master/Task.html#async_stream/5" rel="noopener nofollow ugc"><code>Task.async_stream</code></a> ore more advanced things are a better choice for all that I know <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>All that said, I’m contemplating the display of a “throughput” when parallel is used in benchee now but I’m a bit torn on it. I’ll have to meditate on it, I’ll try to make the docs even clearer on the existing option. It’s powerful and was very easy to add, but seemingly sadly has sometimes done more harm than good.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143908" 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/looking-for-help-with-poor-ecto-query-performance/25476/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-143908" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143908"
                     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 #23"></div>
  </section>
</div>
    <div class="postbit" id="143911" data-post-id="143911">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="scouten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/scouten/120/2055_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  scouten
                    <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>We are currently working on reproducing our results without benchee. Will report back as we know more, hopefully later today.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143911" 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/looking-for-help-with-poor-ecto-query-performance/25476/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-143911" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143911"
                     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 #24"></div>
  </section>
</div>
    <div class="postbit" id="143915" data-post-id="143915">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>When looking at your results and taking the parallel 20 example and multiplying it with its ips you’re almost at the pg_bench result and the remaining 10% or so can be accounted for through decoding/encoding etc imo.</p>
<p>If you provide <code>extended_statistics: true</code> you’ll also get the sample size aka the total number of times the function ran/number of transactions.</p>
<p>Looking at your statistics from the one run that is shown completely I can see that there is a HUGE difference between median and average and 99th% is even LOWER than the average. That means that there is a huge outlier out there some where. Maybe a very big garbage collection run (don’t forget this you’re producing a lot of memory garbage) or a long time waiting for a new connection.</p>
<p>The median seems in line with pg_bench times. Pg_bench doesn’t have to deal with GC so that seems likely.</p>
<p>I’d recommend using the HTML formatter to see the outlier. You might have to lower the times though as it might break graphing that many samples.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143915" 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/looking-for-help-with-poor-ecto-query-performance/25476/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-143915" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143915"
                     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 #25"></div>
  </section>
</div>
    <div class="postbit" id="143917" data-post-id="143917">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="scouten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/scouten/120/2055_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  scouten
                    <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>I think we may be on to something there. Working on breaking up the test runner so that we build up less garbage per-process.</p>
<p>Definitely seeing a big delta between 99th percentile and max.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143917" 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/looking-for-help-with-poor-ecto-query-performance/25476/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-143917" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143917"
                     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 #26"></div>
  </section>
</div>
    <div class="postbit" id="143967" data-post-id="143967">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>To avoid garbage influencing your measurements you could use hooks with <code>after_each: fn _ -&gt; :erlang.garbage_collect() end</code> however those collects take a long time so the total number of samples/work done will go down by A LOT.</p>
<p>It’s a nice way to check if it’s really GC though (increase the time by a bit though so you get at least some samples in <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"> ) To see how it affects the sample size I still recommend <code>extended_statistics: true</code></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="143967" 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/looking-for-help-with-poor-ecto-query-performance/25476/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-143967" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="143967"
                     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 #27"></div>
  </section>
</div>
    <div class="postbit" id="144056" data-post-id="144056">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="scouten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/scouten/120/2055_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  scouten
                    <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>Thanks, all, for the feedback on benchee’s intended design space. I’ve updated the benchmark repo (<a href="https://github.com/scouten/pghr" class="inline-onebox" rel="noopener nofollow ugc">GitHub - scouten-archive/pghr: Q&amp;D demo of PG perf issues · GitHub</a>). In this version, I’ve:</p>
<ul>
<li>replaced benchee with my own (very quick-n-dirty) parallel benchmark runner,</li>
<li>upgraded Postgres to a more recent version (11.5 vs 9.6),</li>
<li>broken out a raw-SQL update from an Ecto-based update,</li>
<li>re-run all benchmarks and posted new results.</li>
</ul>
<p><strong>New findings:</strong> Create record results are now at least within the same order of magnitude as the <code>pgbench</code> results.</p>
<p>Unfortunately, update performance is still off by a <strong>large</strong> margin (roughly 15x). One concern that was raised was that the Ecto version needs to read the row and then update that row. To isolate that concern, I wrote a version of the benchmark that uses exactly the same SQL statement (via <code>SQL.query!</code>) as the one being run in <code>pgbench</code>. The results of that test are essentially the same as the pure Ecto 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="144056" 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/looking-for-help-with-poor-ecto-query-performance/25476/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-144056" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144056"
                     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 #28"></div>
  </section>
</div>
    <div class="postbit" id="144057" data-post-id="144057">
  <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="scouten" data-post="29" data-topic="25476">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/scouten/48/2055_2.png" class="avatar"> scouten:</div>
<blockquote>
<p>One concern that was raised was that the Ecto version needs to read the row and then update that row.</p>
</blockquote>
</aside>
<p>Why?  You can pass an update query to update, it shouldn’t need to read back the rows at all?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144057" 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/looking-for-help-with-poor-ecto-query-performance/25476/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-144057" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144057"
                     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 #29"></div>
  </section>
</div>
    <div class="postbit" id="144058" data-post-id="144058">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Drop change sets and use <code>Repo.update_all/3</code> as right now you need to make more queries, processing, and validations.</p>
<p><a href="https://github.com/scouten/pghr/pull/7/files" rel="noopener nofollow ugc">Here you go</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144058" 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/looking-for-help-with-poor-ecto-query-performance/25476/31">Post #30</a>
	                </div>
	            </div>
              <div id="likers-container-144058" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144058"
                     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 #30"></div>
  </section>
</div>
    <div class="postbit" id="144062" data-post-id="144062">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="scouten" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/scouten/120/2055_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  scouten
                    <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>Thanks for the suggestion. I happened to write a version of that at the same time (see my PR <span class="hashtag-raw">#8</span>, just merged), which I think is differs from yours only in a trivial syntax approach.</p>
<p>I see a very modest performance gain (maybe 6% faster) compared to my previous update benchmarks (either the Ecto changeset or the raw SQL), but it’s still <strong>way</strong> off the <code>pgbench</code> results. Numbers are added to the README.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="144062" 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/looking-for-help-with-poor-ecto-query-performance/25476/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-144062" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="144062"
                     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 #31"></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/25476/load_more?page=4">Load more posts (52 remaining)</a>
</div></template></turbo-stream>