Puma

AppSignal for RubyThis feature requires version 3.0.7 or higher.
PumaThis feature requires version 3.11.4 or higher.

Puma was built for speed and parallelism. Puma is a small library providing a fast and concurrent HTTP 1.1 server for Ruby web applications.

The AppSignal Ruby gem automatically inserts a listener into the Puma server; no manual setup is required.

Puma metrics plugin

The AppSignal Puma plugin will collect metrics about how Puma is operating. When AppSignal detects Puma metrics, it will create an Automated Dashboard, allowing you to monitor core metrics visually.

To enable the metrics collection, add the AppSignal plugin to your Puma configuration:

ruby
# puma.rb (or config/puma.rb) plugin :appsignal

The StatsD server bundled with the AppSignal Agent must be active for the Puma metrics plugin to work. Make sure the enable_statsd config option is not set to false.

Puma may require additional configuration to load your application's secrets, which may be necessary for AppSignal to start.

Usage with prune_bundler

If your puma.rb includes prune_bundler, you must add AppSignal as a runtime dependency.

To use Puma with prune_bundler, Puma version 4.2.0 or higher is required.

ruby
# puma.rb (or config/puma.rb) prune_bundler plugin :appsignal extra_runtime_dependencies ["appsignal"]

Secrets

If you use a library such as Rails or dotenv to manage your app's secrets and configure AppSignal, you will need to load these in your Puma configuration.

AppSignal runs a background process in Puma's main process when using the Puma plugin. The rest of your app is not loaded by default in Puma's main process (unless you use preload_app!, which may not be suitable for your app). Without additional configuration, the AppSignal config will fail to load, and AppSignal will not start.

No "on boot" hook is available in Puma to load your extra config in the main process. To load your configuration, add it to the root of your puma.rb configuration file, as in the example below.

ruby
# puma.rb (or config/puma.rb) plugin :appsignal # Add this plugin # Rails secrets # Add this line when using Rails secrets in your `config/appsignal.yml` file. require "rails" # Add this section when using dotenv for secrets management require "dotenv" Dotenv.load # or for Rails apps: require "dotenv/rails-now" Dotenv.load # Rest of your Puma config...

Hostname

This probe listens to the APPSIGNAL_HOSTNAME config option from the environment variable for the hostname tag added to all its metrics. If none is set, it will try to detect it automatically. Use the APPSIGNAL_HOSTNAME system environment variable to set the hostname if you want to change the detected hostname.

StatsD port

This probe listens to the APPSIGNAL_STATSD_PORT config option from the environment variable for the configuration of non-default StatsD ports. If the environment variable is not set, it defaults to 8125. For the Puma main process, it is required to use the environment variable; it will not read the AppSignal file configuration.

Phased restart

Puma phased restarts don't restart the main Puma process, meaning that the AppSignal background process does not get restarted either on a phased restart. If you have made changes to the AppSignal config, you will need to fully restart your Puma app afterward to have the configuration change take effect.

sh
# After changing the AppSignal config, restart using: pumactl restart # instead of: pumactl phased-restart

Automated dashboard

When AppSignal receives Puma metrics, it will create a Puma automated dashboard, available from the dashboard section of the AppSignal app.

The Puma automated dashboard will have the following graphs:

GraphMetricsTags
Connection backlogpuma_connection_backloghostname
Pool capacitypuma_pool_capacityhostname
Threadspuma_threads
  • max
  • running
  • Worker infopuma_workers
  • booted
  • count
  • old
  • Tags give you a contextual breakdown of Active job performance information. AppSignal reports the following tags for Active Job jobs:

    NameDescription
    bootedTotal number of currently booted workers for this server.
    countNumber of currently running threads for this server.
    hostnameName of the host the metric was reported from.
    maxMaximum number of configured threads for this server.
    oldNumber of workers running the previous configuration/code of the server at the moment in time. Puma will phase these out as new workers start.
    runningNumber of currently running threads for this server

    Graphs allow you to monitor your application's metrics visually. You can add markers to graphs and click on any data point to gain insights into your application's state at that time.

    Example Puma automated dashboard

    Connection backlog graph

    The Connection backlog graph shows the amount of incoming connections to the server that are waiting to be served in the server's backlog queue.

    You can use the Connection backlog graph to monitor how many requests are waiting to be handled and spot Puma bottlenecks.

    Pool capacity graph

    The Pool capacity graph shows the amount of Puma threads available to receive requests, including Puma threads that have yet to be spawned.

    You can use the Pool capacity graph to monitor the availability of Puma threads and optimize workers.

    Threads graph

    The Threads graph shows information about the threads spawned by Puma to serve web requests aggregated across all Puma workers. To serve web requests, Puma will spawn more threads when needed. The graph will show you the amount of threads running against the max available number of threads.

    You can use the Threads graph to monitor the demand and supply of Puma threads and optimize workers.

    Worker info graph

    The Worker info graph shows how many Puma workers are working and what version of your website they are using. The count line shows how many workers are working in total, while the booted and old lines show how many workers are using the new version and how many workers are using the old version of your application.

    You can use the worker info graph to monitor the status and performance of your Puma workers and see how many workers are running on an outdated configuration of your application.