Add concurrency limits and configuration options for SteamCache
- Introduced maxConcurrentRequests and maxRequestsPerClient fields in the Config struct to manage request limits. - Updated the SteamCache implementation to utilize these new configuration options for controlling concurrent requests. - Enhanced the ServeHTTP method to enforce global and per-client rate limiting using semaphores. - Modified the root command to accept new flags for configuring concurrency limits via command-line arguments. - Updated tests to reflect changes in the SteamCache initialization and request handling logic.
This commit is contained in:
@@ -11,6 +11,10 @@ type Config struct {
|
||||
// Server configuration
|
||||
ListenAddress string `yaml:"listen_address" default:":80"`
|
||||
|
||||
// Concurrency limits
|
||||
MaxConcurrentRequests int64 `yaml:"max_concurrent_requests" default:"200"`
|
||||
MaxRequestsPerClient int64 `yaml:"max_requests_per_client" default:"5"`
|
||||
|
||||
// Cache configuration
|
||||
Cache CacheConfig `yaml:"cache"`
|
||||
|
||||
@@ -65,6 +69,12 @@ func LoadConfig(configPath string) (*Config, error) {
|
||||
if config.ListenAddress == "" {
|
||||
config.ListenAddress = ":80"
|
||||
}
|
||||
if config.MaxConcurrentRequests == 0 {
|
||||
config.MaxConcurrentRequests = 50
|
||||
}
|
||||
if config.MaxRequestsPerClient == 0 {
|
||||
config.MaxRequestsPerClient = 3
|
||||
}
|
||||
if config.Cache.Memory.Size == "" {
|
||||
config.Cache.Memory.Size = "0"
|
||||
}
|
||||
@@ -88,16 +98,18 @@ func SaveDefaultConfig(configPath string) error {
|
||||
}
|
||||
|
||||
defaultConfig := Config{
|
||||
ListenAddress: ":80",
|
||||
ListenAddress: ":80",
|
||||
MaxConcurrentRequests: 50, // Reduced for home user (less concurrent load)
|
||||
MaxRequestsPerClient: 3, // Reduced for home user (more conservative per client)
|
||||
Cache: CacheConfig{
|
||||
Memory: MemoryConfig{
|
||||
Size: "1GB",
|
||||
Size: "1GB", // Recommended for systems that can spare 1GB RAM for caching
|
||||
GCAlgorithm: "lru",
|
||||
},
|
||||
Disk: DiskConfig{
|
||||
Size: "10GB",
|
||||
Size: "1TB", // Large HDD cache for home user
|
||||
Path: "./disk",
|
||||
GCAlgorithm: "hybrid",
|
||||
GCAlgorithm: "lru", // Better for gaming patterns (keeps recently played games)
|
||||
},
|
||||
},
|
||||
Upstream: "",
|
||||
|
||||
Reference in New Issue
Block a user