Skip to content

Queue size variables#59

Open
maximk-1 wants to merge 2 commits into
nginx-modules:masterfrom
maximk-1:queue_size_variables
Open

Queue size variables#59
maximk-1 wants to merge 2 commits into
nginx-modules:masterfrom
maximk-1:queue_size_variables

Conversation

@maximk-1
Copy link
Copy Markdown

@maximk-1 maximk-1 commented Apr 23, 2026

Added $cache_purge_queue_size/$cache_purge_queue_max_size to track queue size in logs or metrics.

@maximk-1
Copy link
Copy Markdown
Author

To be honest, I'm not familiar in nginx module development and this PR was fully vibecoded with claude.

@maximk-1 maximk-1 marked this pull request as draft April 23, 2026 15:02
@maximk-1 maximk-1 marked this pull request as ready for review April 23, 2026 15:12
@denji
Copy link
Copy Markdown
Member

denji commented Apr 24, 2026

Architectural Alternative: Status Handler

Exposing global shared-memory state via per-request variables can be risky.

Recommendation: Instead of variables, consider implementing a dedicated status handler (similar to src/http/modules/ngx_http_stub_status_module.c).

Benefits: This allows external monitoring tools (like Prometheus or Datadog) to scrape the queue metrics at a fixed interval (e.g., every 5 seconds) rather than forcing NGINX to calculate and log the data for every single request. This keeps the request path clean and provides the same level of observability.

Status-handler shape is cleaner for production observability. NGINX’s own stub_status module is explicitly a small endpoint for scraping basic status data, and it also exposes embedded variables for that purpose. That makes a dedicated /status location a better fit for queue metrics than pushing the data through every request.

So the best compromise is probably: keep the variables for ad hoc debugging, but add a dedicated status endpoint for real monitoring. That keeps the request path simple while still giving operators the visibility they need. Also, the fact that NGINX modules commonly register embedded variables during module init, like ngx_http_upstream does, means the variable approach is architecturally acceptable; it is just not the lowest-overhead observability surface.

@denji denji self-requested a review April 24, 2026 06:32
@denji denji force-pushed the queue_size_variables branch from 506953a to b63e1f9 Compare April 24, 2026 06:44
@maximk-1
Copy link
Copy Markdown
Author

imho variables are more flexible as they can be used in own handlers, like basic return 200 $cache_purge_queue_size; inside location or in nginx-lua-prometheus handlers.

@maximk-1 maximk-1 force-pushed the queue_size_variables branch from b63e1f9 to 506953a Compare April 28, 2026 07:42
…variables

Register two read-only nginx variables via postconfiguration hook:

- $cache_purge_queue_size: live atomic read of queue->size
- $cache_purge_queue_max_size: plain read of queue->max_size (immutable)

Both return "-" when background purge is disabled. Covered by tests
7 and 8 in t/background_queue.t.
@maximk-1 maximk-1 force-pushed the queue_size_variables branch from 506953a to be59e9e Compare April 28, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants