That’s it. On my PHP side, I need to obtain the data of the sub-server every 10 seconds. If I write to the database every time and record the number of times, the amount of data will be too large in the end. If there are 100 sub-servers, the performance problem will be even greater. Seriously, I have considered writing redis, but if I write redis, the json string is large enough, and it is also troublesome to calculate the average. Do you have any good algorithms to solve it? For example, you can calculate the average value after a period of time, or you have any good suggestions when saving data. I hope you can help me, thank you all!
That’s it. On my PHP side, I need to obtain the data of the sub-server every 10 seconds. If I write to the database every time and record the number of times, the amount of data will be too large in the end. If there are 100 sub-servers, the performance problem will be even greater. Seriously, I have considered writing redis, but if I write redis, the json string is large enough, and it is also troublesome to calculate the average. Do you have any good algorithms to solve it? For example, you can calculate the average value after a period of time, or you have any good suggestions when saving data. I hope you can help me, thank you all!
Uh-huh. I'm so stupid. Every time I receive data, I record the number of times, and then every time new data comes, I add it to the old data, and finally divide it by the total number of times. Does this work?
Your method is fine. In addition, when storing data, you can also write in batches. For example, 100 servers, read 10 and write once, and write 10 times in total. Writing to the database 10 times in 10 seconds puts no pressure on the database
The question method is correct. Every time data comes, a comment is calculated and a total number counter is set next to it