<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'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"><<a href="mailto:jason.greene@redhat.com" target="_blank">jason.greene@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Nov 25, 2015, at 3:27 PM, Stuart Douglas <<a href="mailto:sdouglas@redhat.com">sdouglas@redhat.com</a>> wrote:<br>
><br>
><br>
><br>
> ----- Original Message -----<br>
>> From: "Andrew Brampton" <<a href="mailto:me@bramp.net">me@bramp.net</a>><br>
>> To: <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
>> Sent: Wednesday, 25 November, 2015 4:13:03 PM<br>
>> Subject: [undertow-dev] Undertow and non-blocking File IO<br>
>><br>
>> I just started playing with Undertow, but I had a couple of questions about<br>
>> the use of non-blocking operations vs using the worker thread pool.<br>
>><br>
>> In the ResourceHandler.java it appears to dispatch itself onto a worker<br>
>> thread, and then uses blocking file IO to actually read the file. I'm<br>
>> curious why a AsynchronousFileChannel wasn't used to read from the file in a<br>
>> non-blocking way? This would be in keeping with the non-blocking IO threads.<br>
><br>
> 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="">><br>
>><br>
>> I wrote a quick HttpHandler that used the AsynchronousFileChannel and it<br>
>> worked really well. However, when creating AsynchronousFileChannel you have<br>
>> to specify the ExecutorService to be used to schedule the completion handler<br>
>> callback on. I was able to use exchange.getIoThread().getWorker(), but I'm<br>
>> curious if there is a way to schedule it back on the IO Threads? It just<br>
>> seems "purer" keeping everything on a single IO thread per core.<br>
><br>
> 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>
><br>
> Stuart<br>
><br>
>><br>
>> thanks<br>
>> Andrew<br>
>><br>
>> _______________________________________________<br>
>> undertow-dev mailing list<br>
>> <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
>> <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>
> undertow-dev mailing list<br>
> <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
> <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>