Implement promises via CompletableFuture#202
Implement promises via CompletableFuture#202akhahaha wants to merge 0 commit intographql-java:masterfrom akhahaha:master
Conversation
|
Hello @akhahaha nice work, I think its better to return CompletionStage rather than CompletableFuture, since CompletableFuture is an implemention of CompletionStage, like its done in Akka and PlayFramework which use this Interface extensively for asyncronous operatio 8000 ns. Thanks. |
|
Hi @oexza. Can you please provide your thoughts regarding #37 (comment) and on? |
|
@oexza in fact I like the syntax of |
|
@oexza @hepin1989 Lol damn, well I just changed it to CompletionStage, but I can always revert it. What are the pros and cons? |
|
I think this makes sense to do as a sub project, if anyone would like to do that. |
|
What would that entail specifically? |
|
@akhahaha I'm not sure! I would like to explore concrete use-cases. For example, @pcarrier wrote the other day
I'd like see a code sample that shows this usage, so we can figure out how it might be targeted. If you're trying to get each field (and ultimately a whole query) resolved on an event loop, then those tasks need to somehow get on to that event loop. An appropriate execution strategy needs to somehow take this in to account. I've been Googling around for some pure Java examples of async request processing. Some things I've found:
I've not explored Netty and am hoping @pcarrier will provide his use-case. http://www.nurkiewicz.com/2015/11/which-thread-executes.html |
|
@dminkovsky It sounds like @pcarrier might be having similar "issues" from what we discussed in #37. Have you shown him that thread and perhaps this PR? To reiterate, to accomplish the async functionality that I think and he and I were looking for, simply use blocking DataFetchers and then perform the serial execution using the ExecutorService strategy on another thread using an async wrapper of your choice. Each DataFetcher will then resolve in parallel, and the async wrapper should return when all have been resolved. It's not intuitively async like we'd expect, but the result should be equivalent. I guess it does beg the discussion again of whether or not async functionality like this should be built-in by default. |
|
@akhahaha thanks for you response.
I @-tagged him in my post above, and just in case just highlighted him in the Gitter chat with a link here.
Yeah, that seems to be the Java/JVM way. But for some reason this topic keeps coming back up, in issues and in the Gitter chat. People seem to want to minimize blocking and context switching. My Google searching suggested that this approach might not actually yield performance gains, but this has come up time and time again. I personally like the simple code style that comes with blocking threads, and appreciate that Dropwizard claims 30-50k reqs/seq with a default 1024-count thread pool. Then again, maybe people can achieve even more on a tight event loop?
I think so too. But given the repeated interest I think I closed this PR too hastily. I would like to keep this main project on Java 1.6 to facilitate "legacy" users experimenting with GraphQL on Java. But at the same time perhaps a motivated, interested party will be interested in doing a sub-project. |
|
async is for not blocking on IO,not for speed. |
|
I'm reworking this |
|
Hi Alan, Cool, sounds good. In terms of getting this incorporated into this project or built out as a On Thu, Sep 22, 2016 at 1:11 AM, Alan Kha notifications@github.com wrote:
|
|
I think I'm onto a fairly simple solution right now. I've extended Users can then return their data in a promise using I think there should also be Unlike my previous implementation, this method should not require changing any other part of the library. I'd recommend this be placed into a subproject/module (requiring current graphql-java to be moved into a "core" module). It shouldn't be too hard to maintain this plugin alongside the main project. Thoughts? |
|
@akhahaha that is pretty interesting. I thought about this yesterday and here are my thoughts:
I was thinking this could be a subproject and therefore just simply target 1.8. I think the async/non-blocking crowd is all using 1.8.
I'm not sure what to say about this because I don't know how this would integrate with the bigger picture for people who are doing async/non-blocking request handling already. These users already have a way they're handling concurrency, and I suspect they want this to integrate nicely with the way of handling concurrency. Take for example the RxJava README. There they mention as one of its features:
I wonder how they do this... If we have a slew of So, with all that said, I am not sure how to proceed. It's almost like there's no generic solution to be had? I want to further study the Servlet 3.0 asynchronous handling API and Netty. I think an answer, if there is one, might be found somewhere around there. Please let me know if any of this is unclear or needs more elaboration. Thank you. PS. Please see also 8 Asynchronous & Non Blocking |
I think my proposed solution is in fact non-opinionated about the source of concurrency. From what I can tell, both Some sort of ExecutorService is necessary to achieve the same functionality like we discussed. I agree that it does seem undesirable, but the other alternative is to follow the guidelines listed in your Ratpack link, namely:
Incidentally, I believe this is how my original PR worked, by creating a pipeline of |
Related to Asynchronous DataFetcher request (#37)
Massive change that deprecates nearly all key interfaces and moves the SDK requirement to 1.8. Should be considered for a 3.0.0 release.
Error handling and propagation was a little tricky and could probably use some refinement by someone more talented than I, but all tests seem to pass.
Special thanks to @hepin1989 for his input on using CompletableFutures.