Skip to content

Commit 29e8c6c

Browse files
committed
fix: Add connection pre-warming for DynamoDB async client
Add warmup_connections parameter to DynamoDBOnlineStoreConfig and warm up connections via describe_limits inside initialize() method to solve cold-start latency. Fixes feast-dev#6060 Signed-off-by: Nithin <[email protected]>
1 parent 39d408d commit 29e8c6c

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎sdk/python/feast/infra/online_stores/dynamodb.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class DynamoDBOnlineStoreConfig(FeastConfigBaseModel):
7676
consistent_reads: StrictBool = False
7777
"""Whether to read from Dynamodb by forcing consistent reads"""
7878

79+
warmup_connections: StrictBool = False
80+
"""Whether to warm up the connection pool with a lightweight call on initialization"""
81+
7982
tags: Union[Dict[str, str], None] = None
8083
"""AWS resource tags added to each table"""
8184

@@ -146,7 +149,7 @@ def __init__(self):
146149
async def initialize(self, config: RepoConfig):
147150
online_config = config.online_store
148151

149-
await self._get_aiodynamodb_client(
152+
client = await self._get_aiodynamodb_client(
150153
online_config.region,
151154
online_config.max_pool_connections,
152155
online_config.keepalive_timeout,
@@ -157,6 +160,12 @@ async def initialize(self, config: RepoConfig):
157160
online_config.endpoint_url,
158161
)
159162

163+
if online_config.warmup_connections:
164+
try:
165+
await client.describe_limits()
166+
except Exception:
167+
logger.warning("Failed to warmup DynamoDB connection pool", exc_info=True)
168+
160169
async def close(self):
161170
await self._aiodynamodb_close()
162171

‎sdk/python/tests/unit/infra/online_store/test_dynamodb_online_store.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def test_dynamodb_online_store_config_default():
7575
assert dynamodb_store_config.read_timeout == 10
7676
assert dynamodb_store_config.total_max_retry_attempts == 3
7777
assert dynamodb_store_config.retry_mode == "adaptive"
78+
assert dynamodb_store_config.warmup_connections is False
7879

7980

8081
def test_dynamodb_online_store_config_custom_params():
@@ -88,12 +89,52 @@ def test_dynamodb_online_store_config_custom_params():
8889
batch_size=batch_size,
8990
endpoint_url=endpoint_url,
9091
table_name_template=table_name_template,
92+
warmup_connections=True,
9193
)
9294
assert dynamodb_store_config.type == "dynamodb"
9395
assert dynamodb_store_config.batch_size == batch_size
9496
assert dynamodb_store_config.endpoint_url == endpoint_url
9597
assert dynamodb_store_config.region == aws_region
9698
assert dynamodb_store_config.table_name_template == table_name_template
99+
assert dynamodb_store_config.warmup_connections is True
100+
101+
102+
@pytest.mark.asyncio
103+
async def test_dynamodb_online_store_warmup_connections():
104+
"""Test DynamoDBOnlineStore warmup connections in initialize method."""
105+
from unittest.mock import AsyncMock
106+
107+
online_store = DynamoDBOnlineStore()
108+
109+
# Mock _get_aiodynamodb_client to return a mock client
110+
mock_client = AsyncMock()
111+
mock_client.describe_limits = AsyncMock()
112+
online_store._get_aiodynamodb_client = AsyncMock(return_value=mock_client)
113+
114+
# Test case 1: warmup_connections=True
115+
config_warmup = RepoConfig(
116+
registry=REGISTRY,
117+
project=PROJECT,
118+
provider=PROVIDER,
119+
online_store=DynamoDBOnlineStoreConfig(region=REGION, warmup_connections=True),
120+
offline_store=DaskOfflineStoreConfig(),
121+
entity_key_serialization_version=3,
122+
)
123+
await online_store.initialize(config_warmup)
124+
mock_client.describe_limits.assert_called_once()
125+
126+
# Test case 2: warmup_connections=False
127+
mock_client.describe_limits.reset_mock()
128+
config_no_warmup = RepoConfig(
129+
registry=REGISTRY,
130+
project=PROJECT,
131+
provider=PROVIDER,
132+
online_store=DynamoDBOnlineStoreConfig(region=REGION, warmup_connections=False),
133+
offline_store=DaskOfflineStoreConfig(),
134+
entity_key_serialization_version=3,
135+
)
136+
await online_store.initialize(config_no_warmup)
137+
mock_client.describe_limits.assert_not_called()
97138

98139

99140
def test_dynamodb_online_store_config_dynamodb_client(dynamodb_online_store):

0 commit comments

Comments
 (0)