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

Unusually High CPU While Fetching Mirrors #1389

Closed
tresf opened this issue Mar 20, 2017 · 13 comments
Closed

Unusually High CPU While Fetching Mirrors #1389

tresf opened this issue Mar 20, 2017 · 13 comments

Comments

@tresf
Copy link
Contributor

tresf commented Mar 20, 2017

I'm noticing 80-100% CPU utilization during the fetching process for mirrors (Server 2016 Core Eval).

Is anyone else experiencing this? Is there an inefficiency in the CUI download indicator, or is this a bug specific to the OS/VM technology that I am on?

It doesn't seem to cause any major problems in a development environment, but for a production system, this risks the chance of stealing the resources from elsewhere. May be all or part of the cause for the Anti-Malware executable acting up mid-install (e.g. possibly related to #1388).

@rrelmy
Copy link
Collaborator

rrelmy commented Mar 20, 2017

I noticed that downloads are significantly slower with scoop than with a browser. I have ~10% CPU (maybe 1 of 8 HT cores?) usage on the powershell process.
Seems more than it should be. Need to investigate

@deevus
Copy link
Member

deevus commented Mar 20, 2017 via email

@tresf
Copy link
Contributor Author

tresf commented Mar 21, 2017

I've found that commenting out the download cursor logic fixes the CPU spikes introduced with the [========> 23%] download indicator. There are still a few other spikes, but this is a good start.

The cursor draw routine must have an expensive call in it although I think it can be improved anyway.
https://github.com/lukesampson/scoop/blob/master/lib/install.ps1#L215-L252

If I'm reading this correctly:

  • The download indicator is updated with the buffer; each 2,048 B
  • If my math is correct... A 100 MB package = yields 48,828 executions (1e+8 / 2048) of the draw routine.
  • Assuming we're interested in 0%-100% indicator, this means on average, each percent of a 100MB download is drawn about 500 times.

I've never done CUI/CLI interface coding before, so I'm not prepared to write up a PR just yet, but I think drawing the indicator less often will help remedy this problem. There are likely other indicators that could benefit from less frequent updates as well if the CPU spikes correlate/indicate ("other indicators" is purely speculative, sorry).

@deevus
Copy link
Member

deevus commented Mar 21, 2017 via email

deevus added a commit that referenced this issue Mar 22, 2017
deevus added a commit that referenced this issue Mar 22, 2017
@tresf
Copy link
Contributor Author

tresf commented Mar 23, 2017

There are still some serious performance problems with the download process.

I've upgraded and confirmed I have 01d9b95 in lib\install.ps1

Please see right-most edge...

With L201 $last = dl_onProgress $totalRead $last
image

Without L201 $last = dl_onProgress $totalRead $last
image

@deevus
Copy link
Member

deevus commented Mar 23, 2017 via email

@deevus deevus reopened this Mar 23, 2017
@tresf
Copy link
Contributor Author

tresf commented Mar 23, 2017

I changed it to 1 second (1000 ms) same problem.

@deevus
Copy link
Member

deevus commented Mar 23, 2017

Perhaps it has to do with the number of times the event is thrown, regardless of how often we draw to the screen.

@deevus
Copy link
Member

deevus commented Mar 23, 2017

I'm probably not the best person to test this, because my machine is a beast (i7-5820k /w 64GB RAM) whereas you're running a laptop i7

@deevus
Copy link
Member

deevus commented Mar 23, 2017

What if you do call $last = dl_onProgress $totalRead $last but you make the function just return?

@tresf
Copy link
Contributor Author

tresf commented Mar 23, 2017

Perhaps it has to do with the number of times the event is thrown, regardless of how often we draw to the screen.

I think it's a factor, but it's not a smoking gun. Yes, this still exposes the performance problems, but so does moving the $delta directly into the while {...}.

I was able to eradicate it by using a KB counter (e.g. byte.length * 100), but on slow connections with very small packages (e.g. awk), it doesn't really show enough progress (the timer is the ideal solution).

Still trying things....

tresf added a commit to tresf/scoop that referenced this issue Mar 23, 2017
@tresf
Copy link
Contributor Author

tresf commented Mar 23, 2017

@deevus I've created a PR #1394 which seems to fix the problem. It appears many things can spike the CPU of powershell.exe, namely

  1. New date instantiations/millis math.
  2. Frequent function calls -- even if empty
  3. Frequent screen updates.

By using a stopwatch directly within the while { ... } loop, it seems to fix the problem.

I blindly reverted your 01d9b95 but there is a formatting change that gets reverted. Let me know if you need that back in.

For a visual...

Before #1394
image

After #1394
image

@deevus deevus closed this as completed in f1673ee Mar 23, 2017
@ghost
Copy link

ghost commented Apr 28, 2020

Oh this ticket is tree years old and I have exact two issues.
i installed it today, slow downloading and hight cpu usage.

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

No branches or pull requests

3 participants