<a id="configuration"></a>

# Configuration

*halon-bounce-classifier* loads settings from environment variables.

You can set the environment variables by using the following command.

```console
# systemctl edit halon-bounce-classifier
```

You can then add the environment variables you want to configure like below.

```default
[Service]
Environment="PORT=8000"
Environment="HOST=127.0.0.1"
```

Below are some of the most important environment variables that can be configured.

<a id="confval-PORT"></a>

## PORT

The port that the server will run on. The default is `8080`.

<a id="confval-HOST"></a>

## HOST

The IP address that the server will run on. The default is `127.0.0.1`.

> **Note**
> 
> Use `*` to listen on any IP, useful when for example running in a container

<a id="confval-SSL_CERTFILE"></a>

## SSL_CERTFILE

The path to the certificate. The default is to not use SSL.

<a id="confval-SSL_KEYFILE"></a>

## SSL_KEYFILE

The path to the private key. The default is to not use SSL.

<a id="confval-API_KEY"></a>

## API_KEY

The API key to use. The default is to not use an API key.

<a id="cache"></a>

## Cache

<a id="confval-HALON_BNAC_CACHE"></a>

### HALON_BNAC_CACHE

* **Type:**
  bool

`True` if the cache should be enabled. The default is `True`.

<a id="confval-HALON_BNAC_CACHE_STATS"></a>

### HALON_BNAC_CACHE_STATS

* **Type:**
  bool

`True` if the cache statistics should be enabled. The default is `False` since collection statistics has a small performance impact.

<a id="confval-HALON_BNAC_CACHE_FOLDER"></a>

### HALON_BNAC_CACHE_FOLDER

* **Type:**
  str

The folder where the cache is stored. The default is `/var/lib/halon/bounce-classifier`.

<a id="confval-HALON_BNAC_CACHE_SIZE"></a>

### HALON_BNAC_CACHE_SIZE

* **Type:**
  int

The cache size in bytes. The default is of approximately 100MB.

<a id="confval-HALON_BNAC_CACHE_TIMER"></a>

### HALON_BNAC_CACHE_TIMER

* **Type:**
  bool

Enables timing metrics for cache `get` and `set` operations. The default is `False`.

When enabled, `/v1/cache/stats` reports:

- `timer_enabled` as `true`
- `avg_get_time_ms`: average cache read time in milliseconds
- `avg_set_time_ms`: average cache write time in milliseconds

Set `HALON_BNAC_CACHE_TIMER=true` to enable it. Any other value keeps it disabled.

<a id="batching"></a>

## Batching

<a id="confval-HALON_BNAC_BATCH_SIZE"></a>

### HALON_BNAC_BATCH_SIZE

* **Type:**
  int

Maximum number of queued requests processed together in one server-side batch for batch endpoints (for example `/v1/bnac` and `/v2/bnac`).
This does not apply to single-request endpoints such as `/v1/bnac/single` and `/v2/bnac/single`. The default is `16`.

<a id="confval-HALON_BNAC_BATCH_WAIT_TIME"></a>

### HALON_BNAC_BATCH_WAIT_TIME

* **Type:**
  int

Batch flush interval in milliseconds. The default is `100`.
