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(udf): support client side load balancer for UDF #15200

Merged
merged 5 commits into from
Feb 27, 2024

Conversation

KeXiangWang
Copy link
Contributor

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Support client side load balancer, which read IP list from DNS server and load balance requests to the IPs.

Background:

  • RW's UDF client use gRPC protocol to exchange data with UDF servers.
  • gRPC is based on HTTP2.0, requests of which reuse a single TCP connection.
  • L4 balancer make routing decisions based on information at the TCP or UDP level without understanding higher-level protocols, such as HTTP2.0.
  • L4 is commonly used in K8S environment.
  • If one RW client tries to connect a group of UDF servers behind an L4 balancer, only one server will be accessed.

#15138

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@KeXiangWang KeXiangWang requested a review from a team as a code owner February 23, 2024 02:00
@KeXiangWang KeXiangWang force-pushed the wkx/udf-client-side-lb branch from 386ede3 to d8cd658 Compare February 23, 2024 02:10
@KeXiangWang KeXiangWang linked an issue Feb 23, 2024 that may be closed by this pull request
@KeXiangWang KeXiangWang force-pushed the wkx/udf-client-side-lb branch from d8cd658 to 02b9b47 Compare February 23, 2024 03:49
@BugenZhao
Copy link
Member

May I ask whether there's any downside for always enabling the periodical service discovery? IIUC, if there's no loading balancing under the given domain name, it'll degrade to the normal case and everything should still work well.

@KeXiangWang
Copy link
Contributor Author

KeXiangWang commented Feb 23, 2024

if there's no loading balancing under the given domain name, it'll degrade to the normal case and everything should still work well.

Yes, it will degrade to normal case.

May I ask whether there's any downside for always enabling the periodical service discovery?

If there's a L7 load balancer behind, the client-side load balancing is redundant, which issues an extra thread to refresh the IP list and has some extra cost on routing requests.

@KeXiangWang KeXiangWang requested a review from arkbriar February 23, 2024 04:27
@BugenZhao
Copy link
Member

which issues an extra thread to refresh the IP list and has some extra cost on routing requests

I guess this is quite acceptable. Also IIUC, the interval for DNS lookup only impacts the responsiveness to the changes behind the L4 load balancer and does not hurt the functionality of loading balancing itself. Therefore, using a longer interval should also be fine.

@KeXiangWang KeXiangWang force-pushed the wkx/udf-client-side-lb branch from 02b9b47 to 6ec6823 Compare February 23, 2024 05:28
@KeXiangWang
Copy link
Contributor Author

Update to always enabling client-side LB. The DNS refresh interval is set to be 5 seconds.

Copy link
Contributor

@kwannoel kwannoel left a comment

Choose a reason for hiding this comment

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

Rest LGTM

Copy link
Contributor

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

LGTM!

src/expr/udf/src/external.rs Outdated Show resolved Hide resolved
pub fn connect_lazy(addr: &str) -> Result<Self> {
let conn = tonic::transport::Endpoint::new(addr.to_string())?
block_on(async { Self::connect_inner(addr, ResolutionStrategy::Lazy).await })
Copy link
Member

Choose a reason for hiding this comment

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

By inspecting the source, it appears that .channel() is actually synchronous. We may use .now_or_never().unwrap() on the future here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm will it be much higher cost to do block_on + await here? I prefer not to rely on internal implementations of library.

Copy link
Member

Choose a reason for hiding this comment

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

futures::executor::block_on is fragile as well. If the future implementation leverages I/O capabilities of tokio inside, it will also panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to .now_or_never().unwrap()

src/expr/udf/src/external.rs Outdated Show resolved Hide resolved
src/expr/udf/src/external.rs Outdated Show resolved Hide resolved
src/expr/udf/src/external.rs Outdated Show resolved Hide resolved
src/expr/udf/src/external.rs Outdated Show resolved Hide resolved
src/expr/udf/src/external.rs Outdated Show resolved Hide resolved
src/expr/udf/src/external.rs Show resolved Hide resolved
@KeXiangWang KeXiangWang force-pushed the wkx/udf-client-side-lb branch 2 times, most recently from 9366d56 to b30d061 Compare February 26, 2024 20:40
@KeXiangWang KeXiangWang force-pushed the wkx/udf-client-side-lb branch from bb38a4c to e6a574c Compare February 27, 2024 03:12
Copy link
Contributor

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

LGTM!

@KeXiangWang KeXiangWang added this pull request to the merge queue Feb 27, 2024
Merged via the queue into main with commit 1ab3fdd Feb 27, 2024
27 of 28 checks passed
@KeXiangWang KeXiangWang deleted the wkx/udf-client-side-lb branch February 27, 2024 05:17
KeXiangWang added a commit that referenced this pull request Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support client-side Load Balancer for external UDF service
5 participants