Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 849
Hesey Avatar asked Aug 14 '11 10:08

Hesey


People also ask

What is default buffer size in Java?

stream with a default 512-byte buffer size. Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size.

What is the default size of the buffer?

It uses the following algorithm to determine the default size of the cursor buffer: If one row fits in a 4096-byte buffer, the default buffer size is 4096 bytes (4 kilobytes). If the size of one row exceeds 4096 bytes, the default buffer size is the size of that row.

What is the default buffer size used by any buffered class?

Initializes a new instance of the BufferedStream class with a default buffer size of 4096 bytes.

What is download buffer size?

Buffer size means the time to store data from Network temporarily while downloading.


1 Answers

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.

like image 170
fvu Avatar answered Oct 24 '22 18:10

fvu