hammer v5.0.0 Hammer.Application View Source

Hammer application, responsible for starting the backend worker pools. Configured with the :hammer environment key:

  • :backend, Either a tuple of {module, config}, or a keyword-list of separate, named backends. Examples: {Hammer.Backend.ETS, []}, [ets: {Hammer.Backend.ETS, []}, ...]
  • :suppress_logs, if set to true, stops all log messages from Hammer

General Backend Options

Different backends take different options, but all will accept the following options, and with the same effect:

  • :expiry_ms (int): expiry time in milliseconds, after which a bucket will be deleted. The exact mechanism for cleanup will vary by backend
  • :pool_size (int): size of the backend worker pool
  • :pool_max_overflow int(): number of extra workers the pool is permitted to spawn when under pressure. The worker pool (managed by the poolboy library) will automatically create and destroy workers up to the max-overflow limit

Example of a single backend:

config :hammer,
  backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 2]}

Example of config for multiple-backends:

config :hammer,
  backend: [
    ets: {
      Hammer.Backend.ETS,
      [
        ets_table_name: :hammer_backend_ets_buckets,
        expiry_ms: 60_000 * 60 * 2,
        cleanup_interval_ms: 60_000 * 2,
        pool_size: 2,
        pool_max_overflow: 4
      ]
    },
    redis: {
      Hammer.Backend.Redis,
      [
        expiry_ms: 60_000 * 60 * 2,
        redix_config: [host: "localhost", port: 6379]
      ]
    }
  ]

Link to this section Summary

Functions

Called when an application is started

Link to this section Functions

Called when an application is started.

This function is called when an application is started using Application.start/2 (and functions on top of that, such as Application.ensure_started/2). This function should start the top-level process of the application (which should be the top supervisor of the application’s supervision tree if the application follows the OTP design principles around supervision).

start_type defines how the application is started:

  • :normal - used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another node and the application specification key :start_phases is :undefined.
  • {:takeover, node} - used if the application is distributed and is started on the current node because of a failover on the node node.
  • {:failover, node} - used if the application is distributed and is started on the current node because of a failover on node node, and the application specification key :start_phases is not :undefined.

start_args are the arguments passed to the application in the :mod specification key (e.g., mod: {MyApp, [:my_args]}).

This function should either return {:ok, pid} or {:ok, pid, state} if startup is successful. pid should be the PID of the top supervisor. state can be an arbitrary term, and if omitted will default to []; if the application is later stopped, state is passed to the stop/1 callback (see the documentation for the c:stop/1 callback for more information).

use Application provides no default implementation for the start/2 callback.

Callback implementation for Application.start/2.