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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="idi527" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  idi527
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>There have also been several threads on elixirforum about performance in benchmarks. Some of them might be relevant to you.</p>
<aside class="quote quote-modified" data-post="1" data-topic="473">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/apenney/48/1292_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/plug-post-performance/473" rel="nofollow">Plug POST performance</a> <a class="badge-category__wrapper " href="/c/questions-help/questions/53" rel="nofollow"><span data-category-id="53" style="--category-badge-color: #C14BFB; --category-badge-text-color: #000000; --parent-category-badge-color: #C14BFB;" data-parent-category-id="171" data-drop-close="true" class="badge-category --style-square --has-parent" title="Elixir Questions / Help"><span class="badge-category__name">Questions</span></span></a>
    </div>
  </div>
  <blockquote>
    At work we have a lot of Scala code in our low latency/high throughput product and a couple of us have been advocating Elixir as an alternative to the current codebase.  We recently undertook a 24 hour hackathon and tried to replace a chunk of our code with Elixir but immediately ran into performance issues.  I’m hoping other people on the list might have some suggestions for me because I’ve picked the brains of the IRC channel and been unable to improve things. 
To begin with I’ll set the stage…
  </blockquote>
</aside>

<aside class="quote" data-post="1" data-topic="4951">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mbenatti/48/9575_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/which-is-the-fastest-web-framework-link-repo-and-results-in-this-topic/4951" rel="nofollow">Which is the fastest web framework? (Link/Repo and results in this Topic)</a> <a class="badge-category__wrapper " href="/c/chat-discussions/chat-discussions/167" rel="nofollow"><span data-category-id="167" style="--category-badge-color: #cca771; --category-badge-text-color: #FFFFFF; --parent-category-badge-color: #cca771;" data-parent-category-id="165" data-drop-close="true" class="badge-category --style-square --has-parent"><span class="badge-category__name">Discussions</span></span></a>
    </div>
  </div>
  <blockquote>
    Following <a href="https://github.com/tbrand/which_is_the_fastest" rel="noopener nofollow ugc">https://github.com/tbrand/which_is_the_fastest</a> |&gt; 
<a href="https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs/result.png" rel="noopener nofollow ugc">https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs/result.png</a> 
Updated with Elixir^ 
Now there are frameworks in these languages: 
Ruby (bundler)
Go
Crystal
Rust
node

I would love to see Phoenix framework in this benchmark
  </blockquote>
</aside>

<p><code>which_is_the_fastest</code> benchmark though had a strange benchmarking tool, so those results might be discarded.</p>
<aside class="quote quote-modified" data-post="1" data-topic="5660">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/i/85e7bf/48.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/cowboy1-and-cowboy2-performance-in-a-synthetic-benchmark/5660" rel="nofollow">Cowboy1 and cowboy2 performance in a synthetic benchmark</a> <a class="badge-category__wrapper " href="/c/chat-discussions/chat-discussions/167" rel="nofollow"><span data-category-id="167" style="--category-badge-color: #cca771; --category-badge-text-color: #FFFFFF; --parent-category-badge-color: #cca771;" data-parent-category-id="165" data-drop-close="true" class="badge-category --style-square --has-parent"><span class="badge-category__name">Discussions</span></span></a>
    </div>
  </div>
  <blockquote>
    So I wanted to see how much overhead plug actually adds to cowboy and I tried to add cowboy to the  <a href="https://github.com/tbrand/which_is_the_fastest" class="inline-onebox-loading" rel="noopener nofollow ugc">https://github.com/tbrand/which_is_the_fastest</a> benchmark. It didn’t go quite as expected since cowboy 2.0-pre turned out to be much slower than plug there. So then I tried cowboy 1.1 which plug and phoenix use, but it still was a bit slower. Can maybe somebody with more experience with cowboys look into the code and maybe see ways to improve it? 
my fork of the benchmark for 

cowboy 1.1 <a href="https://github.com/idi-ot/which_is_the_fastest/tree/8c3680d888c4e9e3b534f9d6b0cb44e83071896c/elixir/cowboy1" class="inline-onebox-loading" rel="noopener nofollow ugc">https://g…</a>
  </blockquote>
