Skip to content

Phase 4: Persistent Connections (Keep-Alive) #52

@mgrossmann

Description

@mgrossmann

Implement HTTP/1.1 persistent connections. Biggest performance win — reduces TCP handshakes for multi-resource page loads by 80%+.

Description

REQUEST_VERSION evaluation, idle timeout, request counter, worker pool exhaustion mitigation.

Files to edit

  • src/httprese.c — Evaluate REQUEST_VERSION: HTTP/1.1 + no Connection: close → keepalive=1; HTTP/1.0 + Connection: keep-alive → keepalive=1; else → keepalive=0. If keepalive: transition to CSTATE_IN instead of CSTATE_CLOSE. Increment request_count, close if >= keepalive_max. Reset per-request state but keep socket open.
  • src/httpin.c — Add idle timeout between requests using selectex() with configurable timeout. No data within keepalive_timeout → CSTATE_CLOSE.
  • src/httpresp.c — Send Connection: keep-alive or Connection: close header based on keepalive state.
  • include/httpd.h — Add keepalive (UCHAR), request_count (USHRT) to HTTPC (existing unused bytes). Add cfg_keepalive_timeout, cfg_keepalive_max to HTTPD.

Worker pool exhaustion mitigation

  • Short idle timeout (5s default)
  • keepalive_max limit (100 requests)
  • Worker pool auto-scales (mintask → maxtask)

Acceptance criteria

  • Browser DevTools show connection reuse (single TCP for HTML+CSS+JS+images)
  • Connection closes after keepalive_timeout idle
  • Connection closes after keepalive_max requests
  • HTTP/1.0 clients get Connection: close
  • Worker pool does not deadlock under 9+ concurrent connections
  • mvsMF works identically (no changes needed)

Notion task: TSK-8

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions