Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-blocking I/O support #361

Open
rstml opened this issue Mar 16, 2016 · 60 comments
Open

Non-blocking I/O support #361

rstml opened this issue Mar 16, 2016 · 60 comments
Labels
enhancement For recommending new capabilities feign-12 Issues that are related to the next major release proposal Proposed Specification or API change

Comments

@rstml
Copy link

rstml commented Mar 16, 2016

As per our discussion with @adriancole in #24 , it would be good to add non-blocking I/O support to Feign.

This can be particularly beneficial for the scenarios with API gateways or microservice API composition.

@yairogen
Copy link

I would also like to see this supported.

@shimib
Copy link

shimib commented Jul 17, 2016

+1

2 similar comments
@igreenfield
Copy link

+1

@bahirsch
Copy link

+1

@codefromthecrypt
Copy link
Contributor

can someone in favor of this describe the api they wish to be non-blocking? or is it simply that they want the buffered http request that's invoked synchronously, to use a non-blocking library underneath?

@igreenfield
Copy link

First we want to use lib that use nio as underlying implementation.

in manner of async API I would like to pass to the feign a callback that will handle the response. in this case the API will return void.

@codefromthecrypt
Copy link
Contributor

codefromthecrypt commented Jul 18, 2016 via email

@yairogen
Copy link

What do you mean by "which is what feign isn't designed for"?

@codefromthecrypt
Copy link
Contributor

What do you mean by "which is what feign isn't designed for"?

Feign's is not designed for asynchronous invocation or zero-copy i/o.

For example, requests are buffered up-front, and all i/o operations are
blocking.
Core concepts such as interceptors and exception handlers were not designed
for asynchronous invocation.
The Client interface (required by all http backends) is a synchronous api.
Internal dispatch assumes synchronous apis, as well many try/catch blocks
associated with it.
RetryHandler assumes synchronous invocation

I could go on, but there are a lot of internals that are simpler because
synchronous is assumed. When someone changes the invocation model, they
must break api or certain things won't work. Also, depending on what's
desired
from nio, the contents of requests and responses may also need to be
changed.

Hope this helps.

ps the associated issues are #24 #25 #220 as well as others that were
closed dupe (as this probably should as it highly overlaps with #24)

@yairogen
Copy link

got it. don't think I can commit to so much work at the moment.

@daniellavoie
Copy link

Hi !

I understand Feign has not been designed with non blocking in mind. Maybe a new project is a better target. I would suggest using reactive stream as a standard way to handle IO events. First I am wondering if there is any proper reactive lightweight HTTP client out there.

@codefromthecrypt
Copy link
Contributor

probably want to collaborate on https://github.com/OpenFeign/feign-vertx
for starters

On Sat, Sep 3, 2016 at 3:24 PM, Daniel Lavoie [email protected]
wrote:

Hi !

I understand Feign has not been designed with non blocking in mind. Maybe
a new project is a better target. I would suggest using reactive stream as
a standard way to handle IO events. First I am wondering if there is any
proper reactive lightweight HTTP client out there.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#361 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAD61xREV5wavu_C1_M4X4DIEQp7-O2Vks5qmSDDgaJpZM4Hx9G3
.

@daniellavoie
Copy link

Thanks @adriancole sounds interesting. I'll check it out.

@phymbert
Copy link
Contributor

phymbert commented Aug 21, 2017

Hello,
I submitted a new feature to support java8 streams, it will allow to handle response body asynchronously or without waiting for the full body before to process.

Although request support IO is still blocking, response input stream handling can take benefits of java8 streams.
Please vote in #586 if it solves your issue.

@shenliuyang
Copy link

+1

6 similar comments
@beihaifeiwu
Copy link

+1

@maheshmahadevan
Copy link

+1

@oldprofile
Copy link

+1

@SerJey
Copy link

SerJey commented Oct 23, 2017

+1

@iischwuerfl
Copy link

+1

@paskos
Copy link

paskos commented Oct 23, 2017

+1

@spencergibb
Copy link
Contributor

Please stop +1 in comments and use the 'Add your reaction' feature in the original description.

@dieppa
Copy link

dieppa commented Dec 19, 2017

+1

2 similar comments
@stv8
Copy link

stv8 commented Jan 26, 2018

+1

@dieppa
Copy link

dieppa commented Jan 29, 2018

+1

@Ged0
Copy link

Ged0 commented Feb 11, 2018

+1.
Our client always cost 6~10s to wait for response from a provider. It is impossible to shorten the waiting time.

@bluntviola
Copy link

+1

1 similar comment
@scarter93
Copy link

+1

@jmoney
Copy link

jmoney commented Feb 28, 2018

@adriancole - what are the versions of Java that OpenFeign supports? Could this not be completed by having the Client interface return CompletableFuture<Object>? Then based on the Contract and return type determined in the MethodHandler(It's called `SynchronousMethodHandler so probably needs a rename as part of this) unwraps the CompletableFuture or leaves it alone. Let me know if i'm going down the wrong track on that. I think that's the least invasive approach but is still breaking api compatibility and pins OpenFeign to jdk8+.

Alternative is to use callbacks i guess and detect them in the parameter list of the feign annotated interface and pass down to the Client. The CompletableFuture feels more clean.

@kdavisk6 kdavisk6 added the proposal Proposed Specification or API change label Aug 7, 2019
@tshah010-zz
Copy link

Hi, I am using spring-cloud-starter-openfeign 2.0.1 and I am trying to make several http API calls asynchronously using org.springframework.scheduling.annotation.EnableAsync and org.springframework.scheduling.annotation.Async on methods annotated with @FeignClient. But none of the methods run async.
Is it because @FeignClient is not allowing new threads to be spun up?
Alternatively, I tried using on CompletableFuture on my FeignClient method but method never returns completed.
What's the best way to make async calls when I am using spring-cloud-starter-openfeign? Thanks for your help.

@kdavisk6
Copy link
Member

@tshah010

Feign does not support async execution modes currently. You can't do this yet. It's on our road map.

@tshah010-zz
Copy link

@kdavisk6
thanks for quick response, but Feign documentation for Hystrix here - https://github.com/OpenFeign/feign/tree/master/hystrix clearly says we can use CompletableFuture. But my methods never complete with and without @async.
Is that what you mean by "does not support"? Thanks Kevin.

@kdavisk6
Copy link
Member

@tshah010

I mean that Feign has not been tested or built to support use within any async or non-blocking IO execution mode. The only fully-supported mode is blocking. The one note-able exception is Hystrix, however support is limited to use cases supported by Hystrix, such as using fallbacks and the HystrixFeign builders as the request management is delegated to Hystrix.

I'm afraid that's all I can offer you right now.

@kdavisk6 kdavisk6 added the feign-12 Issues that are related to the next major release label Dec 27, 2019
@motinis
Copy link
Contributor

motinis commented Feb 17, 2020

Please take a look at the the following pull request

@wangzihaogithub
Copy link

Does the current version work with CompleteableFuture?
I can't find a use case.

@motinis
Copy link
Contributor

motinis commented Sep 29, 2020 via email

@michalko
Copy link

michalko commented May 2, 2021

+1

@velo
Copy link
Member

velo commented May 2, 2021

Anyone willing to write a first draft for this?

@bob-bbb
Copy link

bob-bbb commented May 31, 2021

+1

1 similar comment
@icarodemorais
Copy link

+1

@velo
Copy link
Member

velo commented Feb 8, 2022

Yeah, still waiting on volunteers to either spear head this initiative or to fund it.

@wplong11
Copy link
Collaborator

@velo I worked on coroutine support(#1706) with minimal effort, and now I want to support full asynchronous features, and increase the stability level of AsyncFeign from Experimental to Stable. I'm not knowledgeable perfectly about Feign, but I've seen almost all of the internal implementations of Feign, FeignX, and ReactiveFegin, and I think I can try a few.

I plan to

  1. Refactor the internal implementation to support full asynchronous functionality while reusing most of the code.
  2. Add full asynchronous functionality
  3. Clean up AsyncFeign Api Design

@velo
Copy link
Member

velo commented Sep 13, 2022

@wplong11 feel free to reach me any time you find a blocker

@wplong11
Copy link
Collaborator

@velo Do you have any thoughts on what additional work must be done to increase the stability level of AsyncFeign from Experimental to Stable?

What I'm thinking of is:

  • Modify AsyncFeign.AsyncBuilder to extend Feign.Builder or Modify Feign to support the features of AsyncFeign
    • It is intended to be used when customizing Feign.Builder in Spring Cloud OpenFeign.
  • Modify CoroutineFeign.CoroutineBuilder to extend Feign.Builder

@wplong11
Copy link
Collaborator

wplong11 commented Oct 10, 2022

@velo @motinis Is the parameter Optional<C> requestContext important? I understand the intention(#1174), but are you actually using it? It is not being used by AsyncClient implementation.

CompletableFuture<Response> execute(Request request, Options options, Optional<C> requestContext);

I have some problem to integrating AsyncFeign and Feign.
It would be nice if Feign could support non-blocking asynchronous methods without AsyncFeign as well,
but it's not easy to make appropriate changes while keeping the parameters.
There's room for a little more thought, and I have something to explain more, but before that, I'd like to ask a quick question.

@kdavisk6
Copy link
Member

kdavisk6 commented Oct 10, 2022

It is possible to use CompleteableFuture in a blocking mode to achieve asynchronous and blocking support. Here's an example: https://github.com/OpenFeign/feignx/blob/main/core/src/main/java/feign/impl/AbstractTargetMethodHandler.java

However, for true non-blocking support, we'll need to move past CompleteableFuture and into the realm of Event Loops, like Netty, which is the most prominent form today. It's more than likely that Asynchronous, Blocking, and Non-Blocking are going to be different implementations entirely.

The idea of a Context provides information to the components executing in the processing chain that would normally be available on the same Thread in blocking scenarios. Without it, or something like it, the state of the processing chain will need to be managed elsewhere. The approach I use in feignx is start with a RequestSpecification and then move it into an immutable Request. This is very similar to how we do things today, where we start with a RequestTemplate and end with a Request. I think the key areas to deal with first are the mutability of RequestTemplate and the possible places where additional context is required.

@wplong11
Copy link
Collaborator

wplong11 commented Oct 11, 2022

@kdavisk6

we'll need to move past CompleteableFuture and into the realm of Event Loops

Does that mean we should discard using CompletableFuture approach, and then use Event Loops?

@motinis
Copy link
Contributor

motinis commented Oct 11, 2022 via email

@islom-kh
Copy link

islom-kh commented Dec 22, 2022

Hi. any news about non-blocking feign ? @motinis @rstml

@caleb-cushing0-kr
Copy link

another yearly what's going on here?

@velo
Copy link
Member

velo commented Dec 6, 2023

another yearly what's going on here?

Same as last year. Needs people to take charge and do it.

There was a massive effort by @motinis #1174 , wplong11 #1755 and many others https://github.com/OpenFeign/feign/pulls?q=async

Feel free to add your effort into this initiative. I will be here to review, request changes, merge and release.

@gromspys
Copy link
Contributor

gromspys commented Dec 7, 2023

There is already library feign-reactive with non-blocking I/O: https://github.com/PlaytikaOSS/feign-reactive

@DanielYWoo
Copy link

We probably don't need it anymore since the latest JDK 21 supports virtual threads, if it blocks, let it block.

@ducnbyu
Copy link

ducnbyu commented Jan 26, 2024

Is there anything wrong with this solution?

Async call of a FeignClient Springboot with CompletableFuture

It seems to be working for me

@DanielYWoo
Copy link

Is there anything wrong with this solution?

Async call of a FeignClient Springboot with CompletableFuture

It seems to be working for me

this is async flavor programming model from programmer's angle, it's not a non-blocking implementation like nio/aio to improve performance under heavy load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement For recommending new capabilities feign-12 Issues that are related to the next major release proposal Proposed Specification or API change
Projects
None yet
Development

No branches or pull requests