Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created April 17, 2018 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamdriscoll/510724da47360d59038e95e533c37695 to your computer and use it in GitHub Desktop.
Save adamdriscoll/510724da47360d59038e95e533c37695 to your computer and use it in GitHub Desktop.
Using Scheduled endpoints and a cache rather than calling
$Schedule = New-UDEndpointSchedule -Every 1 -Second
$EverySecond = New-UDEndpoint -Schedule $Schedule -Endpoint {
$Cache:ModuleCount = (Get-Module -ListAvailable).Count
}
$moduleCount = New-UDEndpoint -Url "/moduleCount" -Endpoint {
(Get-Module -ListAvailable).Count
}
$CachedModuleCount = New-UDEndpoint -Url "/cached-moduleCount" -Endpoint {
$Cache:ModuleCount
}
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDCounter -Title "Test" -Id "Counter" -Endpoint {
$Cache:ModuleCount
} -AutoRefresh -RefreshInterval 1
}
PS C:\Users\adamr> measure-command { 1..100 | % { Invoke-RestMethod http://localhost:10001/api/cached-moduleCount } }
Days : 0
Hours : 0
Minutes : 0
Seconds : 29
Milliseconds : 50
Ticks : 290500385
TotalDays : 0.000336227297453704
TotalHours : 0.00806945513888889
TotalMinutes : 0.484167308333333
TotalSeconds : 29.0500385
TotalMilliseconds : 29050.0385
PS C:\Users\adamr> measure-command { 1..100 | % { Invoke-RestMethod http://localhost:10001/api/moduleCount } }
Days : 0
Hours : 0
Minutes : 12
Seconds : 55
Milliseconds : 253
Ticks : 7752531632
TotalDays : 0.00897283753703704
TotalHours : 0.215348100888889
TotalMinutes : 12.9208860533333
TotalSeconds : 775.2531632
TotalMilliseconds : 775253.1632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment