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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Reversion1817" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Reversion1817
                    <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>Sorry for a delayed response, I have been busy with some other tasks.</p>
<p><a class="mention" href="/u/hst337" rel="nofollow">@hst337</a> is absolutely right, measuring time in a correct way as well as scrutinizing the same code is the way to test it; I hope to format and put it here soon.</p>
<p>Meanwhile, I implemented the code suggested by <a class="mention" href="/u/dimitarvp" rel="nofollow">@dimitarvp</a>, it is about 25% faster.</p>
<p>Also, I have discovered where Issue <span class="hashtag-raw">#02</span> happens: after <code>Enum.map(&amp;Task.await/1)</code> finishes there is a noticeable delay (about 20 seconds). It only happens when called from within a barebones <code>GenServer</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="289329" 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/a-schrodingers-database-adapter-ecto-postgresql-perform-faster-when-observed-with-observer/55921/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-289329" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="289329"
                     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="298191" data-post-id="298191">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Reversion1817" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Reversion1817
                    <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><a class="mention" href="/u/bartotten" rel="nofollow">@BartOtten</a> <a class="mention" href="/u/hst337" rel="nofollow">@hst337</a> <a class="mention" href="/u/dimitarvp" rel="nofollow">@dimitarvp</a> thank you for your feedback.</p>
<p>It seems that after all probably the main issue was in not trying to overload/saturate the database correctly.</p>
<p>In the initial version of the code, I tried to launch N “parallel” queries against the database, where N could be as  large as 50_000.</p>
<p>In the version suggested by <a class="mention" href="/u/dimitarvp" rel="nofollow">@dimitarvp</a> and slightly modified by me, I split the whole array of tasks into chunks. But the splitting factor is very low, 8 or 16.</p>
<p>That way I roughly get 8-16 “workers” that run thousands of queries each. The performance does not seem to degrade probably because each “worker” manages to re-use the same database connection from the database connection pool.</p>
<p>Thx!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="298191" 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/a-schrodingers-database-adapter-ecto-postgresql-perform-faster-when-observed-with-observer/55921/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-298191" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="298191"
                     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>