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

Request for comment on this line #55

Open
rkarthick opened this issue Jun 29, 2022 · 1 comment
Open

Request for comment on this line #55

rkarthick opened this issue Jun 29, 2022 · 1 comment

Comments

@rkarthick
Copy link

Thank you so much for your work on this tool.

Could you please add a comment to this line?

const maxBufferCap = 262144

Is it to ensure buffer cap is bounded? Curious to understand if you have seen an issue in production that triggered this change.

Thanks!

@Fusl
Copy link

Fusl commented Oct 16, 2022

redcon temporarily buffers all written data in w.b (a []byte, not an actual bytes.Buffer) of the Writer before writing it to the client during a Flush() operation. maxBufferCap is to ensure that if the temporary internal buffer ever grows above 256KiB, memory from this buffer is afterwards released again during a next run of the garbage collector:

// Flush writes all unflushed Write* calls to the underlying writer.
func (w *Writer) Flush() error {
	if w.err != nil {
		return w.err
	}
	_, w.err = w.w.Write(w.b)
	if cap(w.b) > maxBufferCap || w.err != nil {
		w.b = nil // <- frees memory during the next gc run
	} else {
		w.b = w.b[:0] // <- just resets the write cursor/length back to 0 without freeing memory
	}
	return w.err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants