In this case, on the PHP side, data on the subserver is retrieved every 10 seconds. if the data is written to the database every time, the number of records is recorded, and the final data volume is too large, if there are 100 subservers, the performance problem is even more serious. I have considered writing redis, but if I write redis, the json string is large enough, and... in this case, on the PHP side, data on the subserver is retrieved every 10 seconds. if the data is written to the database every time, the number of records is recorded, and the final data volume is too large, if there are 100 subservers, the performance problem is even more serious. I have considered writing redis, but if I write redis, the json string is large enough, and it is troublesome to calculate the average value, do you have any good algorithm solutions? For example, you can calculate the average value over a period of time, or have any suggestions when saving data. I hope you can help me a lot. thank you!
Reply content:
In this case, on the PHP side, data on the subserver is retrieved every 10 seconds. if the data is written to the database every time, the number of records is recorded, and the final data volume is too large, if there are 100 subservers, the performance problem is even more serious. I have considered writing redis, but if I write redis, the json string is large enough, and it is troublesome to calculate the average value, do you have any good algorithm solutions? For example, you can calculate the average value over a period of time, or have any suggestions when saving data. I hope you can help me a lot. thank you!
Amount. I am too stupid. I receive data records every time, and then add new data to old data every time, and finally divide it by the total number of times. do you think this works?
Your method is okay. you can also write data in batches when saving data, such as 100 servers, read 10 times, and write 10 times in total. There is no pressure on the database to write 10 times in 10 seconds.
The subject method is correct. each time data is sent, a comment is calculated, and a counter of the total number of times is set next to it.