We are working to reduce the latency and increase the performance of a process written in Java that consumes data (xml strings) from a socket via the readLine() method of the Bu
Will the inputReader.readLine() method return as soon as it hits the \n character or will it wait till the buffer is full?
Is there a faster of picking up data from the socket than using a BufferedReader?
BufferedReader entails some copying of the data. You could try the NIO apis, which can avoid copying, but you might want to profile before spending any time on this to see if it really is the I/O that is the bottleneck. A simpler quick fix is to add a BufferedInputStream
around the socket, so that each read is not hitting the socket (It's not clear if InputStreamReader does any buffering itself.) e.g.
new BufferedReader(new InputStreamReader(new BufferedInputStream(in)))
What happens when the size of the input string is smaller than the size of the Socket's receive buffer?
What happens when the size of the input string is bigger than the size of the Socket's receive buffer?
To sum up, BufferedReader blocks only when absolutely necessary.