pocketnetteam / pocketnet.core

Decentralized social network based on the blockchain
https://pocketnet.app
Apache License 2.0
109 stars 26 forks source link

Too heavy WebRepository::CollectAccountStatistic() function (5+ minutes execution) with 100% CPU load #692

Open HiHat opened 2 months ago

HiHat commented 2 months ago

Describe the bug 100% CPU utilization once a hour due to WebRepository::CollectAccountStatistic() processing which takes more than 5 minutes to complete.

To Reproduce Steps to reproduce the behavior:

  1. Run node
  2. Enable statistics logging ( pocketcoin-cli logging stat)
  3. Enable benchmarking logging ( pocketcoin-cli logging bench)
  4. Wait several hours
  5. Examine execution statistics (grep "Height-\|Web" ~/.pocketcoin/debug.log | grep ProcessNextHeight:)

Example statistics:

...
2024-04-15T06:23:18Z     - WebPostProcessor::ProcessNextHeight: 80.92ms
2024-04-15T06:29:52Z     - WebPostProcessor::ProcessNextHeight: 363978.11ms
2024-04-15T06:29:52Z     - WebPostProcessor::ProcessNextHeight: 187.70ms
...
2024-04-15T07:21:09Z     - WebPostProcessor::ProcessNextHeight: 1.85ms
2024-04-15T07:28:51Z     - WebPostProcessor::ProcessNextHeight: 358967.93ms
2024-04-15T07:28:51Z     - WebPostProcessor::ProcessNextHeight: 339.76ms
...
2024-04-15T08:27:32Z     - WebPostProcessor::ProcessNextHeight: 172.40ms
2024-04-15T08:34:23Z     - WebPostProcessor::ProcessNextHeight: 361021.17ms
2024-04-15T08:34:23Z     - WebPostProcessor::ProcessNextHeight: 7.62ms
...

Desktop (please complete the following information):

andyoknen commented 2 months ago

Thanks for the comment! I am aware of the problem and I am thinking about optimizing these functions - it is necessary to collect statistics in a cumulative way, instead of counting every time for everyone.

HiHat commented 2 months ago

Sometimes it prevents node shutdown too...

andyoknen commented 2 months ago

Yes, the node cannot close until all active database connections are closed - this is necessary to preserve the integrity of the database.