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

APISIX-38 Allow async plugins #313

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

chibenwa
Copy link

@chibenwa chibenwa commented Dec 18, 2024

Please answer these questions before submitting a pull request

  • Why submit this pull request?

  • Bugfix (for crazy dudes like I who wants Apisix to run run Redis queries... Blocking the event loop IS a bug. In user code but that's a major source of bugs!)

  • New feature provided

  • Improve performance (for crazy dudes like I who wants Apisix to run run Redis queries...)

  • Related issues https://issues.apache.org/jira/projects/APISIX/issues/APISIX-38


Bugfix

CF #264

The lack of asyn support in this plugin is a major showstopper for doing anything complex.

Turns out I need to call a Redis DBs as part of an OIDC logout workflow cf

And I need to avoid blocking on the event loop. The current semantic do not allow for this!

CF my first try in linagora/tmail-backend#1412


New feature or improvement

It turns out that callback based APIs are trivial to adapt to asynchronous code.

What we just need is wrap the "write to the client" stuff in the callback. We thus implement the write as a terminal filter. Which gives asynchrony capability for free.

Possible drawbacks:

  • To be noted that the write is likely to happen outside of the event loop, if the user explicitly switched thread. This can have non trivial consequences on the ordering. If that's an issue writes can be forced back to the event loop and be wrapped as an event loop task. Impacts only users that opt-in the async calls though...
  • This means that if client calls the next plugin in an async way we might have an unbounded number of async calls in flight. (Classic async code drawback: your concurrency no longer is bounded by your threadpool...) Impacts only users that opt-in the async calls though... And user that oped in are likely to know what they are doing.
  • The extra plugin array copy. Likely neglictible, and likely movable upon A6Conf initialization but it would be slightly more invasive onto the existing code base...

Next step

  • We will qualify the async plugin strategy in a real world scenario
  • Document how to write an async plugin (example)
  • Document better the trading model (everything runs onto the Netty event loop listening the UNIX socket, DON"T BLOCK)
  • Happy to write tests if needed. Am I authorized to add something like reactor as a test dependency in order to ease writing tests? Which testing strategy would be best suited to qualify the change?

@chibenwa
Copy link
Author

Test failure seems unrelated to my code

image

@membphis
Copy link
Member

thx for your contribution, nice job

welcome to review and leave comments if you are good at Java
I am not familiar this language, need community's help

@chibenwa
Copy link
Author

welcome to review and leave comments if you are good at Java

I think I have a decent level, so I could get a shot at it.

Question is more about the time though ;)

@chibenwa
Copy link
Author

chibenwa commented Jan 2, 2025

Hello all,
First happy new year
Second here are the perf results for My workload: linagora/tmail-backend#1412 (comment)

TL;DR

1/ Small gains on regular operations (5% mean time AND 7.6 % P99)
2/ Massive gains in term of ourage (x15 mean time AND x50 P99)

@hungphan227
Copy link

hungphan227 commented Jan 7, 2025

@chibenwa should this PR be ready (not draft)?

@chibenwa chibenwa marked this pull request as ready for review January 7, 2025 08:18
@chibenwa
Copy link
Author

Hello Apisix community,

Any update about this?

@membphis
Copy link
Member

E2E test case failed

pls fix them at first

@chibenwa
Copy link
Author

/home/runner/work/_temp/561d5117-b2a0-484e-90f4-8fc8f51c96e2.sh: line 1: docker-compose: command not found

Please point me to a doc telling how to run them locally because as explained in my email, and above in the PR the CI environment is broken.

I did run locally mvn clean install. Isn't this enough?

@chibenwa
Copy link
Author

Personal bet:

The piece of code is so old that we might actually just need to docker-compose => docker compose

Though I failed at locating cCI scripts in the ci folder nor in the e2e folder

@chibenwa
Copy link
Author

The docker worklow needs to be edited:

https://github.com/apache/apisix-java-plugin-runner/actions/runs/12392272043/workflow

I cannot do this within the scope of the PR, admin rights on the repo are needed to do so.

@membphis can you get a shot at this?

@membphis
Copy link
Member

The docker worklow needs to be edited:

https://github.com/apache/apisix-java-plugin-runner/actions/runs/12392272043/workflow

I cannot do this within the scope of the PR, admin rights on the repo are needed to do so.

@membphis can you get a shot at this?

you can send me the patch, then I will help you to submit the PR

thx

@chibenwa
Copy link
Author

I found this file location ^^

And the bet was correct.

I'll write an example and a bit of doc.

@chibenwa
Copy link
Author

@membphis I think this could be merged...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants