I am building a simple java network app and I have a performance issue.
The app is very simple and contains 2 parts (source code):
- The server which is the main thread.
- The client which is new thread that has started by main.
I am trying to send a lot of small data but the maximum send rate is 50 package per second.
So In my search I have found this question with the very same problem.
When I added the Buffered stream to the output stream, the rate goes bigger (thousand per second)
In wireshark I can see the difference very nicely:
- In the slow run there is push flag and in different package the ack flag, and some ack can reach even 45 millisecond of delay, and the cpu use was very low.
- In the fast run all the package contains push and ack together and for all of then the delay is no more then 1 millisecond, and the cpu use was high.
I found also this related question that does not help.
Why is that simple line of code make so different?
And why the simple solution in java so slow?