-
Notifications
You must be signed in to change notification settings - Fork 160
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
Conversation
config/config.go
Outdated
@@ -461,6 +465,15 @@ func Init() error { | |||
Parameters.SyncMode = SyncMode | |||
} | |||
|
|||
if Parameters.SyncStateMaxPeer == 0 { | |||
syncStateMaxPeer := uint64(float64(memory.TotalMemory() / defaultSyncStateThreadMemory)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
node/stateSync.go
Outdated
go func(workerId uint32) { | ||
s.startWorker(s.peers[workerId%uint32(peersNum)]) | ||
s.startWorker(s.peers[workerId%workerNum]) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
node/stateSync.go
Outdated
if workerNum > peersNum { | ||
workerNum = peersNum | ||
} | ||
for workerId = 0; workerId < workerNum*concurrentSyncRequestPerNeighbor; workerId++ { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
98bc007
to
01c564c
Compare
node/stateSync.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this 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
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)Checklist
Please put an
x
against the checkboxes. Write a small comment explaining if itsN/A
(not applicable)Extra information
Any extra information related to this pull request.