OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
GrpcServiceConfig.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <string>
6#include <grpc/impl/compression_types.h>
7
8namespace OdbDesignServer
9{
10 namespace Config
11 {
12 // Human-readable name for a gRPC compression level (for logging)
13 inline const char* CompressionLevelToString(grpc_compression_level level)
14 {
15 switch (level)
16 {
17 case GRPC_COMPRESS_LEVEL_NONE: return "none";
18 case GRPC_COMPRESS_LEVEL_LOW: return "low";
19 case GRPC_COMPRESS_LEVEL_MED: return "medium";
20 case GRPC_COMPRESS_LEVEL_HIGH: return "high";
21 default: return "unknown";
22 }
23 }
24
26 {
27 // Message size limits (in MB)
28 int max_receive_message_size_mb = 250; // Default 250MB (updated to handle large designs like Turbot)
29 int max_send_message_size_mb = 250; // Default 250MB (updated to handle large designs like Turbot)
30
31 // Compression configuration ("none" disables compression)
32 grpc_compression_level compression_level = GRPC_COMPRESS_LEVEL_HIGH; // Default high (best compression)
33
34 // Batch streaming configuration
35 bool enable_batch_streaming = true; // Feature flag for gradual rollout
36 int batch_size = 500; // Features per batch (100-1000)
37
38 // Design streaming configuration (M6: GetDesignStream + disk spool).
39 // The monolithic serve budget itself lives on DesignCache
40 // (setMonolithicWireBudget) so the RPC guard and the background
41 // pre-serialization share one knob.
42 bool enable_design_streaming = true; // Feature flag for GetDesignStream
43 int design_stream_feature_batch_size = 1000; // FeatureRecords per FeatureBatch (100-10000)
44 // Disk spool for over-budget designs. Empty dir = a per-service-
45 // instance directory under the system temp dir (removed on exit).
46 std::string stream_spool_dir;
47 // Total spool byte cap (LRU-evicted beyond it). 4 GiB holds the
48 // spools of both large designs (1.0-1.34 GB each) with headroom.
49 std::uint64_t stream_spool_max_bytes = 4ull * 1024ull * 1024ull * 1024ull;
50
51 // Thread pool configuration
52 int max_threads = 8; // Maximum gRPC server threads (ResourceQuota)
53 int min_pollers = 1; // Minimum polling threads
54
55 // Keepalive configuration (seconds)
56 int keepalive_time_s = 30; // Send keepalive ping every N seconds on idle connections
57 int keepalive_timeout_s = 10; // Close connection if no response within N seconds
58 bool keepalive_permit_without_calls = true; // Send pings even with no active RPCs
59
60 // Clamp batch_size to valid range [100, 1000]
62 {
63 if (batch_size < 100)
64 batch_size = 100;
65 else if (batch_size > 1000)
66 batch_size = 1000;
67 }
68
69 // Create default configuration
70 static std::shared_ptr<GrpcServiceConfig> CreateDefault()
71 {
72 return std::make_shared<GrpcServiceConfig>();
73 }
74
75 // Load result containing config and status
77 {
78 std::shared_ptr<GrpcServiceConfig> config;
79 bool loadedFromFile = false; // true if loaded from file, false if using defaults
80 std::string message; // Status message for logging
81 };
82
83 // Load configuration from JSON file
84 // Returns LoadResult containing config and whether it was loaded from file
85 static LoadResult LoadFromFile(const std::string& configPath);
86 };
87 }
88}
const char * CompressionLevelToString(grpc_compression_level level)
static std::shared_ptr< GrpcServiceConfig > CreateDefault()
static LoadResult LoadFromFile(const std::string &configPath)