Skip to content

Extremely slow first response after idle period (~11 s) on GET /boxes/:id — cold start? #952

Description

@Viper780

Describe the bug

A single GET request to the OpenSenseMap API after a longer period without traffic (hours) takes about 11 seconds to respond (first byte). Subsequent requests answer in < 0.2 s (tested locally right after the slow one). This suggests a cold/idle path on the backend (e.g. MongoDB connection pool / instance cold start), not a network issue: DNS resolves in ~3 ms, TLS handshake < 50 ms, and the response is HTTP 200 once it arrives.

This is a problem for real-world clients with conservative timeouts:

  • Home Assistant's opensensemap integration (opensensemap_api 0.4.1, hard-coded aiohttp.ClientTimeout(total=5)) polls 3 stations; on every cold cycle all 3 requests time out at the same time (Unable to fetch data from openSenseMap:), so sensor values go stale for up to a polling interval.
  • Same pattern would affect any script/device with a timeout of 5–10 s.

To Reproduce

# from Vienna (Wien), 2026-09-05, api.opensensemap.org (128.176.196.25), DNS ~3 ms
# after ≥ a few hours without requests:
curl -m 60 -o /dev/null -w '%{time_total}\n' https://api.opensensemap.org/boxes/5e49643cb131a1001bb79466
# → 11.15  (first request)
curl -m 60 -o /dev/null -w '%{time_total}\n' https://api.opensensemap.org/boxes/5e49643cb131a1001bb79466
# → 0.09   (immediately again)

Observed

  • time_namelookup: 0.003 s (DNS fine)
  • time_connect / TLS: < 0.05 s (TCP/TLS fine)
  • Time to first byte: ~11 s on first request, < 0.2 s afterwards
  • HTTP 200 when it eventually answers
  • Idle threshold: 45 s idle → 0.11 s; 6 min idle → 0.17 s; ~4.5 h idle → 11.15 s
    → the slow path only kicks in after longer idle periods (hours), not minutes
  • Same behavior observed for /boxes list requests (bbox) before
  • No errors/5xx; just a very slow first response

Expected

A single box document (small JSON, existing dataset) should answer in well under 1 s even after idle. If this is a connection-pool / instance cold-start issue, options would be:

  • keepalive / pool warm-up on the backend, or
  • an always-warm instance / health probe to avoid the cold path, or
  • documenting the response-time/idle behavior for integrators.

Context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions