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

feat: separate and optimize async and sync clients #4116

Merged
merged 10 commits into from Oct 12, 2023

Conversation

judahrand
Copy link
Contributor

@judahrand judahrand commented Aug 11, 2023

What does this PR address?

A draft attempt at addressing #4115

Currently, this introduces a lot of duplicate code. However, I think it should be possible to reduce this significantly.

I believe by having separate sync and async implementations optimal performance can be achieved for both.

I'd be interested to get thoughts and feedback on this PR as well as advice on how to benchmark it against main as I believe it should see some performance benefit across multiple requests on the same client.

Fixes #(issue)

Before submitting:

@judahrand judahrand requested a review from a team as a code owner August 11, 2023 11:57
@judahrand judahrand requested review from sauyon and removed request for a team August 11, 2023 11:57
@judahrand judahrand marked this pull request as draft August 11, 2023 11:57
@judahrand judahrand force-pushed the client-attempt-2 branch 3 times, most recently from c14b693 to 46e8dd5 Compare August 11, 2023 12:07
Copy link
Contributor

@sauyon sauyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backwards compatibility, the client implementations will have to retain the sync/async methods; perhaps the default client could instantiate a sync / async client?

@judahrand
Copy link
Contributor Author

judahrand commented Aug 15, 2023

For backwards compatibility, the client implementations will have to retain the sync/async methods; perhaps the default client could instantiate a sync / async client?

@sauyon The latest changes should maintain backwards compatibility. Is this sort of a solution acceptable? If so I'll push forwards with getting the tests passing and perhaps also look at splitting the tests up by sync and async implementation.

@judahrand judahrand force-pushed the client-attempt-2 branch 2 times, most recently from 45c29c8 to e916f29 Compare August 15, 2023 10:44
@judahrand judahrand requested a review from aarnphm August 16, 2023 14:00
@judahrand judahrand force-pushed the client-attempt-2 branch 2 times, most recently from 5077691 to 5b3eefa Compare August 16, 2023 14:29
@judahrand
Copy link
Contributor Author

I think that this PR has gotten a bit muddled. This is something which I am keen to address as at the moment I think the client implementations are quite poor. However, I may take another stab at this later understanding more about all the various moving parts.

There seems to be a lot which needs changes to:

  • make the synchronous clients work reliably and efficiently
  • make the async clients work efficiently
  • separate the client implementation from the core BentoML package to avoid carrying huge numbers of irrelevant dependencies around in client side software.

Copy link
Contributor

@sauyon sauyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things that I think need changing. Haven't reviewed the async client code entirely carefully yet.

@aarnphm can you help review the grpc client?

src/bentoml/_internal/client/__init__.py Outdated Show resolved Hide resolved
src/bentoml/_internal/client/__init__.py Show resolved Hide resolved
src/bentoml/_internal/client/__init__.py Show resolved Hide resolved
src/bentoml/_internal/client/http.py Outdated Show resolved Hide resolved
src/bentoml/_internal/io_descriptors/base.py Outdated Show resolved Hide resolved
@sauyon
Copy link
Contributor

sauyon commented Aug 18, 2023

I think that this PR has gotten a bit muddled. This is something which I am keen to address as at the moment I think the client implementations are quite poor. However, I may take another stab at this later understanding more about all the various moving parts.

I think apart from the IO descriptor change we should get this in, then probably circle back after we rework those.

There seems to be a lot which needs changes to:

  • make the synchronous clients work reliably and efficiently
  • make the async clients work efficiently

Yep.

Somewhat related, there was at one point an issue where connections were being dropped and we were running into strange errors when we reused a connection which we haven't gotten to the bottom of, which I probably could have added a comment for, but we really need to figure that out.

  • separate the client implementation from the core BentoML package to avoid carrying huge numbers of irrelevant dependencies around in client side software.

We probably need to think more carefully about this one in general; a lot of our dependencies are only required for servers / only required for clients, etc. @parano @bojiang something to think about, I think.

@aarnphm
Copy link
Member

aarnphm commented Aug 18, 2023

FWIW I think we can separate out a bentoml-client package, and by default bentoml will include bentoml-client

@judahrand
Copy link
Contributor Author

FWIW I think we can separate out a bentoml-client package, and by default bentoml will include bentoml-client

Agreed. I also wonder if the serialization/deserialization logic should live in a separate package (given that both the client and server will want to depend on it). This is something a lot of Rust projects do very very well (see arrow-rs). They split out all their subcomponents into sub crates.

I believe PDM might even be able to cope with this setup in Python? https://pdm.fming.dev/latest/usage/advanced/#use-pdm-to-manage-a-monorepo

@aarnphm
Copy link
Member

aarnphm commented Aug 18, 2023

FWIW I think we can separate out a bentoml-client package, and by default bentoml will include bentoml-client

Agreed. I also wonder if the serialization/deserialization logic should live in a separate package (given that both the client and server will want to depend on it). This is something a lot of Rust projects do very very well (see arrow-rs). They split out all their subcomponents into sub crates.

I believe PDM might even be able to cope with this setup in Python? pdm.fming.dev/latest/usage/advanced/#use-pdm-to-manage-a-monorepo

this will be added to bentoml-core 🎉

@aarnphm
Copy link
Member

aarnphm commented Aug 18, 2023

@ssheng do you think it is good to refactor our repo into monorepo architecture now?

Maybe good to also separate SDK and CLI as well as client

We might also want to think about bentoml-core development 🤔

@sauyon
Copy link
Contributor

sauyon commented Aug 18, 2023

I don't know that it needs to be a monorepo.

@sauyon
Copy link
Contributor

sauyon commented Aug 29, 2023

Would it be ok if I took this one over so we can get it in while we work on the rework?

@judahrand
Copy link
Contributor Author

Would it be ok if I took this one over so we can get it in while we work on the rework?

100% - sorry for letting this one lag. Various demands on time etc etc etc - same as everyone else 🤣

Copy link
Contributor

@frostming frostming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am mostly fine with it.

src/bentoml/_internal/client/__init__.py Outdated Show resolved Hide resolved
src/bentoml/_internal/client/http.py Outdated Show resolved Hide resolved
@sauyon
Copy link
Contributor

sauyon commented Oct 10, 2023

@aarnphm @frostming should be ready for another look!

aarnphm
aarnphm previously approved these changes Oct 12, 2023
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
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.

None yet

6 participants