-
Notifications
You must be signed in to change notification settings - Fork 201
K8SPXC-1327: Make jemalloc the default memory allocator #2002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
https://perconadev.atlassian.net/browse/K8SPXC-1327 Problem: By default, standard libc allocator is used by PXC. It is often desirable to use jemalloc instead. To do so, use has to configure LD_PRELOAD environment variable. The only way to do this is through k8s secret. Solution: Extended PodSpec object with MySqlAllocator property. If it is empty, omitted or set to 'jemalloc', LD_PRELOAD env variable pointing to jemalloc library will be exported. Otherwise the default allocator will be used.
deploy/cr.yaml
Outdated
size: 3 | ||
image: perconalab/percona-xtradb-cluster-operator:main-pxc8.0 | ||
autoRecovery: true | ||
# mySqlAllocator: jemalloc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cr we have a commented option with a default value. In our doc, we will add all possible values. Also, you can add them in CRD. It is possible to add validation on CRD level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cr we have a commented option with a default value. In our doc, we will add all possible values.
Done
Also, you can add them in CRD. It is possible to add validation on CRD level.
I'm not sure I understand where and what to add.
https://perconadev.atlassian.net/browse/K8SPXC-1327 Logic simplified. LD_PRELOAD is set always via appc.Env.
pkg/pxc/app/statefulset/node.go
Outdated
appc.Env = append(appc.Env, []corev1.EnvVar{ | ||
{ | ||
Name: LD_PRELOAD_KEY, | ||
Value: ldPreloadValue, | ||
}, | ||
}...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are setting only one env var, we can simplify this using the following:
appc.Env = append(appc.Env, corev1.EnvVar{
Name: LD_PRELOAD_KEY,
Value: finalLDPreload,
})
pkg/pxc/app/statefulset/node.go
Outdated
const LD_PRELOAD_KEY = "LD_PRELOAD" | ||
const LIBJEMALLOC_PATH = "/usr/lib64/libjemalloc.so.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention is to use camel case to define constants. They can also start with lowercase given that their scope is within the if clause of 1.18
version.
We can also group them like this:
const (
ldPreloadKey = "LD_PRELOAD"
libJemalloc = "/usr/lib64/libjemalloc.so.1"
)
// Env vars are set via secret. Check if LD_PRELOAD is set. | ||
for key, value := range envVarsSecret.Data { | ||
if key == LD_PRELOAD_KEY { | ||
ldPreloadValue = string(value) | ||
break | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid this loop completely by using
if val, ok := envSecret.Data[LdPreloadKey]; ok {
ldPreload = string(val)
}
Data of secret are of type map[string][]byte
.
https://perconadev.atlassian.net/browse/K8SPXC-1327 Addressed review comments.
94ebe85
to
9b9576e
Compare
https://perconadev.atlassian.net/browse/K8SPXC-1628 Extended solution for K8SPXC-1327 to allow usage of tcmalloc.
commit: 9ccc2eb |
https://perconadev.atlassian.net/browse/K8SPXC-1327
Problem:
By default, standard libc allocator is used by PXC. It is often desirable to use jemalloc instead. To do so, use has to configure LD_PRELOAD environment variable. The only way to do this is through k8s secret.
Solution:
Extended PodSpec object with MySqlAllocator property. If it is empty, omitted or set to 'jemalloc', LD_PRELOAD env variable pointing to jemalloc library will be exported.
Otherwise the default allocator will be used.
CHANGE DESCRIPTION
Problem:
Short explanation of the problem.
Cause:
Short explanation of the root cause of the issue if applicable.
Solution:
Short explanation of the solution we are providing with this PR.
CHECKLIST
Jira
Needs Doc
) and QA (Needs QA
)?Tests
compare/*-oc.yml
)?Config/Logging/Testability