I have been testing the performance of reading server socket input stream. I found that reading itself has about ~9000 nano second (9 us) delay. How can I improve its performance? I have tried JAVA default buffer size and something a bit bigger than that. But its performance is not much changed. In this case, I counted every 1600 samples from the client.
Most delay is found in this line:
inputLine = in.readLine();
Here is the code of reading thread:
PrintWriter out = new PrintWriter(door.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(door.getInputStream()), 10240);
File file = new File(this.storageDirectory);
BufferedWriter save = new BufferedWriter(new FileWriter(file));
String inputLine = null;
while(Switch)
{
inputLine = in.readLine(); //I found ~9000 ns delay in this line.
save.write(inputLine);
if(iCounter==0)
StartTime = System.nanoTime();
iCounter++;
if(iCounter>=1600) //need to store them.
{
EndTime = System.nanoTime();
TimeTick = (EndTime - StartTime)/1600;
System.out.println("TimeTick is [ns]: " + TimeTick);
iCounter = 0;
}
}
Here is the result:
TimeTick is [ns]: 9241
TimeTick is [ns]: 9941
TimeTick is [ns]: 6535
.....
Here is the result without 'inputLine = in.readLine();'
TimeTick is [ns]: 0
TimeTick is [ns]: 0
TimeTick is [ns]: 1
......
How can I improve reading performance? The client is just sending random double point values upon request.
Thanks,