<div dir="ltr">Thanks all, my mind is blown that the async file IO is actually using threads under the hood. I just spent a little while reading through the <span style="font-size:12.8px">SimpleAsynchronousFileChannelI</span><span style="font-size:12.8px">mpl source code, as well as reading up on Linux&#39;s AIO.</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks</span></div><div><span style="font-size:12.8px">Andrew</span></div><div><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 25 November 2015 at 13:50, Jason Greene <span dir="ltr">&lt;<a href="mailto:jason.greene@redhat.com" target="_blank">jason.greene@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
&gt; On Nov 25, 2015, at 3:27 PM, Stuart Douglas &lt;<a href="mailto:sdouglas@redhat.com">sdouglas@redhat.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; ----- Original Message -----<br>
&gt;&gt; From: &quot;Andrew Brampton&quot; &lt;<a href="mailto:me@bramp.net">me@bramp.net</a>&gt;<br>
&gt;&gt; To: <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
&gt;&gt; Sent: Wednesday, 25 November, 2015 4:13:03 PM<br>
&gt;&gt; Subject: [undertow-dev] Undertow and non-blocking File IO<br>
&gt;&gt;<br>
&gt;&gt; I just started playing with Undertow, but I had a couple of questions about<br>
&gt;&gt; the use of non-blocking operations vs using the worker thread pool.<br>
&gt;&gt;<br>
&gt;&gt; In the ResourceHandler.java it appears to dispatch itself onto a worker<br>
&gt;&gt; thread, and then uses blocking file IO to actually read the file. I&#39;m<br>
&gt;&gt; curious why a AsynchronousFileChannel wasn&#39;t used to read from the file in a<br>
&gt;&gt; non-blocking way? This would be in keeping with the non-blocking IO threads.<br>
&gt;<br>
&gt; This is something we should look at, however this only has an actual benefit on Windows AFAIK. Other platforms use SimpleAsynchronousFileChannelImpl which simply delegates to a thread pool.<br>
<br>
</span>The major issue that prevents this is that Linux filesystems (in combination with the kernel) can sometimes block in io_submit (e.g. during certain metadata operations). You also have to open a file aligned and in O_DIRECT which Java NIO does not support. If you look at what the glibc impl does, it actually ends up creating a thread pool of its own.<br>
<span class="">&gt;<br>
&gt;&gt;<br>
&gt;&gt; I wrote a quick HttpHandler that used the AsynchronousFileChannel and it<br>
&gt;&gt; worked really well. However, when creating AsynchronousFileChannel you have<br>
&gt;&gt; to specify the ExecutorService to be used to schedule the completion handler<br>
&gt;&gt; callback on. I was able to use exchange.getIoThread().getWorker(), but I&#39;m<br>
&gt;&gt; curious if there is a way to schedule it back on the IO Threads? It just<br>
&gt;&gt; seems &quot;purer&quot; keeping everything on a single IO thread per core.<br>
&gt;<br>
&gt; The IO threads implement Executor not ExecutorService, you could write a wrapper, but if you used it on non Windows platforms you would block the IO thread.<br>
&gt;<br>
&gt; Stuart<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; thanks<br>
&gt;&gt; Andrew<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; undertow-dev mailing list<br>
&gt;&gt; <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br>
&gt; _______________________________________________<br>
&gt; undertow-dev mailing list<br>
&gt; <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br>
<br>
</span>--<br>
Jason T. Greene<br>
WildFly Lead / JBoss EAP Platform Architect<br>
JBoss, a division of Red Hat<br>
<br>
</blockquote></div><br></div>