From jockeeriksson at msn.com Wed Feb 13 04:39:37 2019 From: jockeeriksson at msn.com (Jocke Eriksson) Date: Wed, 13 Feb 2019 09:39:37 +0000 Subject: [undertow-dev] ProxyHandler returns 503 under load Message-ID: Hello, We are trying to build an API gateway using undertow as a servlet extension, this has been working great until we started our performance tests. Our setup is two gateways balancing traffic towards 10+ servers and we are using JBoss EAP 7.0 We have observed that some of our requests fail with 503 response. When we get a 503 response from a request, we have also observed that it never reaches the proxy target. I made a small test on my machine to see if I could get the same error, to my surprise this was very easy. First I tried with the following code. public class ApiGatewayServletExtension implements ServletExtension { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { LOG.info("Deploying {}...", MethodHandles.lookup().lookupClass().getSimpleName()); deploymentInfo.addInitialHandlerChainWrapper(handler -> { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); return new ProxyHandler(loadBalancer, 30000, handler); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); } }); } } I used JMeter with 20 threads making a simple rest GET request and after 30 seconds or so the test stopped with a 503 response. Then I created a small java application using undertow 2.0.17.Final like this. public static void main(final String[] args) { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); ProxyHandler proxyHandler = new ProxyHandler(loadBalancer, 30000, ResponseCodeHandler.HANDLE_404); Undertow server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(proxyHandler).build(); server.start(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } Getting the same result. I have also tried just loading the home page of one of our servers and still the same result. Any help would be very much appreciated. I have not created a bug because I'm pretty sure we are just missing something here. Regards Joakim Eriksson. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190213/3c838fde/attachment.html From ckozak at ckozak.net Wed Feb 13 08:16:24 2019 From: ckozak at ckozak.net (Carter Kozak) Date: Wed, 13 Feb 2019 08:16:24 -0500 Subject: [undertow-dev] ProxyHandler returns 503 under load In-Reply-To: References: Message-ID: When the connections-per-thread limit is reached, requests result in 503 responses. Is the problem resolved by increasing the connections-per-thread value to 50 or 100? On Wed, Feb 13, 2019, at 04:42, Jocke Eriksson wrote: > Hello, > > We are trying to build an API gateway using undertow as a servlet extension, this has been working great until we started our performance tests. > Our setup is two gateways balancing traffic towards 10+ servers and we are using JBoss EAP 7.0 We have observed that some of our requests fail with 503 response. When we get a 503 response from a request, we have also observed that it never reaches the proxy target. > I made a small test on my machine to see if I could get the same error, to my surprise this was very easy. First I tried with the following code. > > public class ApiGatewayServletExtension implements ServletExtension { > > > @Override > public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { > LOG.info("Deploying {}...", MethodHandles.lookup().lookupClass().getSimpleName()); > deploymentInfo.addInitialHandlerChainWrapper(handler -> { > try { > LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() > .addHost(new URI("http://localhost:8282")) > .setConnectionsPerThread(20); > return new ProxyHandler(loadBalancer, 30000, handler); > } catch (URISyntaxException ex) { > throw new IllegalStateException(ex); > } > }); > } > } > > I used JMeter with 20 threads making a simple rest GET request and after 30 seconds or so the test stopped with a 503 response. > > Then I created a small java application using undertow 2.0.17.Final like this. > > public static void main(final String[] args) { > > > try { > LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() > .addHost(new URI("http://localhost:8282")) > .setConnectionsPerThread(20); > ProxyHandler proxyHandler = new ProxyHandler(loadBalancer, 30000, ResponseCodeHandler.HANDLE_404); > > Undertow server = Undertow.builder() > .addHttpListener(8080, "localhost") > .setHandler(proxyHandler).build(); > > server.start(); > > } catch (Exception ex) { > System.out.println(ex.getMessage()); > } > } > > Getting the same result. I have also tried just loading the home page of one of our servers and still the same result. > > Any help would be very much appreciated. I have not created a bug because I'm pretty sure we are just missing something here. > > Regards Joakim Eriksson. > > > > > > > > _______________________________________________ > undertow-dev mailing list > undertow-dev at lists.jboss.org > https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190213/71113006/attachment-0001.html From sdouglas at redhat.com Wed Feb 13 22:11:23 2019 From: sdouglas at redhat.com (Stuart Douglas) Date: Thu, 14 Feb 2019 14:11:23 +1100 Subject: [undertow-dev] ProxyHandler returns 503 under load In-Reply-To: References: Message-ID: If there is only 20 clients then in theory this should not happen, however to some extent this is inherently racey. What can happen is that there is a slight delay between the client receiving the full response and the connection being returned to the pool (there is nothing that can be done about this, it is impossible to atomically send the last content and return the thread in one action). I would try calling setMaxQueueSize and add a small queue (say 20) which should resolve the issue. If not then this is definitely a bug. Stuart On Thu, Feb 14, 2019 at 1:53 AM Carter Kozak wrote: > When the connections-per-thread limit is reached, requests result in 503 > responses. Is the problem resolved by increasing the connections-per-thread > value to 50 or 100? > > On Wed, Feb 13, 2019, at 04:42, Jocke Eriksson wrote: > > Hello, > > We are trying to build an API gateway using undertow as a servlet > extension, this has been working great until we started our performance > tests. > Our setup is two gateways balancing traffic towards 10+ servers and we are > using JBoss EAP 7.0 We have observed that some of our requests fail with > 503 response. When we get a 503 response from a request, we have also > observed that it never reaches the proxy target. > I made a small test on my machine to see if I could get the same error, to > my surprise this was very easy. First I tried with the following code. > > public class ApiGatewayServletExtension implements ServletExtension { > > @Override > public void handleDeployment(DeploymentInfo deploymentInfo, > ServletContext servletContext) { > LOG.info("Deploying {}...", > MethodHandles.lookup().lookupClass().getSimpleName()); > deploymentInfo.addInitialHandlerChainWrapper(handler -> { > try { > LoadBalancingProxyClient loadBalancer = new > LoadBalancingProxyClient() > .addHost(new URI("http://localhost:8282")) > .setConnectionsPerThread(20); > return new ProxyHandler(loadBalancer, 30000, handler); > } catch (URISyntaxException ex) { > throw new IllegalStateException(ex); > } > }); > } > } > > I used JMeter with 20 threads making a simple rest GET request and after > 30 seconds or so the test stopped with a 503 response. > > Then I created a small java application using undertow 2.0.17.Final like > this. > > public static void main(final String[] args) { > > try { > LoadBalancingProxyClient loadBalancer = new > LoadBalancingProxyClient() > .addHost(new URI("http://localhost:8282")) > .setConnectionsPerThread(20); > ProxyHandler proxyHandler = new ProxyHandler(loadBalancer, > 30000, ResponseCodeHandler.HANDLE_404); > > Undertow server = Undertow.builder() > .addHttpListener(8080, "localhost") > .setHandler(proxyHandler).build(); > > server.start(); > > } catch (Exception ex) { > System.out.println(ex.getMessage()); > } > } > > Getting the same result. I have also tried just loading the home page of > one of our servers and still the same result. > > Any help would be very much appreciated. I have not created a bug because > I'm pretty sure we are just missing something here. > > Regards Joakim Eriksson. > > > > > > > > _______________________________________________ > undertow-dev mailing list > undertow-dev at lists.jboss.org > https://lists.jboss.org/mailman/listinfo/undertow-dev > > > _______________________________________________ > undertow-dev mailing list > undertow-dev at lists.jboss.org > https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190214/51c3f29c/attachment.html From jockeeriksson at msn.com Thu Feb 14 01:58:15 2019 From: jockeeriksson at msn.com (Jocke Eriksson) Date: Thu, 14 Feb 2019 06:58:15 +0000 Subject: [undertow-dev] ProxyHandler returns 503 under load In-Reply-To: References: , Message-ID: We made it work better by changing the worker configuration in JBoss like this. This looks like it could be a bit too much, but we can finetune that later. We do not use mod_cluster, do you recommend us to setConnectionsPerThread on the proxy client? Thanks for the help, Joakim. ________________________________ Fr?n: undertow-dev-bounces at lists.jboss.org f?r Carter Kozak Skickat: den 13 februari 2019 14:16 Till: undertow-dev at lists.jboss.org ?mne: Re: [undertow-dev] ProxyHandler returns 503 under load When the connections-per-thread limit is reached, requests result in 503 responses. Is the problem resolved by increasing the connections-per-thread value to 50 or 100? On Wed, Feb 13, 2019, at 04:42, Jocke Eriksson wrote: Hello, We are trying to build an API gateway using undertow as a servlet extension, this has been working great until we started our performance tests. Our setup is two gateways balancing traffic towards 10+ servers and we are using JBoss EAP 7.0 We have observed that some of our requests fail with 503 response. When we get a 503 response from a request, we have also observed that it never reaches the proxy target. I made a small test on my machine to see if I could get the same error, to my surprise this was very easy. First I tried with the following code. public class ApiGatewayServletExtension implements ServletExtension { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { LOG.info("Deploying {}...", MethodHandles.lookup().lookupClass().getSimpleName()); deploymentInfo.addInitialHandlerChainWrapper(handler -> { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); return new ProxyHandler(loadBalancer, 30000, handler); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); } }); } } I used JMeter with 20 threads making a simple rest GET request and after 30 seconds or so the test stopped with a 503 response. Then I created a small java application using undertow 2.0.17.Final like this. public static void main(final String[] args) { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); ProxyHandler proxyHandler = new ProxyHandler(loadBalancer, 30000, ResponseCodeHandler.HANDLE_404); Undertow server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(proxyHandler).build(); server.start(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } Getting the same result. I have also tried just loading the home page of one of our servers and still the same result. Any help would be very much appreciated. I have not created a bug because I'm pretty sure we are just missing something here. Regards Joakim Eriksson. _______________________________________________ undertow-dev mailing list undertow-dev at lists.jboss.org https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190214/d92df2d4/attachment-0001.html From jockeeriksson at msn.com Thu Feb 14 01:59:40 2019 From: jockeeriksson at msn.com (Jocke Eriksson) Date: Thu, 14 Feb 2019 06:59:40 +0000 Subject: [undertow-dev] ProxyHandler returns 503 under load In-Reply-To: References: , Message-ID: I will try this and get back to you after our tests. Ragrads Joakim. ________________________________ Fillr?n: undertow-dev-bounces at lists.jboss.org f?r Stuart Douglas Skickat: den 14 februari 2019 04:11 Till: Carter Kozak Kopia: Undertow Developers ?mne: Re: [undertow-dev] ProxyHandler returns 503 under load If there is only 20 clients then in theory this should not happen, however to some extent this is inherently racey. What can happen is that there is a slight delay between the client receiving the full response and the connection being returned to the pool (there is nothing that can be done about this, it is impossible to atomically send the last content and return the thread in one action). I would try calling setMaxQueueSize and add a small queue (say 20) which should resolve the issue. If not then this is definitely a bug. Stuart On Thu, Feb 14, 2019 at 1:53 AM Carter Kozak > wrote: When the connections-per-thread limit is reached, requests result in 503 responses. Is the problem resolved by increasing the connections-per-thread value to 50 or 100? On Wed, Feb 13, 2019, at 04:42, Jocke Eriksson wrote: Hello, We are trying to build an API gateway using undertow as a servlet extension, this has been working great until we started our performance tests. Our setup is two gateways balancing traffic towards 10+ servers and we are using JBoss EAP 7.0 We have observed that some of our requests fail with 503 response. When we get a 503 response from a request, we have also observed that it never reaches the proxy target. I made a small test on my machine to see if I could get the same error, to my surprise this was very easy. First I tried with the following code. public class ApiGatewayServletExtension implements ServletExtension { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { LOG.info("Deploying {}...", MethodHandles.lookup().lookupClass().getSimpleName()); deploymentInfo.addInitialHandlerChainWrapper(handler -> { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); return new ProxyHandler(loadBalancer, 30000, handler); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); } }); } } I used JMeter with 20 threads making a simple rest GET request and after 30 seconds or so the test stopped with a 503 response. Then I created a small java application using undertow 2.0.17.Final like this. public static void main(final String[] args) { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); ProxyHandler proxyHandler = new ProxyHandler(loadBalancer, 30000, ResponseCodeHandler.HANDLE_404); Undertow server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(proxyHandler).build(); server.start(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } Getting the same result. I have also tried just loading the home page of one of our servers and still the same result. Any help would be very much appreciated. I have not created a bug because I'm pretty sure we are just missing something here. Regards Joakim Eriksson. _______________________________________________ undertow-dev mailing list undertow-dev at lists.jboss.org https://lists.jboss.org/mailman/listinfo/undertow-dev _______________________________________________ undertow-dev mailing list undertow-dev at lists.jboss.org https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190214/f36b798e/attachment.html From marc.boorshtein at tremolosecurity.com Thu Feb 14 13:19:54 2019 From: marc.boorshtein at tremolosecurity.com (Marc Boorshtein) Date: Thu, 14 Feb 2019 13:19:54 -0500 Subject: [undertow-dev] Memory issue, how can I help? Message-ID: I opened an issue around memory management ( https://issues.jboss.org/browse/UNDERTOW-1486?filter=-2) and did some additional research to isolate at which version memory management seems to be an issue. Is there anything else I can do to help? Its been pretty easy for me to reproduce with jmeter. Thanks Marc -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190214/f3217468/attachment.html From jockeeriksson at msn.com Fri Feb 15 05:52:53 2019 From: jockeeriksson at msn.com (Jocke Eriksson) Date: Fri, 15 Feb 2019 10:52:53 +0000 Subject: [undertow-dev] ProxyHandler returns 503 under load In-Reply-To: References: , Message-ID: After adding more threads and using setMaxQueueSize, we are down to a handful of 503 responses. We will continue with some tunings to see if we can get down to zero. Thanks for the help Joakim. ________________________________ Fr?n: undertow-dev-bounces at lists.jboss.org f?r Stuart Douglas Skickat: den 14 februari 2019 04:11 Till: Carter Kozak Kopia: Undertow Developers ?mne: Re: [undertow-dev] ProxyHandler returns 503 under load If there is only 20 clients then in theory this should not happen, however to some extent this is inherently racey. What can happen is that there is a slight delay between the client receiving the full response and the connection being returned to the pool (there is nothing that can be done about this, it is impossible to atomically send the last content and return the thread in one action). I would try calling setMaxQueueSize and add a small queue (say 20) which should resolve the issue. If not then this is definitely a bug. Stuart On Thu, Feb 14, 2019 at 1:53 AM Carter Kozak > wrote: When the connections-per-thread limit is reached, requests result in 503 responses. Is the problem resolved by increasing the connections-per-thread value to 50 or 100? On Wed, Feb 13, 2019, at 04:42, Jocke Eriksson wrote: Hello, We are trying to build an API gateway using undertow as a servlet extension, this has been working great until we started our performance tests. Our setup is two gateways balancing traffic towards 10+ servers and we are using JBoss EAP 7.0 We have observed that some of our requests fail with 503 response. When we get a 503 response from a request, we have also observed that it never reaches the proxy target. I made a small test on my machine to see if I could get the same error, to my surprise this was very easy. First I tried with the following code. public class ApiGatewayServletExtension implements ServletExtension { @Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { LOG.info("Deploying {}...", MethodHandles.lookup().lookupClass().getSimpleName()); deploymentInfo.addInitialHandlerChainWrapper(handler -> { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); return new ProxyHandler(loadBalancer, 30000, handler); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); } }); } } I used JMeter with 20 threads making a simple rest GET request and after 30 seconds or so the test stopped with a 503 response. Then I created a small java application using undertow 2.0.17.Final like this. public static void main(final String[] args) { try { LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient() .addHost(new URI("http://localhost:8282")) .setConnectionsPerThread(20); ProxyHandler proxyHandler = new ProxyHandler(loadBalancer, 30000, ResponseCodeHandler.HANDLE_404); Undertow server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(proxyHandler).build(); server.start(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } Getting the same result. I have also tried just loading the home page of one of our servers and still the same result. Any help would be very much appreciated. I have not created a bug because I'm pretty sure we are just missing something here. Regards Joakim Eriksson. _______________________________________________ undertow-dev mailing list undertow-dev at lists.jboss.org https://lists.jboss.org/mailman/listinfo/undertow-dev _______________________________________________ undertow-dev mailing list undertow-dev at lists.jboss.org https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190215/43fd1298/attachment-0001.html From prabhashrathore at gmail.com Mon Feb 18 13:47:36 2019 From: prabhashrathore at gmail.com (Prabhash Rathore) Date: Mon, 18 Feb 2019 18:47:36 +0000 (UTC) Subject: [undertow-dev] Undertow - Read/Write timeout References: <688421873.1102360.1550515656778.ref@mail.yahoo.com> Message-ID: <688421873.1102360.1550515656778@mail.yahoo.com> Hello, I am writing a Web Server using undertow. I am trying to set up read and write timeouts using below code but this does not work. I went? through undertow documentation but I didn't see any other way to set up timeout other that what I am trying? Undertow.Builder undertowBuilder = Undertow.builder(); undertowBuilder.addHttpListener(80, "localhost"); undertowBuilder.setServerOption(Options.WRITE_TIMEOUT, 10); undertowBuilder.setServerOption(Options.READ_TIMEOUT, 20); I also tried to set up using setSocketOptions and setWorkerOptions but that dididn't work either? As a side nots, I am not clear on the difference of these three options: ServerOptions, SocketOptions and WorkerOptions. Any help or pointers will be appreciated. Thanks!Prabhash Rathore -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190218/e5a89bbd/attachment.html From andrea at softinstigate.com Fri Feb 22 07:09:30 2019 From: andrea at softinstigate.com (Andrea Di Cesare) Date: Fri, 22 Feb 2019 13:09:30 +0100 Subject: [undertow-dev] How to modify the response with ProxyHandler Message-ID: Hi undertow-dev , I'm using ProxyHandler with LoadBalancingProxyClient and in some cases I need to modify the response content received from the backed before sending it to the client. HttpServerExchange.addResponseCommitListener() allows to modify the response and using it I'm able, for instance, to add a response header but not modifyng the content from the backend since it is not available. Is it possible? What are the suggested ways of implementing this behavior? Thanks, Andrea Di Cesare -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190222/ae19f5fe/attachment.html From sdouglas at redhat.com Fri Feb 22 07:25:08 2019 From: sdouglas at redhat.com (Stuart Douglas) Date: Fri, 22 Feb 2019 23:25:08 +1100 Subject: [undertow-dev] How to modify the response with ProxyHandler In-Reply-To: References: Message-ID: io.undertow.server.HttpServerExchange#addResponseWrapper lets you add a conduit that can modify the response. Stuart On Fri, Feb 22, 2019 at 11:13 PM Andrea Di Cesare wrote: > Hi undertow-dev , > > I'm using ProxyHandler with LoadBalancingProxyClient and in some cases I > need to modify the response content received from the backed before sending > it to the client. > > HttpServerExchange.addResponseCommitListener() allows to modify the > response and using it I'm able, for instance, to add a response header but > not modifyng the content from the backend since it is not available. > > Is it possible? What are the suggested ways of implementing this behavior? > > Thanks, > Andrea Di Cesare > > > _______________________________________________ > undertow-dev mailing list > undertow-dev at lists.jboss.org > https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190222/2bba9f6a/attachment.html From scrapmachines at gmail.com Tue Feb 26 05:10:44 2019 From: scrapmachines at gmail.com (Girish Sharma) Date: Tue, 26 Feb 2019 15:40:44 +0530 Subject: [undertow-dev] Async/Rx approach in HttpHandlers Message-ID: Hi, I have been trying to find some solid examples for using Observables/Callbacks/Futures to delegate long running tasks (which return the response to be sent back) over to separate threads. The idea is that the handler method simply spawns an async task and whenever that async tasks completes, we send back the response without making the handler method/worker threads wait for the async task to finish. Any pointers/examples would be appreciated. -- Girish Sharma -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190226/8b002470/attachment.html From bill at dartalley.com Tue Feb 26 07:20:18 2019 From: bill at dartalley.com (Bill O'Neil) Date: Tue, 26 Feb 2019 07:20:18 -0500 Subject: [undertow-dev] Async/Rx approach in HttpHandlers In-Reply-To: References: Message-ID: Take a look at the various dispatch methods on HttpServerExchange. They allow you to dispatch from the IO thread to the worker pool or to a custom executor. BlockingHandler is a convenience handler for dispatching to the worker thread pool. On Tue, Feb 26, 2019 at 5:13 AM Girish Sharma wrote: > Hi, > > I have been trying to find some solid examples for using > Observables/Callbacks/Futures to delegate long running tasks (which return > the response to be sent back) over to separate threads. The idea is that > the handler method simply spawns an async task and whenever that async > tasks completes, we send back the response without making the handler > method/worker threads wait for the async task to finish. > > Any pointers/examples would be appreciated. > -- > Girish Sharma > _______________________________________________ > undertow-dev mailing list > undertow-dev at lists.jboss.org > https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190226/2febedf5/attachment.html From scrapmachines at gmail.com Tue Feb 26 07:47:20 2019 From: scrapmachines at gmail.com (Girish Sharma) Date: Tue, 26 Feb 2019 18:17:20 +0530 Subject: [undertow-dev] Async/Rx approach in HttpHandlers In-Reply-To: References: Message-ID: I read through the code and did some other reading too. But while exploring on stackoverflow and such, I came upon this [0] question. I am now assuming that since author here did not mention a separate thread-pool, the worker thread pool was used up for the the sleep statement as well and thus his concern? More interesting however is the reply where the person who replied claims undertow is not meant for such cases and mentions his fork undertow-async [1]. Any thoughts around that? [0] https://stackoverflow.com/questions/47464828/undertown-async-responce-with-another-thread [1] https://github.com/hank-whu/undertow-async On Tue, Feb 26, 2019 at 5:50 PM Bill O'Neil wrote: > Take a look at the various dispatch methods on HttpServerExchange. They > allow you to dispatch from the IO thread to the worker pool or to a custom > executor. BlockingHandler is a convenience handler for dispatching to the > worker thread pool. > > On Tue, Feb 26, 2019 at 5:13 AM Girish Sharma > wrote: > >> Hi, >> >> I have been trying to find some solid examples for using >> Observables/Callbacks/Futures to delegate long running tasks (which return >> the response to be sent back) over to separate threads. The idea is that >> the handler method simply spawns an async task and whenever that async >> tasks completes, we send back the response without making the handler >> method/worker threads wait for the async task to finish. >> >> Any pointers/examples would be appreciated. >> -- >> Girish Sharma >> _______________________________________________ >> undertow-dev mailing list >> undertow-dev at lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/undertow-dev > > -- Girish Sharma B.Tech(H), Civil Engineering, Indian Institute of Technology, Kharagpur -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190226/1481615b/attachment-0001.html From ckozak at ckozak.net Tue Feb 26 08:03:04 2019 From: ckozak at ckozak.net (Carter Kozak) Date: Tue, 26 Feb 2019 08:03:04 -0500 Subject: [undertow-dev] Async/Rx approach in HttpHandlers In-Reply-To: References: Message-ID: <9ADBC5AA-961D-4D7B-BEAD-4C62C92E0512@ckozak.net> spring-webflux supports reactive types on undertow: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html It may be helpful to read their undertow handler implementation, or to use spring-webflux directly. -ck > On Feb 26, 2019, at 7:47 AM, Girish Sharma wrote: > > I read through the code and did some other reading too. But while exploring on stackoverflow and such, I came upon this [0] question. > I am now assuming that since author here did not mention a separate thread-pool, the worker thread pool was used up for the the sleep statement as well and thus his concern? > More interesting however is the reply where the person who replied claims undertow is not meant for such cases and mentions his fork undertow-async [1]. > > Any thoughts around that? > > [0] https://stackoverflow.com/questions/47464828/undertown-async-responce-with-another-thread > [1] https://github.com/hank-whu/undertow-async > >> On Tue, Feb 26, 2019 at 5:50 PM Bill O'Neil wrote: >> Take a look at the various dispatch methods on HttpServerExchange. They allow you to dispatch from the IO thread to the worker pool or to a custom executor. BlockingHandler is a convenience handler for dispatching to the worker thread pool. >> >>> On Tue, Feb 26, 2019 at 5:13 AM Girish Sharma wrote: >>> Hi, >>> >>> I have been trying to find some solid examples for using Observables/Callbacks/Futures to delegate long running tasks (which return the response to be sent back) over to separate threads. The idea is that the handler method simply spawns an async task and whenever that async tasks completes, we send back the response without making the handler method/worker threads wait for the async task to finish. >>> >>> Any pointers/examples would be appreciated. >>> -- >>> Girish Sharma >>> _______________________________________________ >>> undertow-dev mailing list >>> undertow-dev at lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/undertow-dev > > > -- > Girish Sharma > B.Tech(H), Civil Engineering, > Indian Institute of Technology, Kharagpur > _______________________________________________ > undertow-dev mailing list > undertow-dev at lists.jboss.org > https://lists.jboss.org/mailman/listinfo/undertow-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190226/7ce72eb7/attachment.html From bill at dartalley.com Tue Feb 26 08:14:23 2019 From: bill at dartalley.com (Bill O'Neil) Date: Tue, 26 Feb 2019 08:14:23 -0500 Subject: [undertow-dev] Async/Rx approach in HttpHandlers In-Reply-To: <9ADBC5AA-961D-4D7B-BEAD-4C62C92E0512@ckozak.net> References: <9ADBC5AA-961D-4D7B-BEAD-4C62C92E0512@ckozak.net> Message-ID: Is your goal to be async or non-blocking? If you want to be non-blocking then every method and library you use must also be non-blocking then you never need to dispatch to a separate worker pool and can stay on the IO threads the entire time. If you want it to be async then you can dispatch to worker threads to handle the blocking operations. A sleep operation is blocking so yes it will block a thread for its duration. That is also true with observables or any of the reactive frameworks. The defaults for the IO thread and worker thread can be found here . IO threads = min (# of CPU cores, 2) worker threads = IO threads * 8 On a 4 core server, you will have 32 worker threads for blocking operations. You can configure both of these pools to meet your needs. If you dispatch then sleep you will be blocking one of the 32 worker threads but the IO thread is free to accept requests. Any of the reactive frameworks or WebFlux type frameworks will handle this in the same way unless the underlying libraries are non-blocking. Most JDBC libraries (for now) are all blocking which means the only way to make it async is to run the query in a separate thread blocking that thread until the query returns. On Tue, Feb 26, 2019 at 8:03 AM Carter Kozak wrote: > spring-webflux supports reactive types on undertow: > https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html > > It may be helpful to read their undertow handler implementation, or to use > spring-webflux directly. > > -ck > > On Feb 26, 2019, at 7:47 AM, Girish Sharma > wrote: > > I read through the code and did some other reading too. But while > exploring on stackoverflow and such, I came upon this [0] question. > I am now assuming that since author here did not mention a separate > thread-pool, the worker thread pool was used up for the the sleep statement > as well and thus his concern? > More interesting however is the reply where the person who replied claims > undertow is not meant for such cases and mentions his fork undertow-async > [1]. > > Any thoughts around that? > > [0] > https://stackoverflow.com/questions/47464828/undertown-async-responce-with-another-thread > [1] https://github.com/hank-whu/undertow-async > > On Tue, Feb 26, 2019 at 5:50 PM Bill O'Neil wrote: > >> Take a look at the various dispatch methods on HttpServerExchange. They >> allow you to dispatch from the IO thread to the worker pool or to a custom >> executor. BlockingHandler is a convenience handler for dispatching to the >> worker thread pool. >> >> On Tue, Feb 26, 2019 at 5:13 AM Girish Sharma >> wrote: >> >>> Hi, >>> >>> I have been trying to find some solid examples for using >>> Observables/Callbacks/Futures to delegate long running tasks (which return >>> the response to be sent back) over to separate threads. The idea is that >>> the handler method simply spawns an async task and whenever that async >>> tasks completes, we send back the response without making the handler >>> method/worker threads wait for the async task to finish. >>> >>> Any pointers/examples would be appreciated. >>> -- >>> Girish Sharma >>> _______________________________________________ >>> undertow-dev mailing list >>> undertow-dev at lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/undertow-dev >> >> > > -- > Girish Sharma > B.Tech(H), Civil Engineering, > Indian Institute of Technology, Kharagpur > > _______________________________________________ > undertow-dev mailing list > undertow-dev at lists.jboss.org > https://lists.jboss.org/mailman/listinfo/undertow-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190226/75bc3ca9/attachment.html From andrea at softinstigate.com Thu Feb 28 08:20:49 2019 From: andrea at softinstigate.com (Andrea Di Cesare) Date: Thu, 28 Feb 2019 14:20:49 +0100 Subject: [undertow-dev] How to modify the response with ProxyHandler In-Reply-To: References: Message-ID: Thanks Stuart, this works very well. For future reference this is our implementation of the modifiable conduit https://github.com/SoftInstigate/uiam/blob/master/src/main/java/io/uiam/handlers/ModifiableContentSinkConduit.java We use it to modify both the request and the response for a proxied resource (via ProxyHandler and LoadBalancingProxyClient). In order to get the plain response to modify it without the need of decod it, we force the Accept-Encoding=identity before proxying it. However we are struggling encoding it according to the original Accept-Encoding after our ModifiableContentSinkConduit.terminateWrites() executes. We thought to set the Accept-Encoding back to its original value and use the EncodingHandler, however the fact that we overwrite the header seems to mess things. Do you have any suggestions? Thanks, Andrea Il giorno ven 22 feb 2019 alle ore 13:25 Stuart Douglas ha scritto: > io.undertow.server.HttpServerExchange#addResponseWrapper lets you add a > conduit that can modify the response. > > Stuart > > On Fri, Feb 22, 2019 at 11:13 PM Andrea Di Cesare < > andrea at softinstigate.com> wrote: > >> Hi undertow-dev , >> >> I'm using ProxyHandler with LoadBalancingProxyClient and in some cases I >> need to modify the response content received from the backed before sending >> it to the client. >> >> HttpServerExchange.addResponseCommitListener() allows to modify the >> response and using it I'm able, for instance, to add a response header but >> not modifyng the content from the backend since it is not available. >> >> Is it possible? What are the suggested ways of implementing this behavior? >> >> Thanks, >> Andrea Di Cesare >> >> >> _______________________________________________ >> undertow-dev mailing list >> undertow-dev at lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/undertow-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20190228/c05ce629/attachment-0001.html