<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">When doing some testing on <a href="http://github.com/robaho/httpserver" class="">github.com/robaho/httpserver</a> - which is a fork of the jdk http server, I discovered a significant performance issue.<div class=""><br class=""></div><div class="">When an http connection is in ‘keep-alive’ - the default for http 1.1 - the headers are “flushed” here <a href="https://github.com/openjdk/jdk21/blob/890adb6410dab4606a4f26a942aed02fb2f55387/src/jdk.httpserver/share/classes/sun/net/httpserver/ExchangeImpl.java#L281" class="">https://github.com/openjdk/jdk21/blob/890adb6410dab4606a4f26a942aed02fb2f55387/src/jdk.httpserver/share/classes/sun/net/httpserver/ExchangeImpl.java#L281</a></div><div class=""><br class=""></div><div class="">This means that after the handler runs and it sends data - e.g. /hello sends “hello” on the connection, the connection will stall due to the Nagel algorithm - usually incurring a 50 ms delay. The stall occurs since the client will not see the expected data until after the delay, so it is unable to send the next (when reusing the same connection/HttpClient).</div><div class=""><br class=""></div><div class="">You can set the TCP_NODELAY on the server to work-around this, but a better solution would be to override the flush() on the BufferedOutputStream to not flush() the underlying connection - i.e. only write the buffered bytes, or rework it a bit to only flush when there is no content to send.</div><div class=""><br class=""></div></div><div dir="ltr"></div></body></html>