Hesey
Hesey

Reputation: 5247

Why default buffer size is 8k in Java IO?

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

Upvotes: 9

Views: 5075

Answers (1)

fvu
fvu

Reputation: 32953

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.

Upvotes: 6

Related Questions