[Java-2.5] WS: Don't wait for response

110 views
Skip to first unread message

Johan Dahlberg

unread,
Feb 16, 2017, 12:58:17 PM2/16/17
to Play Framework
Hi!

Is it possible to skip waiting for the response on a WS request. We send data to an external service but don't really need to wait and see the response. That request is more than half of our response time so it would be nice to rather respond to our clients directly after sending that data. Is that possible to do?

/Johan

Will Sargent

unread,
Feb 16, 2017, 2:32:16 PM2/16/17
to play-fr...@googlegroups.com
How are you waiting for the response?  Play WS is built on AsyncHttpClient, so there shouldn't be any waiting involved -- if you don't want to process the response, you can call .get() and the request will happen on another thread.

--
Will Sargent
Engineer, Lightbend, Inc.


--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/7da75a23-14d7-49ec-abc6-05fb5cb2c4fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johan Dahlberg

unread,
Feb 16, 2017, 2:43:54 PM2/16/17
to play-fr...@googlegroups.com
Sorry, I was overthinking this. Obviously, it's as simple as you describe.
Thank you for making my "internal failure" a lot shorter. :P

/Johan

tors 16 feb. 2017 kl 20:32 skrev Will Sargent <will.s...@lightbend.com>:
How are you waiting for the response?  Play WS is built on AsyncHttpClient, so there shouldn't be any waiting involved -- if you don't want to process the response, you can call .get() and the request will happen on another thread.

--
Will Sargent
Engineer, Lightbend, Inc.


On Thu, Feb 16, 2017 at 9:58 AM, Johan Dahlberg <jo...@dahlberg.co> wrote:
Hi!

Is it possible to skip waiting for the response on a WS request. We send data to an external service but don't really need to wait and see the response. That request is more than half of our response time so it would be nice to rather respond to our clients directly after sending that data. Is that possible to do?

/Johan

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Play Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/sMk9KLgxoPI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/CAJmgB61hbRO_tRq-nupSYyKozqRbHg8%3D569zxvg%3Dy7XEEP5hvg%40mail.gmail.com.

Johan Dahlberg

unread,
Feb 20, 2017, 6:39:32 AM2/20/17
to Play Framework
It looks like it wasn't as simple as I thought. Now my code looks like this:

CompletionStage<WSResponse> response = ws.url(url).setContentType("application/json").post(rootNode);

This code takes over 5 seconds to run. If I don't do anything with the response shouldn't this be very fast?

/Johan


Den torsdag 16 februari 2017 kl. 20:43:54 UTC+1 skrev Johan Dahlberg:
Sorry, I was overthinking this. Obviously, it's as simple as you describe.
Thank you for making my "internal failure" a lot shorter. :P

/Johan

tors 16 feb. 2017 kl 20:32 skrev Will Sargent <will.s...@lightbend.com>:
How are you waiting for the response?  Play WS is built on AsyncHttpClient, so there shouldn't be any waiting involved -- if you don't want to process the response, you can call .get() and the request will happen on another thread.

--
Will Sargent
Engineer, Lightbend, Inc.


On Thu, Feb 16, 2017 at 9:58 AM, Johan Dahlberg <jo...@dahlberg.co> wrote:
Hi!

Is it possible to skip waiting for the response on a WS request. We send data to an external service but don't really need to wait and see the response. That request is more than half of our response time so it would be nice to rather respond to our clients directly after sending that data. Is that possible to do?

/Johan

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Play Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/sMk9KLgxoPI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framework+unsubscribe@googlegroups.com.

Patrick Li

unread,
Feb 23, 2017, 8:23:52 PM2/23/17
to Play Framework
That line should not take 5 seconds to run, as it is only returning a CompletionStage and not the real response from the remote service, it should go onto the next line of code immediately rather than waiting on it. 

How are you getting the 5 seconds? By doing something like System current time right before and after? Is it really blocking for 5 seconds? As it really shouldn't.


On Monday, February 20, 2017 at 3:39:32 AM UTC-8, Johan Dahlberg wrote:
It looks like it wasn't as simple as I thought. Now my code looks like this:

CompletionStage<WSResponse> response = ws.url(url).setContentType("application/json").post(rootNode);

This code takes over 5 seconds to run. If I don't do anything with the response shouldn't this be very fast?

/Johan

Den torsdag 16 februari 2017 kl. 20:43:54 UTC+1 skrev Johan Dahlberg:
Sorry, I was overthinking this. Obviously, it's as simple as you describe.
Thank you for making my "internal failure" a lot shorter. :P

/Johan

tors 16 feb. 2017 kl 20:32 skrev Will Sargent <will.s...@lightbend.com>:
How are you waiting for the response?  Play WS is built on AsyncHttpClient, so there shouldn't be any waiting involved -- if you don't want to process the response, you can call .get() and the request will happen on another thread.

--
Will Sargent
Engineer, Lightbend, Inc.


On Thu, Feb 16, 2017 at 9:58 AM, Johan Dahlberg <jo...@dahlberg.co> wrote:
Hi!

Is it possible to skip waiting for the response on a WS request. We send data to an external service but don't really need to wait and see the response. That request is more than half of our response time so it would be nice to rather respond to our clients directly after sending that data. Is that possible to do?

/Johan

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Play Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/sMk9KLgxoPI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.

Johan Dahlberg

unread,
Feb 24, 2017, 5:53:27 AM2/24/17
to Play Framework
We use New Relic for tracing performance. But if this should be fast maybe New Relic does something wrong then.

/Johan

Patrick Li

unread,
Feb 24, 2017, 1:52:28 PM2/24/17
to Play Framework
Yeah.... not sure how New Relic traces async processes. We use New Relic ourselves, and the data shown is not as clear as normal threaded frameworks like Spring MVC, it can be a little convoluted or misleading at times.

If you want, you can either print out a timestamp before and after your remote call and compare the output. It should be a matter of milliseconds (or less) as WS would simply fire off the request and move on to the next line of code immediately without waiting or caring for the response (which you need to map if you want to know what the response is). Or step through the code in your debugger, and you should see the thread not blocking and waiting for the response, as opposed to traditional URLConnection or HttpClient, which would block and wait until the response is received.

Greg Methvin

unread,
Feb 24, 2017, 4:35:05 PM2/24/17
to play-framework
It's certainly possible that the HTTP request itself takes 5 seconds, depending on what you are requesting. Maybe New Relic is referring to the time taken to complete the CompletionStage?

To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/99225e3d-8d11-45d1-8082-f9b6b1c8b3b5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Tech Lead - Play Framework

Igmar Palsenberg

unread,
Feb 27, 2017, 9:48:38 AM2/27/17
to Play Framework
 
Yeah.... not sure how New Relic traces async processes. We use New Relic ourselves, and the data shown is not as clear as normal threaded frameworks like Spring MVC, it can be a little convoluted or misleading at times.

They bytecode enhance the controller method matching a certain pattern. We used to be a New Relic customer, but I basically refuse to pay for a production that takes > 3 months to support a new major version of a framework.

We internally switched to Kamon, which provides similar functionality, bu is open source : If I want something, I can fix it myself / hire someone to do it.

To track performance issues, we internally use Yourkit probes a lot, which gives us method duration of the function I'm interested in. Not suitable for (semi) production usage however.


Igmar
Reply all
Reply to author
Forward
0 new messages