Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/how-to-guides/online-server-performance-tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Key knobs:
- **`batch_size`**: DynamoDB's `BatchGetItem` accepts up to 100 items per request. For 500 entities, this means 5 batches. Keep at 100 unless hitting the 16 MB response limit.
- **`max_read_workers`**: Controls parallelism for batch reads. With 10 workers, those 5 batches run concurrently (~10 ms) instead of sequentially (~50 ms).
- **`consistent_reads: false`**: Eventually consistent reads are faster and cheaper. Use `true` only if you need read-after-write consistency.
- **`warmup_connections: true`**: Pre-warms the DynamoDB connection pool on server startup by making a lightweight call (`describe_limits`). This avoids a cold-start latency penalty (~20ms) on the very first feature request.
- **`warmup_connections: true`**: Pre-warms the DynamoDB connection pool on server startup by making `max_pool_connections` concurrent lightweight calls (`describe_endpoints`). This avoids a cold-start latency penalty (~20ms) on the first feature requests, including concurrent ones.
- **`max_pool_connections`**: Increase for high-throughput deployments to improve HTTP connection reuse to the DynamoDB endpoint.
- **`keepalive_timeout`**: Longer keep-alive reduces TLS handshake overhead on reused connections.
- **`connect_timeout` / `read_timeout`**: Lower values fail fast, improving p99. Set aggressively if your retry strategy covers transient failures.
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/online-stores/dynamodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ online_store:
| `batch_size` | int | `100` | Number of items per BatchGetItem/BatchWriteItem request (max 100) |
| `max_read_workers` | int | `10` | Maximum parallel threads for batch read operations. Higher values improve throughput for large batch reads but increase resource usage |
| `consistent_reads` | bool | `false` | Whether to use strongly consistent reads (higher latency, guaranteed latest data) |
| `warmup_connections` | bool | `false` | Whether to pre-warm the async connection pool on startup with a lightweight call (`describe_limits`) |
| `warmup_connections` | bool | `false` | Whether to pre-warm the async connection pool on startup with `max_pool_connections` concurrent lightweight calls (`describe_endpoints`) |
| `tags` | dict | `null` | AWS resource tags added to each table |
| `session_based_auth` | bool | `false` | Use AWS session-based client authentication |

Expand All @@ -65,7 +65,7 @@ For high-throughput workloads with large entity counts, increase `max_read_worke

**Batch Size**: Increase `batch_size` up to 100 to reduce the number of API calls. However, larger batches may hit DynamoDB's 16MB response limit for tables with large feature values.

**Connection Warmup**: The DynamoDB async client does not establish actual TCP/TLS connections to the AWS endpoint on initialization. The very first feature retrieval request is penalized with a cold-start overhead (~20ms). Setting `warmup_connections: true` establishes the TCP connection pool during server startup.
**Connection Warmup**: The DynamoDB async client does not establish actual TCP/TLS connections to the AWS endpoint on initialization. The very first feature retrieval request is penalized with a cold-start overhead (~20ms). Setting `warmup_connections: true` opens up to `max_pool_connections` connections during server startup, one per concurrent `describe_endpoints` call. When DynamoDB is reached through a VPC endpoint, these calls need the `dynamodb:DescribeEndpoints` permission; without it the connections are still opened, but a warning is logged.

## Permissions

Expand Down
24 changes: 19 additions & 5 deletions sdk/python/feast/infra/online_stores/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class DynamoDBOnlineStoreConfig(FeastConfigBaseModel):
"""Whether to read from Dynamodb by forcing consistent reads"""

warmup_connections: StrictBool = False
"""Whether to warm up the connection pool with a lightweight call on initialization"""
"""Whether to warm up the connection pool on initialization, with
max_pool_connections concurrent lightweight calls"""

tags: Union[Dict[str, str], None] = None
"""AWS resource tags added to each table"""
Expand Down Expand Up @@ -161,11 +162,24 @@ async def initialize(self, config: RepoConfig):
)

if online_config.warmup_connections:
try:
await client.describe_limits()
except Exception:
# Concurrent calls, so that each one needs its own connection; a
# sequential call would reuse the connection of the previous one.
# describe_endpoints is not tied to a table and, unlike
# describe_limits, has no documented once-a-minute call limit.
results = await asyncio.gather(
*(
client.describe_endpoints()
for _ in range(online_config.max_pool_connections)
),
return_exceptions=True,
)
errors = [r for r in results if isinstance(r, BaseException)]
if errors:
logger.warning(
"Failed to warmup DynamoDB connection pool", exc_info=True
"Failed to warmup %d of %d DynamoDB connections",
len(errors),
len(results),
exc_info=errors[0],
)

async def close(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from copy import deepcopy
from dataclasses import dataclass
from datetime import datetime
Expand Down Expand Up @@ -100,31 +101,47 @@ def test_dynamodb_online_store_config_custom_params():


@pytest.mark.asyncio
async def test_dynamodb_online_store_warmup_connections():
async def test_dynamodb_online_store_warmup_connections(caplog):
"""Test DynamoDBOnlineStore warmup connections in initialize method."""
from unittest.mock import AsyncMock

online_store = DynamoDBOnlineStore()

# Mock _get_aiodynamodb_client to return a mock client
mock_client = AsyncMock()
mock_client.describe_limits = AsyncMock()
mock_client.describe_endpoints = AsyncMock()
online_store._get_aiodynamodb_client = AsyncMock(return_value=mock_client)

# Test case 1: warmup_connections=True
# Test case 1: warmup_connections=True warms the whole pool. The calls
# must be in flight together, or they would all reuse one connection.
pool_size = 8
in_flight = 0
max_in_flight = 0

async def describe_endpoints():
nonlocal in_flight, max_in_flight
in_flight += 1
max_in_flight = max(max_in_flight, in_flight)
await asyncio.sleep(0)
in_flight -= 1

mock_client.describe_endpoints.side_effect = describe_endpoints
config_warmup = RepoConfig(
registry=REGISTRY,
project=PROJECT,
provider=PROVIDER,
online_store=DynamoDBOnlineStoreConfig(region=REGION, warmup_connections=True),
online_store=DynamoDBOnlineStoreConfig(
region=REGION, warmup_connections=True, max_pool_connections=pool_size
),
offline_store=DaskOfflineStoreConfig(),
entity_key_serialization_version=3,
)
await online_store.initialize(config_warmup)
mock_client.describe_limits.assert_called_once()
assert mock_client.describe_endpoints.call_count == pool_size
assert max_in_flight == pool_size

# Test case 2: warmup_connections=False
mock_client.describe_limits.reset_mock()
mock_client.describe_endpoints.reset_mock()
config_no_warmup = RepoConfig(
registry=REGISTRY,
project=PROJECT,
Expand All @@ -134,13 +151,17 @@ async def test_dynamodb_online_store_warmup_connections():
entity_key_serialization_version=3,
)
await online_store.initialize(config_no_warmup)
mock_client.describe_limits.assert_not_called()

# Test case 3: warmup_connections=True and describe_limits raises an exception (should catch and log warning)
mock_client.describe_limits.reset_mock()
mock_client.describe_limits.side_effect = Exception("Connection failed")
await online_store.initialize(config_warmup)
mock_client.describe_limits.assert_called_once()
mock_client.describe_endpoints.assert_not_called()

# Test case 3: a failed warmup call is logged, and the other calls still run
mock_client.describe_endpoints.reset_mock()
mock_client.describe_endpoints.side_effect = [Exception("Connection failed")] + [
None
] * (pool_size - 1)
with caplog.at_level("WARNING"):
await online_store.initialize(config_warmup)
assert mock_client.describe_endpoints.call_count == pool_size
assert f"Failed to warmup 1 of {pool_size} DynamoDB connections" in caplog.text


def test_dynamodb_online_store_config_dynamodb_client(dynamodb_online_store):
Expand Down