</aside>

<p><code>cowboy1-and-cowboy2</code> is also somewhat controversial since in a blog post by <a class="mention" href="/u/potatosalad" rel="nofollow">@potatosalad</a>  <a href="https://potatosalad.io/2017/08/20/load-testing-cowboy-2-0-0-rc-1" class="inline-onebox" rel="noopener nofollow ugc">Load Testing cowboy 2.0.0-rc.1 · potatosalad</a> cowboy2 was much faster than cowboy1 and in my tests it was the opposite (different benchmarking tools).</p>
<aside class="quote" data-post="1" data-topic="5036">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/satb/48/29729_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/techempower-benchmarks-round-14/5036" rel="nofollow">TechEmpower Benchmarks Round 14</a> <a class="badge-category__wrapper " href="/c/chat-discussions/chat-discussions/167" rel="nofollow"><span data-category-id="167" style="--category-badge-color: #cca771; --category-badge-text-color: #FFFFFF; --parent-category-badge-color: #cca771;" data-parent-category-id="165" data-drop-close="true" class="badge-category --style-square --has-parent"><span class="badge-category__name">Discussions</span></span></a>
    </div>
  </div>
  <blockquote>
    Hot off the presses in the round 14 battle - <a href="https://www.techempower.com/benchmarks/" class="inline-onebox-loading" rel="noopener nofollow ugc">https://www.techempower.com/benchmarks/</a> 
Phoenix somewhere at the median line. I am not too crazy about these numbers. Just interesting to watch.
  </blockquote>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="61850" 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/performance-best-practices/10822/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-61850" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="61850"
                     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="61851" data-post-id="61851">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Some general notes:</p>
<ol>
<li>
<p>Make sure to remove unecessary plugs from your endpoint.</p>
</li>
<li>
<p>Make sure you are comparing apples with apples. For example, if one is logging and the other isn’t, that’s going to be a huge difference in performance.</p>
</li>
<li>
<p>Make sure to set max_keepalive otherwise connections will be recycled over and over again</p>
</li>
<li>
<p>A larger connection pool often implies worst performance, because there is less resource sharing</p>
</li>
</ol>
<p>But in general, if you are getting 408ms for such a simple page, <a class="mention" href="/u/overminddl1" rel="nofollow">@OvermindDL1</a> is right: there is something absurdly wrong.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="61851" 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/performance-best-practices/10822/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-61851" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="61851"
                     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="61869" data-post-id="61869">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="merlin" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  merlin
                    <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 all your suggestions !</p>
<p>408ms is an average based on the wrk load test above. I’m going to try to improve the results, I  think I’ll get better load times by tuning the EVM/elixir and FreeBSD.</p>
<p>Well if someone could perform the same tests and confirm the cowboy/fasthttp load time ratio … Should not take more than 15 minutes <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p>
<p>Regarding the max_keepalive: before increasing it I want to understand how connection pooling works exactly in cowboy. And assess if this server is subject to Slow HTTP Dos Attacks such as described here:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://www.acunetix.com/blog/articles/slow-http-dos-attacks-mitigate-apache-http-server/">
  <header class="source">
      <img src="https://www.acunetix.com/wp-content/themes/acunetix/ico/favicon.png" class="site-icon" alt="" width="64" height="64">

      <a href="https://www.acunetix.com/blog/articles/slow-http-dos-attacks-mitigate-apache-http-server/" target="_blank" rel="noopener nofollow ugc" title="08:00AM - 06 June 2019">Acunetix – 6 Jun 19</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:600/315;"><img src="https://cdn.acunetix.com/wp-content/uploads/2019/06/11110901/slow_featured.png" class="thumbnail" alt="" width="600" height="315"></div>

