ExNominatim.Concurrency (ExNominatim v3.0.0)

Copy Markdown View Source

Per-server concurrency limiter backed by ETS.

Tracks the number of in-flight requests per base_url using an atomic ETS counter (:ets.update_counter/3). When the limit is reached subsequent requests are rejected immediately — no blocking, no queue.

Configuration

Set max_concurrency per request or globally:

# Limit to 5 concurrent requests (non-blocking)
max_concurrency: 5

# No limit (default)
max_concurrency: :infinity

Behaviour

  • The limiter is checked before the HTTP dispatch.
  • acquire/2 atomically increments the counter and returns :ok if the slot is available, or {:error, %{code: :max_concurrency_reached}}.
  • release/1 decrements the counter after the request completes (success or failure).
  • ETS table is created lazily on first use — no supervision tree.

Summary

Functions

Acquire a concurrency slot for base_url.

Get the current in-flight count for base_url.

Release a concurrency slot for base_url.

Functions

acquire(base_url, config_opts)

Acquire a concurrency slot for base_url.

Returns :ok when the current in-flight count is below max_concurrency, or {:error, %{code: :max_concurrency_reached, descr: _}} when at capacity.

current_count(base_url)

Get the current in-flight count for base_url.

release(base_url)

Release a concurrency slot for base_url.

Decrements the in-flight counter. Safe to call even after the limiter has been disabled or if the table is empty.