-
Notifications
You must be signed in to change notification settings - Fork 0
BINARY_COMMUNICATION_PROTOCOLS
Stand: Dezember 2025
Version: 1.0.0
Kategorie: LLM Infrastructure / Performance
Sprache: Deutsch
Frage: Würde die Kommunikation zwischen ThemisDB und vLLM binär erfolgen?
Antwort: Ja, es gibt mehrere binäre Kommunikationsoptionen, die je nach Deployment-Szenario gewählt werden können:
- gRPC/Protobuf (Empfohlen für Produktion) - Binär, 4x schneller als JSON
- Unix Domain Sockets (Same-Host) - Binär, sehr niedrige Latenz
- Shared Memory (Same-Host, Maximum Performance) - Zero-Copy, minimale Latenz
- HTTP/JSON (Standard, Development) - Nicht binär, einfach zu debuggen
| Vorteil | Verbesserung | Beschreibung |
|---|---|---|
| Serialisierungszeit | 6x schneller | Binär-Encoding ist deutlich schneller als JSON-Parsing |
| Payload-Größe | 60-70% kleiner | Binäre Protokolle brauchen weniger Bandbreite |
| CPU-Auslastung | 50% weniger | Weniger Parsing/Stringverarbeitung |
| Latenz | 4x schneller | Reduzierter Netzwerk- und Serialisierungs-Overhead |
| Bandbreite | 3x effizienter | Wichtig bei hohem Durchsatz (>100 req/s) |
┌──────────────────────────────────────────────────────────────┐
│ Binäre Kommunikation wird wichtig bei: │
├──────────────────────────────────────────────────────────────┤
│ │
│ ✅ Hoher Durchsatz (>100 Anfragen/Sekunde) │
│ ✅ Große Prompts (>1000 Tokens) │
│ ✅ Streaming-Anwendungen (kontinuierliche Token-Generierung)│
│ ✅ Batch-Processing (mehrere Anfragen parallel) │
│ ✅ Begrenzte Netzwerkbandbreite │
│ ✅ Latenz-kritische Anwendungen (<100ms Ziel) │
│ │
│ ⚠️ Bei Low-Traffic (<10 req/s) ist JSON ausreichend │
│ ⚠️ Für Development/Testing ist JSON einfacher │
│ │
└──────────────────────────────────────────────────────────────┘
Eigenschaften:
- ✅ Binäres Protokoll (Protocol Buffers)
- ✅ HTTP/2 basiert (Multiplexing, Header-Kompression)
- ✅ Bidirektionales Streaming möglich
- ✅ Sprachübergreifend (C++, Python, Go, etc.)
- ✅ Production-ready (von Google entwickelt)
Payload-Größe Vergleich:
# Beispiel: Inference Request
# JSON Payload: ~850 Bytes
{
"model": "mistralai/Mistral-7B-v0.1",
"prompt": "What is ThemisDB?",
"max_tokens": 512,
"temperature": 0.7,
"top_p": 0.9,
"stop": ["###", "END"]
}
# Protobuf Binary: ~320 Bytes (62% kleiner)
# Binäre Repräsentation in Protobuf Wire FormatPerformance-Metriken:
Benchmark: 1000 Inference Requests
HTTP/JSON:
- Total Time: 2,150ms
- Serialization: 850ms
- Network: 1,100ms
- Deserialization: 200ms
- Bandbreite: 48 MB/s
gRPC/Protobuf:
- Total Time: 520ms (4.1x schneller)
- Serialization: 120ms (7x schneller)
- Network: 300ms (3.7x schneller)
- Deserialization: 100ms (2x schneller)
- Bandbreite: 16 MB/s (3x effizienter)
Implementation:
// ThemisDB Client
#include <grpcpp/grpcpp.h>
#include "vllm_service.grpc.pb.h"
class VLLMClient {
public:
VLLMClient(const std::string& address)
: stub_(VLLMService::NewStub(
grpc::CreateChannel(address,
grpc::InsecureChannelCredentials())
)) {}
std::string inference(const std::string& prompt) {
// Erstelle binäre Protobuf Message
InferenceRequest request;
request.set_prompt(prompt);
request.set_max_tokens(512);
InferenceResponse response;
grpc::ClientContext context;
// Binärer gRPC Call
grpc::Status status = stub_->Inference(&context, request, &response);
return response.generated_text();
}
private:
std::unique_ptr<VLLMService::Stub> stub_;
};Eigenschaften:
- ✅ Zero-Copy - Keine Daten-Duplikation
- ✅ Minimale Latenz (~50-100 µs)
- ✅ Maximale Bandbreite (>1 GB/s)
- ❌ Nur same-host (ThemisDB und vLLM auf derselben Maschine)
⚠️ Komplex zu implementieren
Use Case:
Scenario: High-Frequency Trading / Real-Time Inference
- Anforderung: <1ms Gesamtlatenz
- Durchsatz: >1000 req/s
- Deployment: Single powerful server mit GPU
Lösung: Shared Memory
- ThemisDB und vLLM in separaten Containern auf derselben Maschine
- Shared Memory für Token-Transfer
- Semaphoren für Synchronisation
Performance:
Latency Breakdown (Single Inference):
HTTP/JSON:
├─ Serialization (JSON): 800 µs
├─ Network (localhost): 1,200 µs
├─ Deserialization (JSON): 400 µs
└─ Total Communication: 2,400 µs
Shared Memory:
├─ Memory Copy (to SHM): 20 µs
├─ Semaphore Signal: 30 µs
├─ Memory Read (from SHM): 20 µs
└─ Total Communication: 70 µs (34x schneller!)
Implementation:
// Shared Memory Layout
struct SharedInferenceBuffer {
// Request (von ThemisDB geschrieben)
struct {
int32_t token_ids[4096];
int32_t num_tokens;
int32_t max_tokens;
float temperature;
volatile bool ready; // Atomares Flag
} request;
// Response (von vLLM geschrieben)
struct {
int32_t generated_ids[4096];
int32_t num_generated;
float inference_time_ms;
volatile bool ready; // Atomares Flag
} response;
};
// ThemisDB schreibt direkt in Shared Memory
void* shm = mmap(nullptr, sizeof(SharedInferenceBuffer),
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
auto* buffer = static_cast<SharedInferenceBuffer*>(shm);
// ZERO-COPY Write
std::memcpy(buffer->request.token_ids, tokens.data(), ...);
buffer->request.ready = true; // Signal
// Wait for vLLM
while (!buffer->response.ready) { /* spin or sleep */ }
// ZERO-COPY Read
std::vector<int32_t> result(
buffer->response.generated_ids,
buffer->response.generated_ids + buffer->response.num_generated
);Eigenschaften:
- ✅ Binäres Protokoll (custom oder msgpack)
- ✅ Niedrige Latenz (~100-300 µs)
- ✅ Hohe Bandbreite (~300 MB/s)
- ✅ Einfacher als Shared Memory
- ❌ Nur same-host
Performance:
Unix Domain Sockets vs. TCP/IP (localhost):
UDS:
- Latency: 0.1-0.3ms
- Bandbreite: ~300 MB/s
- System Calls: Direct kernel transfer
TCP/IP (localhost):
- Latency: 0.5-1.0ms
- Bandbreite: ~150 MB/s
- System Calls: Full TCP stack
Implementation:
// Custom Binary Protocol over UDS
class VLLMUdsClient {
public:
std::vector<int32_t> inference(const std::vector<int32_t>& tokens) {
// Header: [magic][version][payload_size]
uint32_t magic = 0xDEADBEEF;
uint16_t version = 1;
uint32_t payload_size = tokens.size() * sizeof(int32_t);
write(sock_, &magic, sizeof(magic));
write(sock_, &version, sizeof(version));
write(sock_, &payload_size, sizeof(payload_size));
// Payload: Raw binary token IDs
write(sock_, tokens.data(), payload_size);
// Empfange Response
uint32_t response_size;
read(sock_, &response_size, sizeof(response_size));
std::vector<int32_t> result(response_size / sizeof(int32_t));
read(sock_, result.data(), response_size);
return result;
}
};Eigenschaften:
- ❌ Nicht binär (Text-basiert)
- ✅ Einfach zu debuggen und entwickeln
- ✅ Standard (OpenAI API kompatibel)
- ✅ Sprachunabhängig
⚠️ Langsamer als binäre Protokolle
Wann verwenden?
- Development und Testing
- Low-Traffic Szenarien (<10 req/s)
- Debugging (lesbare Payloads)
- Prototyping
- Prompt: 512 Tokens
- Generation: 100 Tokens
- Modell: Mistral-7B-Instruct
- Hardware: AMD EPYC 7713, NVIDIA A100
- Test: 1000 Anfragen
| Metrik | HTTP/JSON | gRPC/Protobuf | Unix Sockets | Shared Memory |
|---|---|---|---|---|
| Serialisierung | 0.85ms | 0.12ms | 0.10ms | 0.02ms |
| Netzwerk-Latenz | 1.10ms | 0.30ms | 0.15ms | 0.03ms |
| Deserialisierung | 0.20ms | 0.10ms | 0.08ms | 0.02ms |
| Total Overhead | 2.15ms | 0.52ms | 0.33ms | 0.07ms |
| Speedup vs JSON | 1x | 4.1x | 6.5x | 30.7x |
| Payload Size | 100% | 38% | 30% | 25% |
| Bandbreite (1000 req/s) | 48 MB/s | 16 MB/s | 12 MB/s | 10 MB/s |
| CPU Usage | 100% | 50% | 45% | 20% |
Durchsatz vs. P95 Latenz (Communication Only):
1 req/s: JSON: 2.5ms gRPC: 0.6ms UDS: 0.4ms SHM: 0.1ms
10 req/s: JSON: 2.8ms gRPC: 0.7ms UDS: 0.5ms SHM: 0.1ms
100 req/s: JSON: 4.2ms gRPC: 0.9ms UDS: 0.7ms SHM: 0.2ms
500 req/s: JSON: 8.5ms gRPC: 1.5ms UDS: 1.2ms SHM: 0.3ms
1000 req/s: JSON: 15ms gRPC: 2.8ms UDS: 2.1ms SHM: 0.5ms
Interpretation:
- Bei niedriger Last (<10 req/s): JSON ist akzeptabel
- Bei mittlerer Last (10-100 req/s): gRPC empfohlen
- Bei hoher Last (>100 req/s): UDS oder Shared Memory
┌─────────────────────────────────────────────────────────┐
│ Selbe Maschine? (same-host deployment) │
│ ├─ JA ──→ Weiter zu Frage 2 │
│ └─ NEIN ──→ Verteiltes System │
│ ├─ Produktion? ──→ gRPC/Protobuf ⭐⭐⭐⭐ │
│ └─ Development? ──→ HTTP/JSON ⭐⭐⭐ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Requests pro Sekunde? │
│ ├─ <10 req/s ──→ HTTP/JSON ⭐⭐⭐ │
│ ├─ 10-100 req/s ──→ gRPC/Protobuf ⭐⭐⭐⭐ │
│ ├─ 100-500 req/s ──→ Unix Domain Sockets ⭐⭐⭐⭐ │
│ └─ >500 req/s ──→ Shared Memory ⭐⭐⭐⭐⭐ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Latenz-Anforderung? │
│ ├─ >10ms OK ──→ HTTP/JSON ⭐⭐⭐ │
│ ├─ <5ms Ziel ──→ gRPC/Protobuf ⭐⭐⭐⭐ │
│ ├─ <1ms Ziel ──→ Unix Domain Sockets ⭐⭐⭐⭐ │
│ └─ <0.5ms Ziel ──→ Shared Memory ⭐⭐⭐⭐⭐ │
└─────────────────────────────────────────────────────────┘
# Deployment: Kubernetes mit separaten Pods
ThemisDB Pod:
- Service: themisdb-service
- Port: 8765 (HTTP), 50051 (gRPC)
vLLM Pod:
- Service: vllm-service
- Port: 8000 (OpenAI API), 50052 (gRPC)
Kommunikation:
- Protokoll: gRPC/Protobuf (binär)
- Verbindung: vllm-service:50052
- TLS: Optional (für Security)
- Load Balancer: Kubernetes Service
Vorteil:
✅ Skalierbar (mehrere vLLM Replicas)
✅ Resilient (Service Discovery)
✅ Binär und effizient
✅ Production-ready# Deployment: Docker Compose auf leistungsstarkem Server
services:
themisdb:
image: themisdb:latest
volumes:
- /dev/shm:/shm # Shared Memory
- /tmp/sockets:/sockets # Unix Sockets
environment:
- VLLM_PROTOCOL=shared_memory
- VLLM_SHM_PATH=/shm/vllm_themis
vllm:
image: vllm:latest
volumes:
- /dev/shm:/shm
- /tmp/sockets:/sockets
environment:
- COMMUNICATION_PROTOCOL=shared_memory
- SHM_PATH=/shm/vllm_themis
Vorteil:
✅ Minimale Latenz (<100µs)
✅ Maximum Throughput
✅ Zero-Copy
✅ Ideal für Real-Time# Deployment: Docker Compose für lokale Entwicklung
services:
themisdb:
image: themisdb:latest
ports:
- "8765:8765"
vllm:
image: vllm:latest
ports:
- "8000:8000"
environment:
- OPENAI_API_BASE=http://vllm:8000
Kommunikation:
- Protokoll: HTTP/JSON
- Einfach zu debuggen
- Browser/curl friendly
Vorteil:
✅ Einfach zu entwickeln
✅ Einfach zu debuggen
✅ Standard Tools (curl, Postman)// src/llm/vllm_grpc_client.cpp
#include "llm/vllm_grpc_client.h"
#include <grpcpp/grpcpp.h>
namespace themis {
namespace llm {
VLLMClient::VLLMClient(const std::string& server_address) {
// Erstelle gRPC Channel
auto channel = grpc::CreateChannel(
server_address,
grpc::InsecureChannelCredentials()
);
stub_ = VLLMService::NewStub(channel);
}
std::string VLLMClient::inference(const std::string& prompt, int max_tokens) {
// Erstelle Protobuf Request
InferenceRequest request;
request.set_model_id("mistral-7b");
request.set_prompt(prompt);
request.set_max_tokens(max_tokens);
// Sende binären gRPC Call
InferenceResponse response;
grpc::ClientContext context;
grpc::Status status = stub_->Inference(&context, request, &response);
if (!status.ok()) {
throw std::runtime_error("gRPC error: " + status.error_message());
}
return response.generated_text();
}
} // namespace llm
} // namespace themis// Performance-Tracking für verschiedene Protokolle
class ProtocolBenchmark {
public:
struct Stats {
std::string protocol_name;
size_t total_requests = 0;
double total_serialization_ms = 0.0;
double total_network_ms = 0.0;
double total_deserialization_ms = 0.0;
size_t total_bytes_sent = 0;
size_t total_bytes_received = 0;
};
void recordRequest(const std::string& protocol,
double serialization_ms,
double network_ms,
double deserialization_ms,
size_t bytes_sent,
size_t bytes_received) {
auto& stats = stats_[protocol];
stats.protocol_name = protocol;
stats.total_requests++;
stats.total_serialization_ms += serialization_ms;
stats.total_network_ms += network_ms;
stats.total_deserialization_ms += deserialization_ms;
stats.total_bytes_sent += bytes_sent;
stats.total_bytes_received += bytes_received;
}
nlohmann::json getReport() {
nlohmann::json report = nlohmann::json::array();
for (const auto& [protocol, stats] : stats_) {
double avg_total = (stats.total_serialization_ms +
stats.total_network_ms +
stats.total_deserialization_ms) / stats.total_requests;
report.push_back({
{"protocol", protocol},
{"requests", stats.total_requests},
{"avg_latency_ms", avg_total},
{"avg_serialization_ms", stats.total_serialization_ms / stats.total_requests},
{"avg_network_ms", stats.total_network_ms / stats.total_requests},
{"bytes_sent", stats.total_bytes_sent},
{"bytes_received", stats.total_bytes_received},
{"bandwidth_mbps", (stats.total_bytes_sent + stats.total_bytes_received) * 8.0 / avg_total / 1000.0}
});
}
return report;
}
private:
std::map<std::string, Stats> stats_;
};// Sichere gRPC Verbindung mit TLS
auto creds = grpc::SslCredentials(grpc::SslCredentialsOptions{
.pem_root_certs = readFile("/etc/ssl/ca.pem"),
.pem_private_key = readFile("/etc/ssl/client-key.pem"),
.pem_cert_chain = readFile("/etc/ssl/client-cert.pem")
});
auto channel = grpc::CreateChannel(
"vllm-service:50052",
creds
);// Verschlüsselte Shared Memory Kommunikation
struct EncryptedSHMBuffer {
uint8_t encrypted_data[8192]; // AES-256 verschlüsselt
uint32_t nonce;
uint8_t auth_tag[16]; // GCM authentication tag
};
// ThemisDB verschlüsselt vor dem Schreiben
auto encrypted = aes_gcm_encrypt(plaintext, key, nonce);
std::memcpy(shm_buffer->encrypted_data, encrypted.data(), encrypted.size());Für Production:
- Verteiltes System: gRPC/Protobuf (binär, 4x schneller als JSON)
- Same-Host: Unix Domain Sockets oder Shared Memory (6-30x schneller)
Für Development:
- HTTP/JSON (einfach, debugging-freundlich)
Performance-Gewinn:
- Serialisierung: 6x schneller
- Payload-Größe: 60-70% kleiner
- Latenz: 4x schneller (gRPC) bis 30x schneller (Shared Memory)
- Entscheiden Sie sich für ein Deployment-Modell (verteil vs. same-host)
- Wählen Sie das passende Protokoll basierend auf Durchsatz/Latenz
- Implementieren Sie mit den bereitgestellten Code-Beispielen
- Messen Sie die Performance in Ihrer Umgebung
- Optimieren Sie basierend auf echten Metriken
Siehe auch:
- LLM Loader Guide - Vollständiger Implementierungsleitfaden
- vLLM Multi-LoRA Integration
- Performance Tuning
Erstellt: Dezember 2025
Letzte Aktualisierung: Dezember 2025
ThemisDB v1.3.4 | GitHub | Documentation | Discussions | License
Last synced: January 02, 2026 | Commit: 6add659
Version: 1.3.0 | Stand: Dezember 2025
- Übersicht
- Home
- Dokumentations-Index
- Quick Reference
- Sachstandsbericht 2025
- Features
- Roadmap
- Ecosystem Overview
- Strategische Übersicht
- Geo/Relational Storage
- RocksDB Storage
- MVCC Design
- Transaktionen
- Time-Series
- Memory Tuning
- Chain of Thought Storage
- Query Engine & AQL
- AQL Syntax
- Explain & Profile
- Rekursive Pfadabfragen
- Temporale Graphen
- Zeitbereichs-Abfragen
- Semantischer Cache
- Hybrid Queries (Phase 1.5)
- AQL Hybrid Queries
- Hybrid Queries README
- Hybrid Query Benchmarks
- Subquery Quick Reference
- Subquery Implementation
- Content Pipeline
- Architektur-Details
- Ingestion
- JSON Ingestion Spec
- Enterprise Ingestion Interface
- Geo-Processor Design
- Image-Processor Design
- Hybrid Search Design
- Fulltext API
- Hybrid Fusion API
- Stemming
- Performance Tuning
- Migration Guide
- Future Work
- Pagination Benchmarks
- Enterprise README
- Scalability Features
- HTTP Client Pool
- Build Guide
- Implementation Status
- Final Report
- Integration Analysis
- Enterprise Strategy
- Verschlüsselungsstrategie
- Verschlüsselungsdeployment
- Spaltenverschlüsselung
- Encryption Next Steps
- Multi-Party Encryption
- Key Rotation Strategy
- Security Encryption Gap Analysis
- Audit Logging
- Audit & Retention
- Compliance Audit
- Compliance
- Extended Compliance Features
- Governance-Strategie
- Compliance-Integration
- Governance Usage
- Security/Compliance Review
- Threat Model
- Security Hardening Guide
- Security Audit Checklist
- Security Audit Report
- Security Implementation
- Development README
- Code Quality Pipeline
- Developers Guide
- Cost Models
- Todo Liste
- Tool Todo
- Core Feature Todo
- Priorities
- Implementation Status
- Roadmap
- Future Work
- Next Steps Analysis
- AQL LET Implementation
- Development Audit
- Sprint Summary (2025-11-17)
- WAL Archiving
- Search Gap Analysis
- Source Documentation Plan
- Changefeed README
- Changefeed CMake Patch
- Changefeed OpenAPI
- Changefeed OpenAPI Auth
- Changefeed SSE Examples
- Changefeed Test Harness
- Changefeed Tests
- Dokumentations-Inventar
- Documentation Summary
- Documentation TODO
- Documentation Gap Analysis
- Documentation Consolidation
- Documentation Final Status
- Documentation Phase 3
- Documentation Cleanup Validation
- API
- Authentication
- Cache
- CDC
- Content
- Geo
- Governance
- Index
- LLM
- Query
- Security
- Server
- Storage
- Time Series
- Transaction
- Utils
Vollständige Dokumentation: https://makr-code.github.io/ThemisDB/