<div dir="ltr">Seems to Reading Request body is wrong , So what is the efficient way of reading request body in undertow ?<div><br></div><div>--Senthil</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 22, 2017 at 11:30 PM, SenthilKumar K <span dir="ltr">&lt;<a href="mailto:senthilec566@gmail.com" target="_blank">senthilec566@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello Undertow Dev Team ,<div><br></div><div>      I have been working on the use case where i should create simple http server to serve 1.5 Million Requests per Second per Instance .. </div><div><br></div><div><br></div><div>Here is the benchmark result of Undertow :</div><div><br></div><div><div>Running 1m test @ <a href="http://127.0.0.1:8009/" target="_blank">http://127.0.0.1:8009/</a></div><div>  20 threads and 40 connections</div><div>  Thread Stats   Avg      Stdev     Max   +/- Stdev</div><div>    Latency     2.51ms   10.75ms 282.22ms   99.28%</div><div>    Req/Sec     1.12k   316.65     1.96k    54.50%</div><div>  Latency Distribution</div><div>     50%    1.43ms</div><div>     75%    2.38ms</div><div>     90%    2.90ms</div><div>     99%   10.45ms</div><div>  1328133 requests in 1.00m, 167.19MB read</div><div>Requests/sec:  <b>22127</b>.92</div><div>Transfer/sec:      2.79MB</div></div><div><br></div><div>This is less compared to other frameworks like Jetty and Netty .. But originally Undertow is high performant http server .. </div><div><br></div><div>Hardware details:</div><div><span style="color:rgb(128,128,128);font-family:arial,helvetica,&quot;helvetica neue&quot;,verdana,sans-serif;font-size:14px">Xeon CPU E3-1270 v5 machine with 4 cores ( Clock 100 MHz, Capacity 4 GHz) , Memory : 32 G , Available memory 31 G.</span><br></div><div><br></div><div>I would need Undertow experts to review the server code below and advice me on tuning to achieve my goal( ~1.5 Million requests/sec ).</div><div><br></div><div>Server :</div><div><br></div><div><div>Undertow server = Undertow.builder()</div><div>               .addHttpListener(8009, &quot;localhost&quot;)</div><div>               .setHandler(new Handler()).build();</div><div>server.start();</div></div><div><br></div><div><br></div><div>Handler.Java</div><div><br></div><div><div>    final Pooled&lt;ByteBuffer&gt; pooledByteBuffer =          </div><div>                 exchange.getConnection().<wbr>getBufferPool().allocate();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>final ByteBuffer byteBuffer = pooledByteBuffer.getResource()<wbr>;</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    byteBuffer.clear();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    exchange.getRequestChannel().<wbr>read(byteBuffer);</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    int pos = byteBuffer.position();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    byteBuffer.rewind();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    byte[] bytes = new byte[pos];</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    byteBuffer.get(bytes);</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    String requestBody = new String(bytes, Charset.forName(&quot;UTF-8&quot;) );</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    byteBuffer.clear();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    pooledByteBuffer.free();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>    final PostToKafka post2Kafka = new PostToKafka();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>try {</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span><b>post2Kafka.write2Kafka(<wbr>requestBody);  { This API can handle  ~2 Millions events per sec }</b></div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>} catch (Exception e) {</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>e.printStackTrace();</div><div><span class="m_5540164263429922309gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>}</div><div>    exchange.getResponseHeaders().<wbr>put(Headers.CONTENT_TYPE, &quot;text/plain&quot;);</div><div>    exchange.getResponseSender().<wbr>send(&quot;SUCCESS&quot;);</div></div><div><br></div><div><br></div><div>--Senthil</div></div>
</blockquote></div><br></div>