Skip to content
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

helper: reduce size of buffer used by template connections #18524

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

tgross
Copy link
Member

@tgross tgross commented Sep 15, 2023

In #12458 we added an in-memory connection buffer so that template runners that want access to the Nomad API for Service Registration and Variables can communicate with Nomad without having to create a real HTTP client. The size of this buffer (1 MiB) was taken directly from its usage in Vault, and each connection makes 2 such buffers (send and receive). Because each template runner has its own connection, when there are large numbers of allocations this adds up to significant memory usage.

The largest Nomad Variable payload is 64KiB, and a small amount of metadata. Service Registration responses are much smaller, and we don't include check results in them (as Consul does), so the size is relatively bounded. We should be able to safely reduce the size of the buffer by a factor of 10 or more without forcing the template runner to make multiple read calls over the buffer.

Fixes: #18508

In #12458 we added an in-memory connection buffer so that template runners that
want access to the Nomad API for Service Registration and Variables can
communicate with Nomad without having to create a real HTTP client. The size of
this buffer (1 MiB) was taken directly from its usage in Vault, and each
connection makes 2 such buffers (send and receive). Because each template runner
has its own connection, when there are large numbers of allocations this adds up
to significant memory usage.

The largest Nomad Variable payload is 64KiB, and a small amount of
metadata. Service Registration responses are much smaller, and we don't include
check results in them (as Consul does), so the size is relatively bounded. We
should be able to safely reduce the size of the buffer by a factor of 10 or more
without forcing the template runner to make multiple read calls over the buffer.

Fixes: #18508
Copy link
Member

@schmichael schmichael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also worth noting that the performance expectations here should be awfully loose anyway. No one should be pull megabytes of state through templates as those sorts of assets are much better suited for the artifacts.

@tgross tgross merged commit 5bd8b89 into main Sep 18, 2023
@tgross tgross deleted the smaller-buffer-for-template-conn branch September 18, 2023 13:12
@tgross tgross added the backport/1.6.x backport to 1.6.x release line label Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High memory usage on Nomad agent due to static buffer in template client?
2 participants