<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'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 <<a href="mailto:sdouglas@redhat.com">sdouglas@redhat.com</a>> 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>
> From: "Chris Back" <<a href="mailto:chris.back@gmail.com" target="_blank">chris.back@gmail.com</a>><br>
> To: <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
> Sent: Wednesday, 29 April, 2015 12:08:09 AM<br>
> Subject: [undertow-dev] Mostly IO, non-blocking workload best practice<br>
><br>
> I am writing a server that will need to respond to lots of small web<br>
> requests. Most of the requests will come with a small POST payload. Based on<br>
> the contents of the payload, the server will either a) respond immediately,<br>
> or b) forward the request as is to one of a pool of backend servers, waiting<br>
> for a response and forwarding the response back to the client.<br>
><br>
> It looks like given the existing undertow code, I have good examples of how<br>
> to forward requests to the backend. What isn't as clear is how to handle the<br>
> getting the POST data. Is there a way of doing that without blocking?<br>
><br>
> Ideally, my handler flow would be:<br>
><br>
> 1. Non-blocking request handler that makes sure all POST data is in.<br>
> 2. A non-blocking handler that decisions based on content of POST data to<br>
> 3a. Immediately return a response to the client (non-blocking).<br>
> or<br>
> 3b. Dispatch to the worker pool to forward request to backend server and<br>
> await response.<br>
><br>
> 90% of my requests will go through path 3a, and I'd like that to be as quick<br>
> as possible. When the server decides a request should go through 3b, only<br>
> then should it go to the blocking worker pool.<br>
><br>
> Am I viewing this correctly? What are my options? Based on this thread<br>
> <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>
> it seems like an option could be to get the request channel in step 1 above?<br>
> Its not clear to me how that would work.<br>
><br>
> Thanks,<br>
> Chris<br>
><br>
> _______________________________________________<br>
> undertow-dev mailing list<br>
> <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">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>
</blockquote></div></div></div>