Java IO Performance Issue

I use:

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.txt"),1024*1024*500))

to write a large file (about 2 GB). Recording takes 26 seconds. But, when I replace 500 with 10/20, it takes 19 seconds.

From here , I realized that buffering gives better performance. If so, why is this happening? I checked it by doing it 5 times each, so loading the system / I / O is not a problem.

+3
source share
6 answers

As I said in the previous question, there is an optimal buffer size (usually around 32 KB), and since you make the buffer larger than this, it is slower not faster. The default buffer size is 8 KB.

BTW: How big is your L2 / L3 processor cache? (about 10 MB I suspect) Is your main L1 cache about 32 KB?

, , . , , ( 10 ).


.

ISO-8859-1 encoding i.e (byte) ch ByteBuffer, , .

/ long double ByteBuffer .

https://github.com/peter-lawrey/Java-Chronicle/blob/master/src/main/java/vanilla/java/chronicle/impl/AbstractExcerpt.java

, 5 .

+2

. 32-64 kb IMO

+2

1024*1024*500 - 500 , smidgen. JVM 500 , JVM, , GC.

+1

(500 ) , .

. , .

, - O(n).

+1

. , 64K 8K . , , , , -, . , (min-max, ) - . -, . , , , , . - 8K-16K, , . 32K .., , . , . , 2 .

, 2 26 , 76 / 650 /. , , .

+1

- . ( , ), . :

  • 500 GC .

  • 500 , , .

Just try using a (significantly) smaller buffer. (I personally would not use a buffer larger than 8kb without doing some configuration for a specific application.)

+1
source

All Articles