#26492·vector

TCP-based sources: idle connections starve busy connections (`RequestLimiter` capped at `num_threads()`)

Author: thomasqueirozbCreated Sep 28, 2026Updated Sep 28, 2026

A note for the community

  • Please vote on this issue by adding a reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Problem

All sources built on TcpSource (socket, syslog, fluent, logstash, statsd) use one RequestLimiter per source. Its number of permits is capped at crate::num_threads(), the number of available CPUs:

https://github.com/vectordotdev/vector/blob/e44fb91fa1ce822b8ce45d66ea925e497431e6d9/src/sources/util/net/tcp/mod.rs#L171-L172

A connection must hold a permit before it reads. It keeps the permit:

The semaphore is FIFO, and each turn reads at most one ReadyFrames batch (1024 frames). So one round takes about connections × hold time / permits. When many connections are quiet, a busy connection gets a turn only every few hundred ms. Its kernel receive queue fills and the sender sees a zero window, while Vector's CPU usage stays low and the downstream buffers stay empty.

Expected: the throughput of a busy connection should not depend on how many idle connections are open.

This is the same problem as #23392, which #23448 fixed for dnstap only.

Configuration

yaml
sources:
  src:
    type: socket
    mode: tcp
    address: 127.0.0.1:7010
    decoding:
      codec: bytes
    framing:
      method: octet_counting
sinks:
  out:
    type: blackhole
    inputs: [src]
    print_interval_secs: 0

For the last row of the results, add a second identical source on port 7011 and send the busy connection there.

Version

vector 0.58.0 (aarch64-apple-darwin 2bcad9b 2026-08-26 13:37:07.557544670)

Example Data

On a 16-CPU machine (16 permits): one connection sends ~100 B octet-counted frames as fast as it can, and N other connections are open.

Other connections Busy connection
0 55 MiB/s
8 56 MiB/s
16 28 MiB/s
64 idle 2.3 MiB/s
256 idle 0.66 MiB/s
750 idle 0.06–0.37 MiB/s
750, each sends one frame every 100 ms 1.2 MiB/s
750, each sends one frame every 10 ms 5.3 MiB/s
750 idle, busy connection on a separate source 52 MiB/s

Vector CPU was ~100% with no other connections (one connection uses one core) and ~7% in a run with 750 idle connections (that run also had a route transform).

The measurements match the model: 256 idle × 10 ms / 16 permits = 160 ms per round, so at most 1024 frames per 160 ms ≈ 6.4k events/s. The measured value was 6.8k events/s.

Load generator

Usage: python3 load.py <other_connections> <other_interval_secs, 0 = idle> <duration_secs> [busy_port]

python
import resource, socket, sys, threading, time

resource.setrlimit(resource.RLIMIT_NOFILE, (8192, 8192))

ADDR = ("127.0.0.1", 7010)
N_OTHER = int(sys.argv[1])
OTHER_INTERVAL = float(sys.argv[2])
DURATION = float(sys.argv[3]) if len(sys.argv) > 3 else 10.0

body = b"date=2026-09-18 time=13:17:40 devname=fgt01 type=traffic subtype=forward srcip=10.0.0.1 act=accept"
frame = str(len(body)).encode() + b" " + body
chunk = frame * (1_048_576 // len(frame))

stop = threading.Event()
others = [socket.create_connection(ADDR) for _ in range(N_OTHER)]

def trickle(s):
    while not stop.is_set():
        try:
            s.sendall(frame)
        except OSError:
            return
        stop.wait(OTHER_INTERVAL)

if OTHER_INTERVAL > 0:
    for s in others:
        threading.Thread(target=trickle, args=(s,), daemon=True).start()

time.sleep(1.0)
busy = socket.create_connection((ADDR[0], int(sys.argv[4]) if len(sys.argv) > 4 else ADDR[1]))
sent = 0
start = time.monotonic()
while time.monotonic() - start < DURATION:
    busy.sendall(chunk)
    sent += len(chunk)
elapsed = time.monotonic() - start
stop.set()
print(f"others={N_OTHER} busy={sent / elapsed / 1_048_576:.2f} MiB/s")

Additional Context

We cannot simply copy the #23448 fix (raise the cap). In dnstap a permit covers one event, and a setting (max_frame_handling_tasks) already existed. In TcpSource a permit covers a whole batch: up to 1024 frames, or a full fluent request. The CPU cap comes from the backpressure RFC ("A value higher than this has no benefit, but would use more memory"). That assumption holds only if a connection holds a permit while it does CPU work, not while it waits.

If we raise the cap, the RFC's other limit (100k events divided by the average batch size) must bound memory. With mixed traffic, many 1-event batches keep the average low, so the permit count goes up to the cap. Under backpressure, each permit keeps its decoded batch in memory. The worst case goes from num_threads × 1024 to cap × 1024 events.

Options to explore:

  1. Take a permit only when data is ready. Wait until the socket is readable, then acquire the permit. This keeps the RFC's memory bound. The wait must be skipped when FramedRead or the TLS layer already has buffered bytes, or the connection can stall.
  2. Raise the cap behind a new option, like max_frame_handling_tasks for dnstap. This is a simple change, but memory use under backpressure grows as described above.
  3. Shorten the 10 ms idle timeout. This reduces the effect but does not remove it, and it adds wakeups for every idle connection.

Workaround: put the busy senders on a separate source (port). Each source has its own limit.

References

  • Discussion #26430
  • #23392, #23448 (same problem, fixed for dnstap)
  • #11549 (10 ms idle timeout)
  • #10962 and rfcs/2022-01-06-8596-tcp-source-backpressure.md (request limiter design)