background

Recently, I made an interface for the third party. The interface’s function is to receive data and verify the data and push it to the model through Kafka for data processing. Finally, I received the data through Kafka. However, after running for a period of time, the program will enter the suspended animation state, and the interface cannot be called normally.

The synchronous interface

The implementation of synchronous interface is to use blocking Map. When the other party sends a request, the data is verified and pushed to the model. After the result is returned, the processed data is pushed to the other party’s interface.

Train of thought

Began to think that is out of memory due to large users of suspended animation program, use JMeter to conduct stress tests 10000 requests call interface at the same time, the asynchronous interface simulation program as smooth running, no problem, all requests all return (here due to the server at home through the VPN connection of company development, the network is not stable, So take a few test cases);

Then I began to wonder if there was something wrong with the synchronous interface. At the beginning, I simulated a few requests, because I was testing in the development environment at that time, and the model was not put up, so there was no return information. I was waiting for the return result of the model, and there was no problem.

Thinking: all resources are blocked, because there is no processing result, has not released the process, when the data is too large will not cause the server resource exhaustion, resulting in the program false death?

When the call times of the synchronous interface are increased again, the asynchronous interface is tried to request the asynchronous interface, but the asynchronous interface also does not return information, then the problem is confirmed again.

Threads are all blocked, when too many resources are not released, the server resources are exhausted, resulting in the program can not run normally;

To solve

After finding the problem is to solve the problem, it is impossible to remove the synchronization interface, so it is necessary to set a timeout time for the blocked thread, when there is no model for a long time to process data, actively give up listening, release occupied resources, so as to ensure sufficient server resources;

thinking

Although the problem is solved, the model can produce up to 10 seconds of data. This problem still occurs when the concurrency is too large. How to solve this problem without moving the model? How do I always keep my server resourced?

The resources

Blocking the realization of the Map: songsong.iteye.com/blog/802881

Pressure test profile and JMeter simple practical: www.cnblogs.com/TankXiao/p/…