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

Investigate overconsumption of CPU with latest master #287

Closed
tiero opened this issue Mar 5, 2021 · 7 comments
Closed

Investigate overconsumption of CPU with latest master #287

tiero opened this issue Mar 5, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@tiero
Copy link
Collaborator

tiero commented Mar 5, 2021

You can see the change in the CPU consumption just switching from commit b3965b316a5ed37fe5ff53781dc9db6a254e34b3 to 0ab84f87237a1023258401d8e0d168f4ef59bcc9

I tried to "drop" only that commit (ie. git revert --strategy resolve 0ab84f87237a1023258401d8e0d168f4ef59bcc9), but every subsequent commit is too tangled to that, so would be better to inverstigate how to make it less expensive.

golang/go#27707
https://stackoverflow.com/questions/55367231/golang-for-select-loop-consumes-100-of-cpu

I suspect time.Sleep introdcued in the for loop is not the best strategy here

@tiero tiero added the bug Something isn't working label Mar 5, 2021
@tiero
Copy link
Collaborator Author

tiero commented Mar 5, 2021

instead of "sleeping" before inserting an observable, would be better to attach specific options to each observable that will dictate the behavior ie. when to trigger. In #276 we introduce this topic better and I think that would be the definitive solution.

@tiero
Copy link
Collaborator Author

tiero commented Mar 5, 2021

Latest master

Daemon "empty" just started

image

Daemon after funding and opening a market

image

@tiero
Copy link
Collaborator Author

tiero commented Mar 5, 2021

Commit hash b3965b316a5ed37fe5ff53781dc9db6a254e34b3

empty

image

funded market

image

@tiero
Copy link
Collaborator Author

tiero commented Mar 5, 2021

Don't ask me why, following this comment

Adding this microsecond of sleep in listenToEventChannel in blockchain_listener visibly lowered the "noise" my computer was doing. I don't have much experience on how to "demonstrate" this with pprof (cc/ @sekulicd) but pretty sure this is the problem in there.

@tiero
Copy link
Collaborator Author

tiero commented Mar 5, 2021

On a amazon ec2 the v0.2.0-rc.2 was eating 100% of container CPU all the time

Now with the latest v0.2.0-rc.3 we have a variable consumption that goes from 0.74% to max 34%. I suspect that those spikes are the ticker calling the explorer, so this makes sense.

@sekulicd
Copy link
Contributor

sekulicd commented Mar 6, 2021

@tiero u can check CPU profile by doing as follows:

  1. go tool pprof http://localhost:8024/debug/pprof/profile\?seconds\=30 -> this will profile CPU for 30 sec, do this after some time when u hear the noise.
  2. after profiling finishes type 'web' and u should see image with most intensive method calls

Another way:

  1. go tool pprof http://localhost:8024/debug/pprof/profile\?seconds\=30
  2. in ~/pprof it should be generated profile file
  3. Then u run go tool pprof -http :8080 {cpu file} -> in my case name was pprof.samples.cpu.001.pb.gz

Please find attachment of CPU profile that i did if u dont want to bother.
profile001

In picture u can see that unblindingUtxo method is 'killing' us, more precisely confidential.UnblindOutputWithKey.
Before when we had one ticker, which by default was set to 5000(5sec) we would crawl all addresses async and do unblinding and then CPU would relax, now we have ticker for each address and we constantly fetch and unblind which makes CPU work all the time. RateLImiter helps in a way that is limits to 10 calls in second(as per current configuration).

@tiero
Copy link
Collaborator Author

tiero commented Mar 31, 2021

Closing, altough we may need to lower the depenedency on many cgo calls @altafan

@tiero tiero closed this as completed Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants