Bandwidth limiter uses nanosleep causing jitter, and SSL thread-local limits threading #111

Closed
opened 2026-07-21 16:20:30 +02:00 by TapTap · 1 comment
Owner

Description

Two performance issues in the I/O layer:

  1. Bandwidth limiter jitter (protocol.c:30-58): The token bucket throttle uses nanosleep() for deficit sleep. Short sleeps on a loaded system can overrun. The 65536-byte chunk size for throttling may cause burstiness.

  2. SSL thread-local statics (protocol.c:11-13): io_read_fd, io_write_fd, io_ssl are __thread statics. This works with fork()-per-connection but prevents using a thread pool on the server side without complex TLS context management.

Location

  • src/shared/protocol.c:11-13 (thread-local statics)
  • src/shared/protocol.c:30-58 (bw_throttle)

Suggested Fix

  1. Replace nanosleep with timerfd for precise bandwidth shaping, or use ppoll() with a deadline.
  2. Move IO state into a per-connection context struct passed through the call chain instead of thread-local statics.

Severity

low

Category

performance

Sub-Agent

perf-analyst (PA-6, PA-7)


This issue was automatically generated by the issue-creator agent.

## Description Two performance issues in the I/O layer: 1. **Bandwidth limiter jitter** (protocol.c:30-58): The token bucket throttle uses `nanosleep()` for deficit sleep. Short sleeps on a loaded system can overrun. The 65536-byte chunk size for throttling may cause burstiness. 2. **SSL thread-local statics** (protocol.c:11-13): `io_read_fd`, `io_write_fd`, `io_ssl` are `__thread` statics. This works with `fork()`-per-connection but prevents using a thread pool on the server side without complex TLS context management. ## Location - src/shared/protocol.c:11-13 (thread-local statics) - src/shared/protocol.c:30-58 (bw_throttle) ## Suggested Fix 1. Replace nanosleep with `timerfd` for precise bandwidth shaping, or use `ppoll()` with a deadline. 2. Move IO state into a per-connection context struct passed through the call chain instead of thread-local statics. ## Severity low ## Category performance ## Sub-Agent perf-analyst (PA-6, PA-7) --- _This issue was automatically generated by the issue-creator agent._
Author
Owner

Fixed in PR #148 — merged into main on 2026-07-29.

Fixed in PR #148 — merged into main on 2026-07-29.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#111