Puma
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:
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
file includes prune_bundler
, you must add AppSignal as a runtime dependency.
Usage with preload_app!
If your puma.rb
file includes preload_app!
, some configuration is required to correctly report metrics from minutely probes. When preload_app!
is true, the minutely probes are run in the Puma primary process. In the primary process, the probes cannot access the same data that the app running in Puma workers can, reporting inaccurate or no data.
In the Puma puma.rb
config file, stop the AppSignal minutely probes in the before_fork
callback to stop the minutely probes in the Puma main process. Then, start the minutely probes in the worker process from the on_worker_boot
callback.
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.
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.
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:
Graph | Metrics | Tags |
---|---|---|
Connection backlog | puma_connection_backlog | hostname |
Pool capacity | puma_pool_capacity | hostname |
Threads | puma_threads | max running |
Worker info | puma_workers | booted count old |
Tags give you a contextual breakdown of Active job performance information. AppSignal reports the following tags for Active Job jobs:
Name | Description |
---|---|
booted | Total number of currently booted workers for this server. |
count | Number of currently running threads for this server. |
hostname | Name of the host the metric was reported from. |
max | Maximum number of configured threads for this server. |
old | Number of workers running the previous configuration/code of the server at the moment in time. Puma will phase these out as new workers start. |
running | Number 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.
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.