-
Notifications
You must be signed in to change notification settings - Fork 48
feat: Add Valkey and RDMA support for KV-cache indexing #139
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
rishi-jat
wants to merge
1
commit into
llm-d:main
Choose a base branch
from
rishi-jat:feature/valkey-support-134
base: main
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.
Open
Changes from all commits
Commits
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
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
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,100 @@ | ||
# Valkey Configuration Example for KV-Cache Manager | ||
|
||
This example demonstrates how to configure the KV-Cache Manager to use Valkey as the backend for KV-block indexing. | ||
|
||
## Basic Valkey Configuration | ||
|
||
```json | ||
{ | ||
"kvBlockIndexConfig": { | ||
"valkeyConfig": { | ||
"address": "valkey://127.0.0.1:6379", | ||
"backendType": "valkey", | ||
"enableRDMA": false | ||
}, | ||
"enableMetrics": true, | ||
"metricsLoggingInterval": "30s" | ||
} | ||
} | ||
``` | ||
|
||
## Valkey with RDMA Support | ||
|
||
```json | ||
{ | ||
"kvBlockIndexConfig": { | ||
"valkeyConfig": { | ||
"address": "valkey://valkey-server:6379", | ||
"backendType": "valkey", | ||
"enableRDMA": true | ||
}, | ||
"enableMetrics": true | ||
} | ||
} | ||
``` | ||
|
||
## Valkey with SSL/TLS | ||
|
||
```json | ||
{ | ||
"kvBlockIndexConfig": { | ||
"valkeyConfig": { | ||
"address": "valkeys://valkey-cluster:6380", | ||
"backendType": "valkey", | ||
"enableRDMA": false | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Environment Variables | ||
|
||
You can also configure Valkey using environment variables: | ||
|
||
```bash | ||
export VALKEY_ADDR="valkey://127.0.0.1:6379" | ||
export VALKEY_ENABLE_RDMA="false" | ||
``` | ||
|
||
## Migration from Redis | ||
|
||
To migrate from Redis to Valkey, simply change the configuration: | ||
|
||
**Before (Redis):** | ||
```json | ||
{ | ||
"kvBlockIndexConfig": { | ||
"redisConfig": { | ||
"address": "redis://127.0.0.1:6379" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**After (Valkey):** | ||
```json | ||
{ | ||
"kvBlockIndexConfig": { | ||
"valkeyConfig": { | ||
"address": "valkey://127.0.0.1:6379", | ||
"backendType": "valkey" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Benefits of Using Valkey | ||
|
||
1. **Open Source**: Valkey remains under the BSD license, ensuring long-term availability | ||
2. **Redis Compatibility**: Drop-in replacement for Redis with full API compatibility | ||
3. **RDMA Support**: Lower latency networking for high-performance workloads | ||
4. **Community Backed**: Supported by major cloud vendors and the Linux Foundation | ||
5. **Performance**: Optimizations specifically for modern hardware | ||
|
||
## RDMA Configuration Notes | ||
|
||
When `enableRDMA: true` is set: | ||
- Ensure your Valkey server is compiled with RDMA support | ||
- Verify that RDMA hardware and drivers are properly configured | ||
- Note that RDMA support in the Go client is experimental | ||
- The connection will fall back to standard TCP if RDMA is not available |
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,138 @@ | ||
# Valkey Example for KV-Cache Manager | ||
|
||
This example demonstrates how to use Valkey as the backend for the KV-Cache Manager's KV-block indexing system. | ||
|
||
## What is Valkey? | ||
|
||
Valkey is a community-forked version of Redis that remains under the original BSD license. It's fully API-compatible with Redis and offers additional features like RDMA support for improved latency in high-performance scenarios. | ||
|
||
## Benefits of Using Valkey | ||
|
||
- **Open Source**: Remains under the BSD license | ||
- **Redis Compatibility**: Drop-in replacement for Redis | ||
- **RDMA Support**: Lower latency networking for high-performance workloads | ||
- **Community Backed**: Supported by major cloud vendors and Linux Foundation | ||
- **Performance**: Optimizations for modern hardware | ||
|
||
## Prerequisites | ||
|
||
1. **Valkey Server**: Install and run a Valkey server | ||
```bash | ||
# Using Docker | ||
docker run -d -p 6379:6379 valkey/valkey:latest | ||
|
||
# Or install from source/package manager | ||
``` | ||
|
||
2. **Go Environment**: Go 1.24.1 or later | ||
|
||
3. **Optional**: Hugging Face token for tokenizer access | ||
```bash | ||
export HF_TOKEN="your-huggingface-token" | ||
``` | ||
|
||
## Running the Example | ||
|
||
### Basic Usage | ||
|
||
```bash | ||
# Run with default Valkey configuration | ||
go run main.go | ||
|
||
# Run with custom Valkey address | ||
VALKEY_ADDR="valkey://your-valkey-server:6379" go run main.go | ||
``` | ||
|
||
### With RDMA Support | ||
|
||
If your Valkey server supports RDMA: | ||
|
||
```bash | ||
VALKEY_ADDR="valkey://rdma-valkey-server:6379" \ | ||
VALKEY_ENABLE_RDMA="true" \ | ||
go run main.go | ||
``` | ||
|
||
### Environment Variables | ||
|
||
- `VALKEY_ADDR`: Valkey server address (default: `valkey://127.0.0.1:6379`) | ||
- `VALKEY_ENABLE_RDMA`: Enable RDMA transport (default: `false`) | ||
- `HF_TOKEN`: Hugging Face token for tokenizer access (optional) | ||
|
||
## What the Example Does | ||
|
||
1. **Configuration**: Sets up a KV-Cache Manager with Valkey backend | ||
2. **Cache Operations**: Demonstrates adding prompts to the cache | ||
3. **Cache Hits**: Shows how repeated prompts result in cache hits | ||
4. **Multi-Pod Lookup**: Demonstrates cache sharing across multiple pods | ||
5. **Metrics**: Enables metrics collection for monitoring cache performance | ||
|
||
## Expected Output | ||
|
||
``` | ||
I0104 10:30:00.123456 1 main.go:45] Initializing KV-Cache Manager with Valkey backend valkeyAddr="valkey://127.0.0.1:6379" rdmaEnabled=false | ||
I0104 10:30:00.234567 1 main.go:109] Processing prompt iteration=1 prompt="Hello, how are you today?" | ||
I0104 10:30:00.345678 1 main.go:122] Cache score prompt="Hello, how are you today?" score=1.0 podID="demo-pod-1" | ||
I0104 10:30:00.456789 1 main.go:109] Processing prompt iteration=3 prompt="Hello, how are you today?" | ||
I0104 10:30:00.567890 1 main.go:122] Cache score prompt="Hello, how are you today?" score=1.0 podID="demo-pod-1" | ||
... | ||
I0104 10:30:02.123456 1 main.go:65] Valkey example completed successfully | ||
``` | ||
|
||
## Comparison with Redis | ||
|
||
The Valkey backend is API-compatible with Redis, so you can easily switch between them: | ||
|
||
### Redis Configuration | ||
```json | ||
{ | ||
"kvBlockIndexConfig": { | ||
"redisConfig": { | ||
"address": "redis://127.0.0.1:6379" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Valkey Configuration | ||
```json | ||
{ | ||
"kvBlockIndexConfig": { | ||
"valkeyConfig": { | ||
"address": "valkey://127.0.0.1:6379", | ||
"backendType": "valkey", | ||
"enableRDMA": false | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Performance Considerations | ||
|
||
- **RDMA**: Enable RDMA for ultra-low latency if your infrastructure supports it | ||
- **Connection Pooling**: The underlying Redis client handles connection pooling | ||
- **Persistence**: Valkey data persists across restarts (unlike in-memory backends) | ||
- **Scalability**: Suitable for distributed deployments with multiple indexer replicas | ||
|
||
## Troubleshooting | ||
|
||
### Connection Issues | ||
- Ensure Valkey server is running and accessible | ||
- Check network connectivity and firewall rules | ||
- Verify the address format (supports `valkey://`, `redis://`, or plain addresses) | ||
|
||
### RDMA Issues | ||
- Confirm Valkey server is compiled with RDMA support | ||
- Verify RDMA hardware and drivers are properly configured | ||
- Check that both client and server are on RDMA-enabled networks | ||
|
||
### Performance Issues | ||
- Monitor cache hit rates using the built-in metrics | ||
- Adjust block size in TokenProcessorConfig for your use case | ||
- Consider using multiple Valkey instances for horizontal scaling | ||
|
||
## See Also | ||
|
||
- [Valkey Configuration Guide](../valkey_configuration.md) | ||
- [KV-Cache Manager Architecture](../../docs/architecture.md) | ||
- [Configuration Reference](../../docs/configuration.md) |
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.
Extra trailing space after comma should be removed.
Copilot uses AI. Check for mistakes.