<div dir="ltr">I have included an example of the code I built to make sure all request data has been read before passing on to my next handler. It is included in the two attached files.<div><br></div><div>My questions are :</div><div>a) Does it look correct? Things seem to be working in practice, but I&#39;d like confirmation from people more experienced with undertow.</div><div>b) I am occasionally seeing requests that start in a non-io thread (i.e. if I call isInIoThread() as the first call of my root HttpHandler it returns false. Should that be possible?</div><div><br></div><div>Thanks,</div><div>Chris<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 28, 2015 at 9:16 PM Stuart Douglas &lt;<a href="mailto:sdouglas@redhat.com">sdouglas@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The non blocking API for reading data is actually something we are looking at improving in the next version of Undertow.<br>
<br>
For now you need to use the XNIO request channel. For an example of how to use this look at io.undertow.util.StringReadChannelListener (you can actually just subclass this class).<br>
<br>
Basically the most efficient way to use the API is:<br>
<br>
- Get a pooled buffer from the connections buffer pool<br>
- keep calling StreamSinkChannel.read() to read the data<br>
- If read returns 0 register a read listener and then call resumeReads() and return. Your listener will be notified when more data is available.<br>
- When read returns -1 you are done<br>
<br>
Stuart<br>
<br>
----- Original Message -----<br>
&gt; From: &quot;Chris Back&quot; &lt;<a href="mailto:chris.back@gmail.com" target="_blank">chris.back@gmail.com</a>&gt;<br>
&gt; To: <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
&gt; Sent: Wednesday, 29 April, 2015 12:08:09 AM<br>
&gt; Subject: [undertow-dev] Mostly IO, non-blocking workload best practice<br>
&gt;<br>
&gt; I am writing a server that will need to respond to lots of small web<br>
&gt; requests. Most of the requests will come with a small POST payload. Based on<br>
&gt; the contents of the payload, the server will either a) respond immediately,<br>
&gt; or b) forward the request as is to one of a pool of backend servers, waiting<br>
&gt; for a response and forwarding the response back to the client.<br>
&gt;<br>
&gt; It looks like given the existing undertow code, I have good examples of how<br>
&gt; to forward requests to the backend. What isn&#39;t as clear is how to handle the<br>
&gt; getting the POST data. Is there a way of doing that without blocking?<br>
&gt;<br>
&gt; Ideally, my handler flow would be:<br>
&gt;<br>
&gt; 1. Non-blocking request handler that makes sure all POST data is in.<br>
&gt; 2. A non-blocking handler that decisions based on content of POST data to<br>
&gt; 3a. Immediately return a response to the client (non-blocking).<br>
&gt; or<br>
&gt; 3b. Dispatch to the worker pool to forward request to backend server and<br>
&gt; await response.<br>
&gt;<br>
&gt; 90% of my requests will go through path 3a, and I&#39;d like that to be as quick<br>
&gt; as possible. When the server decides a request should go through 3b, only<br>
&gt; then should it go to the blocking worker pool.<br>
&gt;<br>
&gt; Am I viewing this correctly? What are my options? Based on this thread<br>
&gt; <a href="http://lists.jboss.org/pipermail/undertow-dev/2015-January/001082.html" rel="noreferrer" target="_blank">http://lists.jboss.org/pipermail/undertow-dev/2015-January/001082.html</a><br>
&gt; it seems like an option could be to get the request channel in step 1 above?<br>
&gt; Its not clear to me how that would work.<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Chris<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; undertow-dev mailing list<br>
&gt; <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">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>
</blockquote></div></div></div>