-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Support for RateLimiter in Beam Remote Model Handler #37218
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
Open
tarun-google
wants to merge
23
commits into
apache:master
Choose a base branch
from
tarun-google:remote_rt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−6
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
26f23ca
Support for EnvoyRateLimiter in Apache Beam
tarun-google 92fd0cd
fix format issues
tarun-google c3ef5a4
fix test formatting
tarun-google 5369f42
Fix test and syntax
tarun-google 4967fe7
fix lint
tarun-google 6868614
Add dependency based on python version
tarun-google a42a97d
revert setup to separete pr
tarun-google 7cbba0f
Merge branch 'apache:master' into beam_envoy_rate_limiter
tarun-google fa30212
fix lint
tarun-google a548fef
fix formatting
tarun-google c71edca
resolve comments
tarun-google 167d484
Support Ratelimiter through RemoteModelHandler
tarun-google 8239ccb
fix lint
tarun-google 1f23f7f
fix lint
tarun-google 84d2457
Merge branch 'master' of github.com:tarun-google/beam into remote_rt
tarun-google c1cf403
backmerge master
tarun-google 058bf43
fix comments
tarun-google 7d50f60
Add custom RateLimited Exception
tarun-google 1756bef
fix doc
tarun-google 6ee520a
Merge branch 'apache:master' into remote_rt
tarun-google f1fa3e6
fix test
tarun-google d5cdbfd
Merge branch 'remote_rt' of github.com:tarun-google/beam into remote_rt
tarun-google 2c82420
fix lint
tarun-google File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
sdks/python/apache_beam/examples/inference/rate_limiter_vertex_ai.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| """A simple example demonstrating usage of the EnvoyRateLimiter with Vertex AI. | ||
| """ | ||
|
|
||
| import argparse | ||
| import logging | ||
|
|
||
| import apache_beam as beam | ||
| from apache_beam.io.components.rate_limiter import EnvoyRateLimiter | ||
| from apache_beam.ml.inference.base import RunInference | ||
| from apache_beam.ml.inference.vertex_ai_inference import VertexAIModelHandlerJSON | ||
| from apache_beam.options.pipeline_options import PipelineOptions | ||
| from apache_beam.options.pipeline_options import SetupOptions | ||
|
|
||
|
|
||
| def run(argv=None): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| '--project', | ||
| dest='project', | ||
| help='The Google Cloud project ID for Vertex AI.') | ||
| parser.add_argument( | ||
| '--location', | ||
| dest='location', | ||
| help='The Google Cloud location (e.g. us-central1) for Vertex AI.') | ||
| parser.add_argument( | ||
| '--endpoint_id', | ||
| dest='endpoint_id', | ||
| help='The ID of the Vertex AI endpoint.') | ||
| parser.add_argument( | ||
| '--rls_address', | ||
| dest='rls_address', | ||
| help='The address of the Envoy Rate Limit Service (e.g. localhost:8081).') | ||
|
|
||
| known_args, pipeline_args = parser.parse_known_args(argv) | ||
| pipeline_options = PipelineOptions(pipeline_args) | ||
| pipeline_options.view_as(SetupOptions).save_main_session = True | ||
|
|
||
| # Initialize the EnvoyRateLimiter | ||
| rate_limiter = EnvoyRateLimiter( | ||
| service_address=known_args.rls_address, | ||
| domain="mongo_cps", | ||
| descriptors=[{ | ||
| "database": "users" | ||
| }], | ||
| namespace='example_pipeline') | ||
|
|
||
| # Initialize the VertexAIModelHandler with the rate limiter | ||
| model_handler = VertexAIModelHandlerJSON( | ||
| endpoint_id=known_args.endpoint_id, | ||
| project=known_args.project, | ||
| location=known_args.location, | ||
| rate_limiter=rate_limiter) | ||
|
|
||
| # Input features for the model | ||
| features = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0], | ||
| [10.0, 11.0, 12.0], [13.0, 14.0, 15.0]] | ||
|
|
||
| with beam.Pipeline(options=pipeline_options) as p: | ||
| _ = ( | ||
| p | ||
| | 'CreateInputs' >> beam.Create(features) | ||
| | 'RunInference' >> RunInference(model_handler) | ||
| | 'PrintPredictions' >> beam.Map(logging.info)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| logging.getLogger().setLevel(logging.INFO) | ||
| run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going back to the base implementation of the rate limiter, but throttle() returning True logically makes me think that the request should be throttled, not that it's approved. See the adaptive throttler definition of
throttle_request()(beam/sdks/python/apache_beam/io/components/adaptive_throttler.py
Line 103 in 8a90113
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context is different in AdaptiveThrottler and RateLimiter. In AdaptiveThrottler throttling is always possible throttle_request is giving caller info to either apply throttle delay or allow. In RateLimiter throttling might not be always possible, and if possible, delay is already applied by RateLimiter. So true indicates that it is throttled and false indicates its not.
If the naming of throttle() is confusing for people coming from AdaptiveThrottler context we can change it to allow/acquire()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I'm still not following this logic based based on the description in the RateLimiter class:
beam/sdks/python/apache_beam/io/components/rate_limiter.py
Lines 63 to 77 in 6bedec3
"Check if request should be throttled" as a docstring, but then responding with a
Trueif the request is allowed feels backwards.throttle()returningFalsesounds like the request isn't being throttled or limited in any way, when that isn't the case. That's where the disconnect is here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing to the source of confusion. I have updated the doc string to set the expectations of the functions.