Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically adjust state sync RAM usage #858

Merged
merged 1 commit into from
Jun 6, 2022

Conversation

bufrr
Copy link
Contributor

@bufrr bufrr commented Jun 6, 2022

Proposed changes in this pull request

Explain the changes in this pull request in order to help the project maintainers understand the overall impact of it.

Type (put an x where ever applicable)

  • Bug fix: Link to the issue
  • Feature (Non-breaking change)
  • Feature (Breaking change)
  • Documentation Improvement

Checklist

Please put an x against the checkboxes. Write a small comment explaining if its N/A (not applicable)

  • Read the CONTRIBUTION guidelines.
  • All the tests are passing after the introduction of new changes.
  • Added tests respective to the part of code I have written.
  • Added proper documentation where ever applicable (in code and README.md).
  • Code has been written according to NKN-Golang-Style-Guide

Extra information

Any extra information related to this pull request.

@bufrr bufrr requested a review from yilunzhang June 6, 2022 04:26
config/config.go Outdated
@@ -461,6 +465,15 @@ func Init() error {
Parameters.SyncMode = SyncMode
}

if Parameters.SyncStateMaxPeer == 0 {
syncStateMaxPeer := uint64(float64(memory.TotalMemory() / defaultSyncStateThreadMemory))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using uint32() instead of uint64 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -171,10 +172,14 @@ func (s *stateSync) run() error {

func (s *stateSync) startWorkerThread() {
var workerId uint32
peersNum := len(s.peers)
for workerId = 0; workerId < uint32(peersNum*concurrentSyncRequestPerNeighbor); workerId++ {
peersNum := uint32(len(s.peers))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you missing concurrentSyncRequestPerNeighbor here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

go func(workerId uint32) {
s.startWorker(s.peers[workerId%uint32(peersNum)])
s.startWorker(s.peers[workerId%workerNum])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be peersNum just in case workerNum > peersNum in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@yilunzhang yilunzhang changed the title state sync oom fix Dynamically adjust state sync RAM usage Jun 6, 2022
if workerNum > peersNum {
workerNum = peersNum
}
for workerId = 0; workerId < workerNum*concurrentSyncRequestPerNeighbor; workerId++ {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concurrentSyncRequestPerNeighbor should be moved to L175, otherwise we will have more workers than config.Parameters.SyncStateMaxPeer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not fixed yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

config/config.go Outdated
@@ -461,6 +465,15 @@ func Init() error {
Parameters.SyncMode = SyncMode
}

if Parameters.SyncStateMaxPeer == 0 {
syncStateMaxPeer := uint32(float64(memory.TotalMemory() / defaultSyncStateThreadMemory))
Parameters.SyncStateMaxPeer = uint32(syncStateMaxPeer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do type conversion here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@bufrr bufrr force-pushed the statesync-oom-fix branch 2 times, most recently from 98bc007 to 01c564c Compare June 6, 2022 05:30
@@ -171,10 +172,14 @@ func (s *stateSync) run() error {

func (s *stateSync) startWorkerThread() {
var workerId uint32
peersNum := len(s.peers)
for workerId = 0; workerId < uint32(peersNum*concurrentSyncRequestPerNeighbor); workerId++ {
peersNum := uint32(len(s.peers) * concurrentSyncRequestPerNeighbor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause L182 to use the wrong peersNum. Try something like this (you might need to fix type)

peersNum := len(s.peers)
workerNum := peersNum * concurrentSyncRequestPerNeighbor
if workerNum > config.Parameters.SyncStateMaxPeer {
 	workerNum = config.Parameters.SyncStateMaxPeer
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

config/config.go Outdated
@@ -357,6 +360,7 @@ type Configuration struct {
Mining bool `json:"Mining"`
MiningDebug bool `json:"MiningDebug"`
BeneficiaryAddr string `json:"BeneficiaryAddr"`
SyncStateMaxPeer uint32 `json:"SyncStateMaxPeer"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better rename to SyncStateMaxWorkers because concurrentSyncRequestPerNeighbor might be more than 1 in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -461,6 +465,15 @@ func Init() error {
Parameters.SyncMode = SyncMode
}

if Parameters.SyncStateMaxThread == 0 {
syncStateMaxPeer := uint32(float64(memory.TotalMemory() / defaultSyncStateThreadMemory))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L469. 470 and defaultSyncStateMaxPeer still have the old name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

@yilunzhang yilunzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@yilunzhang yilunzhang merged commit 76c335b into nknorg:master Jun 6, 2022
@bufrr bufrr deleted the statesync-oom-fix branch June 6, 2022 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants