Concurrent client BUG repair and optimize the performance of two

A, bufferedReader reading data

If you force quit, may be empty, may report a null pointer exception when data is read using the str

str = bufferedReader.readLine()

You need to add judge

  if(str == null||Foo.COMMAND_EXIT.equalsIgnoreCase(str)){
                break;
            }

 

two,

Memory rising

cpu time consumption statistics

The most time consuming is write, readLine and println.

The two main IO output, namely System.out or System.in the IO output. Both ends of the interface is consumed, these two things, and includes a console input information output read data from the console. The reason why the data is read from the console discharged to the front, because it is among the main thread, the main thread to the cpu time allocated slightly more. However, the overall performance impact, a larger effect on the output because the output string to the screen are not to be recovered, i.e., GC and GC information does not fall on the screen, resulting in a delay GC, it leads to other the thread is waiting.

When the data cleared the console, you can find the thread has returned to normal for some time.

Memory is

This also shows the console output information will affect the performance.

Therefore, the following code is removed System.out

 

In the case of connecting 200 clients, the server will be forwarded 199 times, completed within 1.5s, about more than 20 200 * 199 / 1.5 = 26533 connections, memory, cpu although jitter That occurred per second, but generally in a stable state. Therefore, data transmission at more than 20,000 relatively healthy state is currently scheduled for 1 second.

Thread scheduling in green indicate normal operating conditions

Pink and orange indicates a state of waiting and idle.

From the point of view thread scheduling is also normal.

 

Published 174 original articles · won praise 115 · views 830 000 +

Guess you like

Origin blog.csdn.net/nicolelili1/article/details/105132976