MCPcopy
hub / github.com/redis/go-redis / ApplyDefaultsWithPoolConfig

Method ApplyDefaultsWithPoolConfig

maintnotifications/config.go:222–318  ·  view source on GitHub ↗

ApplyDefaultsWithPoolConfig applies default values to any zero-value fields in the configuration, using the provided pool size and max active connections to calculate worker and queue defaults. This ensures that partially configured structs get sensible defaults for missing fields.

(poolSize int, maxActiveConns int)

Source from the content-addressed store, hash-verified

220// using the provided pool size and max active connections to calculate worker and queue defaults.
221// This ensures that partially configured structs get sensible defaults for missing fields.
222func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *Config {
223 if c == nil {
224 return DefaultConfig().ApplyDefaultsWithPoolSize(poolSize)
225 }
226
227 defaults := DefaultConfig()
228 result := &Config{}
229
230 // Apply defaults for enum fields (empty/zero means not set)
231 result.Mode = defaults.Mode
232 if c.Mode != "" {
233 result.Mode = c.Mode
234 }
235
236 result.EndpointType = defaults.EndpointType
237 if c.EndpointType != "" {
238 result.EndpointType = c.EndpointType
239 }
240
241 // Apply defaults for duration fields (zero means not set)
242 result.RelaxedTimeout = defaults.RelaxedTimeout
243 if c.RelaxedTimeout > 0 {
244 result.RelaxedTimeout = c.RelaxedTimeout
245 }
246
247 result.HandoffTimeout = defaults.HandoffTimeout
248 if c.HandoffTimeout > 0 {
249 result.HandoffTimeout = c.HandoffTimeout
250 }
251
252 // Copy worker configuration
253 result.MaxWorkers = c.MaxWorkers
254
255 // Apply worker defaults based on pool size
256 result.applyWorkerDefaults(poolSize)
257
258 // Apply queue size defaults with new scaling approach
259 // Default: max(20x workers, PoolSize), capped by maxActiveConns or 5x pool size
260 workerBasedSize := result.MaxWorkers * 20
261 poolBasedSize := poolSize
262 result.HandoffQueueSize = max(workerBasedSize, poolBasedSize)
263 if c.HandoffQueueSize > 0 {
264 // When explicitly set: enforce minimum of 200
265 result.HandoffQueueSize = max(200, c.HandoffQueueSize)
266 }
267
268 // Cap queue size: use maxActiveConns+1 if set, otherwise 5x pool size
269 var queueCap int
270 if maxActiveConns > 0 {
271 queueCap = maxActiveConns + 1
272 // Ensure queue cap is at least 2 for very small maxActiveConns
273 if queueCap < 2 {
274 queueCap = 2
275 }
276 } else {
277 queueCap = poolSize * 5
278 }
279 result.HandoffQueueSize = min(result.HandoffQueueSize, queueCap)

Callers 2

initMethod · 0.80

Calls 7

applyWorkerDefaultsMethod · 0.95
DebugLoggingEnabledFunction · 0.92
ConfigDebugFunction · 0.92
DefaultConfigFunction · 0.85
DebugOrAboveMethod · 0.80
PrintfMethod · 0.65

Tested by

no test coverage detected