<h3><a href="https://www.acunetix.com/blog/articles/slow-http-dos-attacks-mitigate-apache-http-server/" target="_blank" rel="noopener nofollow ugc">Mitigate Slow HTTP GET/POST Vulnerabilities in the Apache HTTP Server | Acunetix</a></h3>

  <p>A Slow HTTP DoS Attack takes advantage of a vulnerability in thread-based web servers which wait for entire HTTP headers to be received before releasing the connection.</p>

  <p>
    <span class="label1">Est. reading time: 5 minutes</span>
  </p>

  </article>

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

  <div style="clear: both"></div>
</aside>
<p>
In one of the posts above I saw someone setting it to 5_000_000 … wow <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_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="61869" 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/performance-best-practices/10822/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-61869" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="61869"
                     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="61870" data-post-id="61870">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="idi527" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  idi527
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>And assess if this server is subject to Slow HTTP Dos Attacks such as described here:</p>
</blockquote>
<aside class="quote quote-modified" data-post="15" data-topic="694">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/aseigo/48/10674_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/is-cowboy-a-production-ready-server/694/15" rel="nofollow">Is Cowboy a production ready server?</a> <a class="badge-category__wrapper " href="/c/questions-help/questions/53" rel="nofollow"><span data-category-id="53" style="--category-badge-color: #C14BFB; --category-badge-text-color: #000000; --parent-category-badge-color: #C14BFB;" data-parent-category-id="171" data-drop-close="true" class="badge-category --style-square --has-parent" title="Elixir Questions / Help"><span class="badge-category__name">Questions</span></span></a>
    </div>
  </div>
  <blockquote>
    FWIW Cowboy has code to protect against slow requests: <a href="http://blog.differentpla.net/blog/2013/11/03/cowboy-request-timeouts" class="inline-onebox-loading" rel="noopener nofollow ugc">http://blog.differentpla.net/blog/2013/11/03/cowboy-request-timeouts</a> … though I have not tested if that is sufficient in practice. 
That said, cowboy is used a lot in production environments, and while no software can be considered 100% secure, it seems to be quite solid in practice. 
On the topic of porxying, I would definitely recommend haproxy over apache, and even nginx. Apache is far more than one needs for a simple proxy (overhead, con…
  </blockquote>
</aside>

<p>Still, I usually put haproxy in front of erlang webservers (I usually use elli).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="61870" 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/performance-best-practices/10822/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-61870" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="61870"
                     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="61873" data-post-id="61873">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Cowboy’s max_keepalive is not a timeout, it’s the maximum number of HTTP requests that can be done reusing the same connection. It has a separate timeout and maximum number of connections.</p>
<p><a href="https://github.com/ninenines/cowboy/commit/a013becc66b50db038c1f7f3539040b4482bba18" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/ninenines/cowboy/commit/a013becc66b50db038c1f7f3539040b4482bba18</a></p>
<p><a href="https://github.com/ninenines/cowboy/commit/5d698250b228229001ca9966a390bf1545fcd0b0" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/ninenines/cowboy/commit/5d698250b228229001ca9966a390bf1545fcd0b0</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="61873" 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/performance-best-practices/10822/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-61873" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="61873"
                     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="61878" data-post-id="61878">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="merlin" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  merlin
                    <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>So I’ve re-run several tests setting max_keepalive to 5_000_000.</p>
<p>With:<br>
<code>wrk -t12 -c12 -d1s -T10s http://.../fortune</code><br>
I get  an average latency of 8.3 ms and max latency of 100ms.</p>
<p>With (same as my initial tests):<br>
<code>wrk -tc -c12000 -d60s -T10s http://.../fortune</code><br>
I get  an average latency of 404ms ms and max latency of 707ms.</p>
<p>Max latency is much better ! 700ms instead of 8000ms<br>
I’ve also tried to lower db pool size to 20, avg latency decreased to 390ms.<br>
Though the average latency remains <span class="mention">@400ms</span>.</p>
<p>Thanks for links regarding the slow attacks, I’ll have to read all of this. Even if  Cowboy servers are not in front I prefer to be very cautious when dealing with such config params. Might as well induce resource exhaustion. I’ll run some tests when I have time.</p>
<p>I’m going deeper underground <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":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="61878" 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/performance-best-practices/10822/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-61878" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="61878"
                     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>