Heroku Worker Monitoring

November 11, 2020

Getting Started With Heroku Worker Monitoring

Worker dynos allow your app to offload time-consuming and resource-intensive tasks as background jobs. This, in turn, enables the web-facing component of your app to focus on receiving requests and dispatching responses with minimal delay. This means that worker processes play a key role in helping scale app performance.

Heroku worker monitoring needs to be included in your overall Heroku visibility strategy. This short post helps you get started with Heroku worker monitoring by walking you through the following topics:

  • Optimizing worker dynos
  • Understanding worker performance metrics
  • Monitoring worker performance metrics with Heroku add-ons

With the Hosted Graphite add-on for Heroku, monitoring every critical process in your app (including worker dynos and background jobs) is as easy as just installing the add-on. The add-on lets you leverage Graphite’s time-series data management capabilities and Grafana’s data visualization features with minimal configuration. 

The HG Heroku monitoring add-on will automatically build your Heroku dashboards for you, check it out:

Screenshot of Hosted Graphite's auto generated Heroku Dashboard


Optimizing worker dynos

While there are many different factors that drive app performance, it often boils down to two main things: latency and throughput. Latency measures how long it takes for your app to process a request, while throughput tells you how many requests your app can simultaneously process.

Worker dynos reduce latency by handling tasks that don’t need to take place within a single request-response cycle. They handle tasks that can block the request-response cycle and free up resources, so that your app can accommodate more requests, thus increasing throughput. In a scalable setup, background tasks run inside dynos that do not handle web processes (i.e., do not handle HTTP requests).

But a worker process will have a positive effect on app performance only if it’s operating as expected. That’s why there’s a clear need to gain visibility on the performance of worker dynos as well.


Understanding worker performance metrics

While worker dynos carry out a different function than web dynos, they’re still subject to similar performance and resource constraints. That’s why worker dynos have almost the same set of key performance metrics you need to keep track of.

Heroku Labs’ log-runtime-metrics include the following metrics for both worker and web dynos:

  • cpu.load_avg_15m
  • cpu.load_avg_1m
  • cpu.load_avg_5m
  • memory.memory_cache
  • memory.memory_pgpgin
  • memory.memory_pgpgout
  • memory.memory_quota
  • memory.memory_rss
  • memory.memory_swap
  • memory.memory_total

These metrics are collected and reported on a per-dyno basis for all dynos in the app. If not available, you may need to enable log-runtime-metrics with the following CLI command:

$ heroku labs:enable log-runtime-metrics

Monitoring worker performance metrics with Heroku add-ons

The fastest way to get started with Heroku worker monitoring is by using a full-featured monitoring tool like the Hosted Graphite add-on. Hosted Graphite lets you begin monitoring your app without any complicated installation or configuration steps. You only need to attach it to your app by running:

$ heroku addons:create hostedgraphite

This initiates the metric-collection process on your app. The add-on then publishes the collected data points to the Hosted Graphite dashboard where the metrics are displayed in Grafana charts.

By default, Hosted Graphite collects and forwards a base set of metrics about the overall app infrastructure. When the log-runtime-metrics are enabled in your app, the add-on monitors a number of other performance metrics per process type (including worker processes).

The screenshot below shows the names of the worker metrics collected by the add-on from a Flask web app with one worker dyno. This is taken from the metrics search page in the Hosted Graphite dashboard.

Screenshot of Hosted Graphite's metric search function in Metric Search tab

You can then use the collected metrics to build custom Grafana data visualizations or set alerts when a metric reaches a given threshold (such as when the memory usage in a worker dyno exceeds the memory quota).

Conclusion

Heroku worker monitoring is easier and more effective when you’re looking at the right metrics and using the right tools.

That’s why you get onto the HG Heroku add-on to see if it’s right for you. If you need further details on how the add-on helps boost the performance of your dynos, you can communicate with us directly through our intercom. You can find our intercom chat on either the Hosted Graphite home page or inside the add-on. We respond within 5 minutes!


Related Posts

No items found.

See why thousands of engineers trust Hosted Graphite with their monitoring

START A FREE TRIAL