chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.24k stars 898 forks source link

Fast method for checking if a version of a package is installed. #1226

Open AlexisColes opened 7 years ago

AlexisColes commented 7 years ago

Hi there,

Please let me know if I am missing something but i am using the following powershell to check to see if a package is installed or not.

choco list -lo | Where-object { $_.ToLower().StartsWith("SomeName".ToLower()) }
if($result -ne $null){
$parts = $result.Split(' ');
    return $parts[1] -eq $this.Version;
}
return $false;

However "choco list -lo" is taking 2-3 seconds to give me a list of about 5 installed packages.

This is quite a long time if I want to check many packages on many servers and I am not sure why it needs to take so long. Is it possible to add a better function for checking if a particular version of a package is installed that returns in less that 50ms?

Cheers.

ferventcoder commented 7 years ago

2-3 seconds? What version of Chocolatey are you on?

ferventcoder commented 7 years ago

It should be subsecond return speed.

AlexisColes commented 7 years ago

PS C:\Users\alexis.coles.adm> choco Chocolatey v0.10.5

PS C:\Users\alexis.coles.adm> measure-command { choco list -lo }

Days : 0 Hours : 0 Minutes : 0 Seconds : 2 Milliseconds : 88 Ticks : 20885527 TotalDays : 2.41730636574074E-05 TotalHours : 0.000580153527777778 TotalMinutes : 0.0348092116666667 TotalSeconds : 2.0885527 TotalMilliseconds : 2088.5527

ferventcoder commented 7 years ago

Dumb question. How big are those nupkgs?

ferventcoder commented 7 years ago

You were a bit quicker than I was posting Measure-Command. 👍

Here are my results with 167 packages installed:

> Measure-Command { choco list -lo }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 858
Ticks             : 18589399
TotalDays         : 2.15155081018519E-05
TotalHours        : 0.000516372194444444
TotalMinutes      : 0.0309823316666667
TotalSeconds      : 1.8589399
TotalMilliseconds : 1858.9399
ferventcoder commented 7 years ago

And here from a Windows 2012R2 box that has 2GB RAM given to it:

image

Still faster than what you are seeing. Something else may be going on.

ferventcoder commented 7 years ago

There was a small bit of slow down in a lookup that was added for 0.10.4+ - #942. However, as you can see it is within reason and has no adverse linear effect.

AlexisColes commented 7 years ago

Ok here are the package sizes

C:\ProgramData\chocolatey\lib\chocolatey: 6.69 mb C:\ProgramData\chocolatey\lib\consul: 75.39 mb C:\ProgramData\chocolatey\lib\ConsulAgentService: 0.01 mb C:\ProgramData\chocolatey\lib\FileBeat: 34.51 mb C:\ProgramData\chocolatey\lib\NSSM: 1.16 mb

ferventcoder commented 7 years ago

Nupkg size, not the directory.

ferventcoder commented 7 years ago

Another consideration, you may want to ensure you have set cacheLocation in the configuration. That helps with a lot of things.

AlexisColes commented 7 years ago

Sorry my bad,

consul.nupkg: 20.4 mb ConsulAgentService.nupkg: 5.64KB FileBeat.nupkg: 7.99 mb NSSM.nupkg: 4.24 kb

ferventcoder commented 7 years ago

No worries. While package size does affect this speed, I don't see anything here in general that could cause that manner of slow down. Do you have any AV set up that may be looking at file access?

AlexisColes commented 7 years ago

Ok so I ran the following

choco config set cacheLocation c:\temp\choco

now getting the following

measure-command { choco list -lo }

Days : 0 Hours : 0 Minutes : 0 Seconds : 1 Milliseconds : 701 Ticks : 17018178

So that has made a difference!! Thanks

But I would still say that this could be a lot quicker ideally as to run through a lot of packages and computers these seconds will still add up

AlexisColes commented 7 years ago

No anti virus, this is running on windows server 2008R2 vm 4 cores 3GB of free memory disk shouldbe doing upward of 400-500iops

AlexisColes commented 7 years ago

just run on a production box on a raid array with 200K iops availability and it is a little faster.

Before set cacheLocation Seconds : 0 Milliseconds : 970

After Seconds : 0 Milliseconds : 987

not sure if that made too much difference after all

ferventcoder commented 7 years ago

That's cool. We expect perf to be under two seconds. That is what we measure that particular command to. Eventually things could get even faster, but it's still much faster than the old PowerShell version of Chocolatey.

https://twitter.com/ferventcoder/status/824639657409466368

AdmiringWorm commented 7 years ago

just wanted to say that I have similiar results as @AlexisColes's first test.

C:\Windows\system32> Measure-Command { choco list -lo }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 502
Ticks             : 25023725
TotalDays         : 2,89626446759259E-05
TotalHours        : 0,000695103472222222
TotalMinutes      : 0,0417062083333333
TotalSeconds      : 2,5023725
TotalMilliseconds : 2502,3725
ferventcoder commented 7 years ago

@AdmiringWorm how many packages for you?

AdmiringWorm commented 7 years ago

90 packages

AdmiringWorm commented 7 years ago

just to check I measured the time for a few other commands as well:

C:\Windows\system32> Measure-Command { choco list ussf -lo }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 33
Ticks             : 20337447
TotalDays         : 2,35387118055556E-05
TotalHours        : 0,000564929083333333
TotalMinutes      : 0,033895745
TotalSeconds      : 2,0337447
TotalMilliseconds : 2033,7447

C:\Windows\system32> Measure-Command { choco install ussf --noop }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 3
Milliseconds      : 840
Ticks             : 38401781
TotalDays         : 4,4446505787037E-05
TotalHours        : 0,00106671613888889
TotalMinutes      : 0,0640029683333333
TotalSeconds      : 3,8401781
TotalMilliseconds : 3840,1781

C:\Windows\system32> Measure-Command { choco uninstall ussf --noop }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 351
Ticks             : 23518853
TotalDays         : 2,72208946759259E-05
TotalHours        : 0,000653301472222222
TotalMinutes      : 0,0391980883333333
TotalSeconds      : 2,3518853
TotalMilliseconds : 2351,8853

C:\Windows\system32> Measure-Command { choco config }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 80
Ticks             : 20806844
TotalDays         : 2,40819953703704E-05
TotalHours        : 0,000577967888888889
TotalMinutes      : 0,0346780733333333
TotalSeconds      : 2,0806844
TotalMilliseconds : 2080,6844