Skip to content

Set the default read/write buffer size of Redis connection to 32KiB#3483

Merged
ndyakov merged 3 commits into
redis:masterfrom
cxljs:typo
Aug 18, 2025
Merged

Set the default read/write buffer size of Redis connection to 32KiB#3483
ndyakov merged 3 commits into
redis:masterfrom
cxljs:typo

Conversation

@cxljs

@cxljs cxljs commented Aug 17, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@ndyakov

ndyakov commented Aug 18, 2025

Copy link
Copy Markdown
Member

@cxljs thank you for updating the Readme. I am still not convinced we need that big of a buffer to be allocated on startup. If you have the time, would you investigate how the reader will compare when reading with 8kb chunks? The reader will need some refactoring, but the writer should be fine, since we know how much data we should write.

@cxljs

cxljs commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

Hello @ndyakov , I agree that the default size of 256KB is a bit large for most scenarios. The default size of the receive buffer for TCP sockets is 128KB, so in most scenarios, a value <= 128KB (or 64KB?) should be sufficient.

would you investigate how the reader will compare when reading with 8kb chunks?

I'll find some time to test it.

@cxljs

cxljs commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

I write a simple test: set a 1KB-32KB value, and use 10000 goroutines to concurrent get it.

when value size = 8KB, the result:

Concurrent get: 10000 times
ReadBufferSize: 4 KB, WriteBufferSize: 256 KB, Time taken: 871.862295ms, avg: 87.186µs
ReadBufferSize: 8 KB, WriteBufferSize: 256 KB, Time taken: 439.96525ms, avg: 43.996µs
ReadBufferSize: 16 KB, WriteBufferSize: 256 KB, Time taken: 439.775098ms, avg: 43.977µs
ReadBufferSize: 32 KB, WriteBufferSize: 256 KB, Time taken: 420.656181ms, avg: 42.065µs
ReadBufferSize: 64 KB, WriteBufferSize: 256 KB, Time taken: 500.629106ms, avg: 50.062µs
ReadBufferSize: 128 KB, WriteBufferSize: 256 KB, Time taken: 398.798537ms, avg: 39.879µs
ReadBufferSize: 256 KB, WriteBufferSize: 256 KB, Time taken: 393.967161ms, avg: 39.396µs
ReadBufferSize: 512 KB, WriteBufferSize: 256 KB, Time taken: 361.235162ms, avg: 36.123µs
ReadBufferSize: 1024 KB, WriteBufferSize: 256 KB, Time taken: 434.438915ms, avg: 43.443µs

It seems that let the read buffer size >= the average size of the value is sufficient.

@ndyakov

ndyakov commented Aug 18, 2025

Copy link
Copy Markdown
Member

@cxljs from the example I can see the WriteBufferSize was always 256? Is this a mistake when printing or you left the write buffer the same?
p.s. looks like we can aim for 32kb as a default buffer size, what do you think?

@cxljs

cxljs commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

you left the write buffer the same?

Yes, and the size of WriteBufferSize won't affect the test results.

looks like we can aim for 32kb as a default buffer size

I agree it.

cxljs added 2 commits August 18, 2025 22:43
Signed-off-by: Xiaolong Chen <fukua95@gmail.com>
Signed-off-by: Xiaolong Chen <fukua95@gmail.com>
@ndyakov

ndyakov commented Aug 18, 2025

Copy link
Copy Markdown
Member

@cxljs would you like to work on this in this branch or I can merge this one and you (or I) can work on using 32k as default and fix all docs / comments related to it ?

@cxljs

cxljs commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

I'll update it directly in this PR.

Signed-off-by: Xiaolong Chen <fukua95@gmail.com>
@cxljs cxljs changed the title update README.md Set the default read/write buffer size of Redis connection to 32KiB Aug 18, 2025

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @cxljs !

@ndyakov ndyakov merged commit e07f55b into redis:master Aug 18, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants