I've been wondering how buffering the stream in Java affect performance for network connections (or socket handles at the OS level). I understand buffering file handles reduces disk-access overhead but what about network connections?
Each read (suppose one byte at a time) from such input streams causes the underlying connection re-xxx something?
I really should understand this to clarify does it really worth to buffer nw connection streams since there is cost of creating internal buffer (array).
Basically, I'm trying to understand the cost/overhead of using regular streams when accessing network in particular.
Thx
A typical system call costs around 2 micro-seconds. This doesn't seem large but if you do this repeatedly i.e. once per byte it really adds up. For a packet of data you are likely to add milliseconds of overhead.
However, the memory for say an 8 KB or 32 KB or even 1 MB costs very little. i.e. the time it takes you decide whether you need a buffer is likely to cost far more, unless you have a very large number of connects i.e. > 10K.