Recently, I am working on a statistical project about network access.
The background is that a single access device can access dozens of users, and each user may call at the same time.
To collect phone data for each user, and store historical data.
First, you need to know that each user needs to save historical data, so it is inevitable to add, delete, and query data during data persistence.
This process, especially when searching, is time-consuming.
Another important point is that we only use a thread to record data for users. That is to say, after a user's call ends, we will calculate data for the user until the end of the persistent data.
And then serve another user.
This poses a problem. When multiple users end the call at the same time, the processing process is unsatisfactory. After the first user finishes processing the call, the session is persisted, and then the second user is processed, this will cause data inaccuracy to the second user.
The solution we came up with is to separate computing from persistence. Because the computing time complexity is relatively small. The time complexity of persistence is relatively large.
So the design is
A thread only calculates the call and pushes it to the linked list after the calculation.
This linked list is like a buffer, and the input end is like the I/O of our computer.
It just means that the input table of the computer is slow and the processing is fast. On the contrary, the data is fast and the processing is slow (persistent ).
The other thread processes the list every two seconds or one second. In this way, the processing is more even.
In the list.
Uniform processing list