Why default buffer size is 8k in Java IO?
Asked Answered
N

1

9

The default buffer size is 8k in BufferedWriter of somewhere else. Why use 8k? Does larger buffer size improve the performance?

Nicholas answered 14/8, 2011 at 10:48 Comment(0)
P
6

The buffer reduces the number of write system calls and thereby optimizes the output. Depending on your program's activity a bigger write buffer may improve performance, it's always best to test with a bigger buffer with a workload comparable to what your program does. Also, the buffer's importance is higher when the underlying filesystem's cache is write-through (no write cache), because a write-behind cache will delay/group the physical write operations anyways.

I think the historical reason for the 8k is related to the traditional allocation sizes on disk, often 2k or a multiple thereof.

Polynuclear answered 14/8, 2011 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.