We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contactedHave 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
| Expand Up | @@ -12,11 +12,13 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import asyncio | ||
| import contextlib | ||
| import itertools | ||
| import logging | ||
| from datetime import datetime | ||
| from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Union | ||
|
|
||
| from aiobotocore.config import AioConfig | ||
| from pydantic import StrictBool, StrictStr | ||
|
|
||
| from feast import Entity, FeatureView, utils | ||
| Expand Down Expand Up | @@ -75,6 +77,9 @@ class DynamoDBOnlineStoreConfig(FeastConfigBaseModel): | |
| session_based_auth: bool = False | ||
| """AWS session based client authentication""" | ||
|
|
||
| max_pool_connections: int = 10 | ||
| """Max number of connections for async Dynamodb operations""" | ||
|
|
||
|
|
||
| class DynamoDBOnlineStore(OnlineStore): | ||
| """ | ||
| Expand All | @@ -87,7 +92,14 @@ class DynamoDBOnlineStore(OnlineStore): | |
|
|
||
| _dynamodb_client = None | ||
| _dynamodb_resource = None | ||
| _aioboto_session = None | ||
|
|
||
| async def initialize(self, config: RepoConfig): | ||
| await _get_aiodynamodb_client( | ||
| config.online_store.region, config.online_store.max_pool_connections | ||
| ) | ||
|
|
||
| async def close(self): | ||
| await _aiodynamodb_close() | ||
|
|
||
| @property | ||
| def async_supported(self) -> SupportedAsyncMethods: | ||
| Expand Down Expand Up | @@ -326,15 +338,17 @@ def to_tbl_resp(raw_client_response): | |
| batches.append(batch) | ||
| entity_id_batches.append(entity_id_batch) | ||
|
|
||
| async with self._get_aiodynamodb_client(online_config.region) as client: | ||
| response_batches = await asyncio.gather( | ||
| *[ | ||
| client.batch_get_item( | ||
| RequestItems=entity_id_batch, | ||
| ) | ||
| for entity_id_batch in entity_id_batches | ||
| ] | ||
| ) | ||
| client = await _get_aiodynamodb_client( | ||
| online_config.region, online_config.max_pool_connections | ||
| ) | ||
|
Comment thread
Comment on lines
-329
to
+343
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide commentwe're now reusing the client and doing context management via initialize and close
Sorry, something went wrong.
👍
1
franciscojavierarceo reacted with thumbs up emoji
All reactions
|
||
| response_batches = await asyncio.gather( | ||
| *[ | ||
| client.batch_get_item( | ||
| RequestItems=entity_id_batch, | ||
| ) | ||
| for entity_id_batch in entity_id_batches | ||
| ] | ||
| ) | ||
|
|
||
| result_batches = [] | ||
| for batch, response in zip(batches, response_batches): | ||
| Expand All | @@ -349,14 +363,6 @@ def to_tbl_resp(raw_client_response): | |
|
|
||
| return list(itertools.chain(*result_batches)) | ||
|
|
||
| def _get_aioboto_session(self): | ||
| if self._aioboto_session is None: | ||
| self._aioboto_session = session.get_session() | ||
| return self._aioboto_session | ||
|
|
||
| def _get_aiodynamodb_client(self, region: str): | ||
| return self._get_aioboto_session().create_client("dynamodb", region_name=region) | ||
|
|
||
| def _get_dynamodb_client( | ||
| self, | ||
| region: str, | ||
| Expand Down Expand Up | @@ -489,6 +495,38 @@ def _to_client_batch_get_payload(online_config, table_name, batch): | |
| } | ||
|
|
||
|
|
||
| _aioboto_session = None | ||
| _aioboto_client = None | ||
|
|
||
|
|
||
| def _get_aioboto_session(): | ||
| global _aioboto_session | ||
| if _aioboto_session is None: | ||
| logger.debug("initializing the aiobotocore session") | ||
| _aioboto_session = session.get_session() | ||
| return _aioboto_session | ||
|
|
||
|
|
||
| async def _get_aiodynamodb_client(region: str, max_pool_connections: int): | ||
| global _aioboto_client | ||
| if _aioboto_client is None: | ||
| logger.debug("initializing the aiobotocore dynamodb client") | ||
| client_context = _get_aioboto_session().create_client( | ||
| "dynamodb", | ||
| region_name=region, | ||
| config=AioConfig(max_pool_connections=max_pool_connections), | ||
| ) | ||
| context_stack = contextlib.AsyncExitStack() | ||
| _aioboto_client = await context_stack.enter_async_context(client_context) | ||
| return _aioboto_client | ||
|
|
||
|
|
||
| async def _aiodynamodb_close(): | ||
| global _aioboto_client | ||
| if _aioboto_client: | ||
| await _aioboto_client.close() | ||
|
|
||
|
|
||
| def _initialize_dynamodb_client( | ||
| region: str, | ||
| endpoint_url: Optional[str] = None, | ||
| Expand Down | ||
| @@ -1,4 +1,6 @@ | ||
| [pytest] | ||
| asyncio_mode = auto | ||
|
|
||
| markers = | ||
| universal_offline_stores: mark a test as using all offline stores. | ||
| universal_online_stores: mark a test as using all online stores. | ||
| Expand All | @@ -7,6 +9,8 @@ env = | |
| IS_TEST=True | ||
|
|
||
| filterwarnings = | ||
| error::_pytest.warning_types.PytestConfigWarning | ||
| error::_pytest.warning_types.PytestUnhandledCoroutineWarning | ||
|
Comment thread
Comment on lines
+12
to
+13
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide commentfail if any async test functions are skipped bc of missing plugins
Sorry, something went wrong.
All reactions
|
||
| ignore::DeprecationWarning:pyspark.sql.pandas.*: | ||
| ignore::DeprecationWarning:pyspark.sql.connect.*: | ||
| ignore::DeprecationWarning:httpx.*: | ||
| Expand Down | ||
Uh oh!
There was an error while loading. Please reload this page.