What is a good algorithm for obtaining data every 10 seconds and calculating the average value of 8640 data entries per day?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.