java - Sockets: BufferedOutputStream or just OutputStream? -


in order fastest transfer speeds on tcp in java, better:

option a:

inputstream in = socket.getinputstream(); outputstream out = socket.getoutputstream(); 

option b:

bufferedinputstream in = new bufferedinputstream(socket.getinputstream()); bufferedoutputstream out = new bufferedoutputstream(socket.getoutputstream()); 

i've read performance takes hit when writing on 8 kib outputstream, recommended it'd written in small chunks not pver 8 kib @ time. 8 kib default buffer size of bufferedoutputstream.

however i've read when transfering data on net it's flush out bytes possible. meaning using buffer , writing in small chunks adds unneeded overhead.

so, option or option b? works best?

right i'm guessing option gives highest transfer speeds while consuming lot more cpu option b. option b might better since doesn't go slower saves lot of cpu.

--

bonus question: idea touch tcp window size? example setting 64 kib:

socket.setreceivebuffersize(65536); socket.setsendbuffersize(65536); 

i tried setting 128 kib on test machine since read increase speeds when server got couple of connections cpu @ 100% instead of ~2% when left alone. guess 128 kib way high unless you've got server can handle rush in traffic, smart set 32 kib? think default 8 kib there me.

("socket" "java.net.socket")

i don't know read nonsense front. more write @ time tcp connection better, , more read @ time ditto. use buffered stream, reader, or writer between application , socket streams. there cases ssl directly writing byte @ time can cause 40x data explosion.

is idea touch tcp window size? example setting 64 kib

you can't 'touch tcp window size'. can increase maximum value via apis mention, , indeed idea.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -