node.js - Running table data cumulation effectively
问题描述
The algorithm
We have a table (let’s call it status
) with status data gathered every second. By status data I mean about five columns with Boolean values.
We have another table (let’s call it status_interval
) where we cumulate the data from status
, i.e. if consecutive rows (based on timestamps) have exactly the same status data, in status_interval
we create a row with start and end timestamp and the status data. When a change in status data occurs, new row is inserted into status_interval
.
Now, currently we have 36 pairs of such tables (and we’ll have 56 in the near future), so we created a PHP script where we run serially through all these tables. We set up a cron job to run this script every 5 minutes. This setup worked good enough when we had only 24 pairs of such tables, but now it uses too much of CPU (one pair of tables runs for about 1m40s and uses 80-100% of CPU load).
So we decided to improve the algorithm (not part of this question) and port it into Node JS. And we are thinking of processing the data (each table pairs) concurrently.
Note that cumulation of the status data is not the most important process running on the server and if it fails/exits, we can safely restart it.
TL;DR
My question is: if running async functions concurrently, won’t it use too much of resources (esp the CPU)? If concurrency is not the best approach in our case, what in Node JS would be?
解决方案
推荐阅读
- java - Spring Boot 中如何将 AOP 日志保存到数据库中
- powerbi - Powerbi 数据导入不正确
- c# - C#中DTO类重命名属性的属性[JsonProperty]
- sql-server - 仅按父级排序的 T-SQL 递归查询
- node.js - 在 forEach 结束之前处理的变量
- docker - 我想在容器中打印 docker run 环境变量
- reactjs - React Datepicker - 当我绑定启用 e.preventDefault() 时显示错误的日期
- ios - CABasicAnimation 默认运行在主线程还是后台线程
- python - 求解微分方程,但出现错误提示“'Add' object is not callable”。我正在使用 Jupyter 笔记本
- python - 函数调用栈:train_function