HTTPS pool: profile the task-queue lock and compare against sharded / lock-free variants

Open
#353 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
c, linux

Research direction

Start by reading scripts/ci/c100k_https.sh and the HTTPS pool implementations of https_pool_submit_ready(), https_pool_submit_conn() and the worker pop. Profile the ramp, request rounds and RSS-gate load with perf record -g, then measure lock hold times at 1, 4 and 12 workers. Compare variants on the listed scenarios; done means reporting results and considering a variant only if it shows a measurable scenario-level win and passes TSan, RSS-gate and C100k.

Written by the indexing model from the issue text.

Description

Follow-up to the r/cprogramming thread about replacing the HTTPS pool's ring buffer with a lock-free queue. The thread's consensus is to measure before changing the design, and the server is mostly I/O-bound, so this issue records the measurements to make. The resize-under-mutex point raised there is fixed in 83fbff48: the new ring is allocated, and the old one freed, outside g_https_pool.mutex.

Profile first

  • perf record -g on scripts/ci/c100k_https.sh (ramp and request rounds) and on the RSS-gate load. Report how much time is spent in pthread_mutex_lock / futex on g_https_pool.mutex, against time in TLS, syscalls and the handler.
  • Measure lock hold times for https_pool_submit_ready(), https_pool_submit_conn() and the worker pop, using perf lock or bpftrace on futex. Do this at 1, 4 and 12 workers.

Scenarios to compare (same machine, same build flags)

Scenario What it stresses
C100k ramp (connect burst, 512 in-flight handshakes per client thread) submit-side contention, ring growth
C100k keep-alive rounds (100k requests in flight) park/unpark resubmits through https_pool_submit_conn()
Connection churn (ab -c 1000, no keep-alive) handshake shards to pool handoff
Small pool (CWIST_WORKERS=1, one core, like oborona.zip) queue depth and waiting, not contention

Variants

  1. Current mutex + condvar ring, with growth outside the lock (baseline).
  2. Per-shard rings (one mutex per N workers), only if (1) shows real contention.
  3. A lock-free MPMC ring, only if (2) still shows contention.

Each variant would need TSan, RSS-gate and C100k results before it is considered. The bar for (2) or (3) is a measurable win on at least one scenario above, not on a microbenchmark.

Dominant language
C
Stars
16
Forks
7
Avg merge
4h 28m
Merged PRs (30d)
191

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from c4punks/CWIST

All issues in c4punks/CWIST

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.