Loading…

Improving the performance of dashboards with scheduled endpoints and caching

With the 1.6.0-beta1 release, you can now create scheduled endpoints and take advantage of cached variables. Previously, variables would not persist between calls to endpoints. With cached variables, the value will persist and be available in any endpoint script block. Scheduled endpoints allow you to set endpoints to run on an interval.These endpoints will execute even when users are not viewing the dashboard. Think of them as scheduled tasks in a PowerShell dashboard. It’s a great way to collect data from systems without the user having to wait while you to do it.

Let’s look at how we can improve the performance of a dashboard using these two features.

Assume we have a dashboard that displays modules from the PowerShell Gallery. It has a UDTable that displays the module’s name, version and download count. Find-Module is called within the UDTable’s Endpoint. Every time the page is loaded this endpoint is invoked and Find-Module is called.

Querying the PowerShell Gallery with Find-Module isn’t instantaneous. You can see below that a call to find 50 SQL modules on the gallery took about 7.5 seconds.

Improving Performance

To improve the performance of the dashboard, we can take advantage of two new features of Universal Dashboard: Scheduled Endpoints and the Cache variable scope. We schedule the endpoint to run every ten minutes. This happens even when users aren’t connected to the dashboard. As long as the dashboard is running, the scheduled endpoint will run on time. Then we store that value in a cache scoped variable that we use in our endpoint.

The result is a 97% reduction is the time to execute the endpoint that displays the table. It takes just 223ms in this example. Additionally, each time a user visits the dashboard, they no longer make a call to the PowerShell Gallery. This can be really handy when calling rate limited services like GitHub.

To learn more about scheduled endpoints and caching, visit the Universal Dashboard documentation site.

Leave a Reply