mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
helper: reduce size of buffer used by template connections (#18524)
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
This commit is contained in:
3
.changelog/18524.txt
Normal file
3
.changelog/18524.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:improvement
|
||||
template: reduce memory usage associated with communicating with the Nomad API
|
||||
```
|
||||
@@ -24,7 +24,10 @@ type BufConnWrapper struct {
|
||||
// New returns a new BufConnWrapper with a new bufconn.Listener. The wrapper
|
||||
// provides a dialer for creating connections to the listener.
|
||||
func New() (net.Listener, *BufConnWrapper) {
|
||||
ln := bufconn.Listen(1024 * 1024)
|
||||
// this buffer is sized to accept a maximum-sized Nomad Variable payload
|
||||
// (64k) with plenty of room to spare for the metadata and envelope, in a
|
||||
// single read
|
||||
ln := bufconn.Listen(1024 * 100)
|
||||
return ln, &BufConnWrapper{listener: ln}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user