-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add memory limiter to gateway collector (#1086)
- Loading branch information
Showing
13 changed files
with
265 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,57 @@ | ||
package gateway | ||
|
||
import odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" | ||
|
||
const ( | ||
defaultRequestMemoryMiB = 500 | ||
|
||
// this configures the processor limit_mib, which is the hard limit in MiB, afterwhich garbage collection will be forced. | ||
// as recommended by the processor docs, if not set, this is set to 50MiB less than the memory limit of the collector | ||
defaultMemoryLimiterLimitDiffMib = 50 | ||
|
||
// the soft limit will be set to 80% of the hard limit. | ||
// this value is used to derive the "spike_limit_mib" parameter in the processor configuration if a value is not set | ||
defaultMemoryLimiterSpikePercentage = 20.0 | ||
|
||
// the percentage out of the memory limiter hard limit, at which go runtime will start garbage collection. | ||
// it is used to calculate the GOMEMLIMIT environment variable value. | ||
defaultGoMemLimitPercentage = 80.0 | ||
) | ||
|
||
type memoryConfigurations struct { | ||
memoryRequestMiB int | ||
memoryLimiterLimitMiB int | ||
memoryLimiterSpikeLimitMiB int | ||
gomemlimitMiB int | ||
} | ||
|
||
func getMemoryConfigurations(odigosConfig *odigosv1.OdigosConfiguration) *memoryConfigurations { | ||
|
||
memoryRequestMiB := defaultRequestMemoryMiB | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.RequestMemoryMiB > 0 { | ||
memoryRequestMiB = odigosConfig.Spec.CollectorGateway.RequestMemoryMiB | ||
} | ||
|
||
// the memory limiter hard limit is set as 50 MiB less than the memory request | ||
memoryLimiterLimitMiB := memoryRequestMiB - defaultMemoryLimiterLimitDiffMib | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB > 0 { | ||
memoryLimiterLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB | ||
} | ||
|
||
memoryLimiterSpikeLimitMiB := memoryLimiterLimitMiB * defaultMemoryLimiterSpikePercentage / 100.0 | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB > 0 { | ||
memoryLimiterSpikeLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB | ||
} | ||
|
||
gomemlimitMiB := int(memoryLimiterLimitMiB * defaultGoMemLimitPercentage / 100.0) | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.GoMemLimitMib != 0 { | ||
gomemlimitMiB = odigosConfig.Spec.CollectorGateway.GoMemLimitMib | ||
} | ||
|
||
return &memoryConfigurations{ | ||
memoryRequestMiB: memoryRequestMiB, | ||
memoryLimiterLimitMiB: memoryLimiterLimitMiB, | ||
memoryLimiterSpikeLimitMiB: memoryLimiterSpikeLimitMiB, | ||
gomemlimitMiB: gomemlimitMiB, | ||
} | ||
} |
This file contains 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
Oops, something went wrong.