Home > Backend Development > PHP Tutorial > Get data every 10 seconds and find the average of 8640 times of data in a day. Is there any good algorithm?

Get data every 10 seconds and find the average of 8640 times of data in a day. Is there any good algorithm?

WBOY
Release: 2016-08-27 09:06:54
Original
1227 people have browsed it

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!

Reply content:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template