[{"content":" Notes ","date":"5 April 2026","externalUrl":null,"permalink":"/","section":"","summary":"","title":"","type":"page"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/tags/benchmarks/","section":"Tags","summary":"","title":"Benchmarks","type":"tags"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/tags/c++/","section":"Tags","summary":"","title":"C++","type":"tags"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/tags/concurrency/","section":"Tags","summary":"","title":"Concurrency","type":"tags"},{"content":" Overview # StudentDbPostgress is a multi-level concurrency benchmark comparing five architectures in C++ and Go against PostgreSQL. The project measures how different concurrency models behave under controlled network latency, injected via macOS dummynet on an M2 MacBook Pro (16GB).\nI coded Level 1 entirely myself. For subsequent levels, I used Claude for architectural design while writing the implementation code.\nWhy This Project Exists # Most concurrency benchmarks measure throughput in ideal conditions. Real systems operate over networks with non-trivial latency. This project injects controlled TCP latency using macOS dummynet to observe how concurrency models degrade under realistic conditions, not just how fast they run in a vacuum.\nArchitecture Levels # Level 1: Single-Threaded Baseline # Sequential request processing. One connection, one query at a time. This establishes the floor for all comparisons. Every millisecond of added latency maps directly to throughput loss with no amortization.\nLevel 2: Thread-Per-Connection # Each incoming request spawns a dedicated thread with its own PostgreSQL connection. Simple to implement, expensive to scale. Thread creation overhead and context switching costs become measurable above ~100 concurrent connections.\nLevel 3: Connection Pool with Worker Threads # A fixed pool of database connections shared across worker threads. Requests queue when all connections are busy. This isolates the cost of connection management from the cost of concurrency.\nLevel 4: Event-Driven (epoll/kqueue) # Non-blocking I/O with an event loop. A single thread multiplexes across many connections using kqueue (macOS). This measures whether eliminating thread overhead compensates for the complexity of async state management.\nLevel 5: Hybrid Architecture # Combines an event loop for I/O multiplexing with a thread pool for CPU-bound work. Requests are accepted asynchronously but dispatched to workers for database operations.\nLatency Injection # TCP latency is injected at the OS level using macOS dummynet (via dnctl and pfctl). This operates below the application layer, so the benchmark code sees the same latency characteristics as a real network hop.\n# Example: inject 5ms latency on loopback traffic to PostgreSQL port sudo dnctl pipe 1 config delay 5ms sudo pfctl -e Latency levels tested: 0ms (baseline), 1ms, 5ms, 10ms, 50ms.\nMeasurement Methodology # Each level runs a fixed workload of student record CRUD operations against PostgreSQL. Metrics collected per run:\nThroughput (operations/second) p50, p95, p99 latency CPU utilization Memory footprint Connection pool saturation (where applicable) All measurements are repeated across 5 runs per configuration. Results report median values with interquartile ranges.\nGo vs C++ Comparison # Both languages implement the same five levels against the same PostgreSQL instance. The comparison isolates runtime overhead: Go\u0026rsquo;s goroutine scheduler and garbage collector vs C++\u0026rsquo;s manual memory management and OS threads (or custom thread pools).\nGo\u0026rsquo;s goroutines are expected to outperform C++ raw threads at high concurrency counts due to M:N scheduling, but C++ connection pool implementations should close the gap at the architectures where pooling dominates.\nCurrent Status # Level 1 (single-threaded baseline) is complete for both C++ and Go. Levels 2 through 5 are in design/implementation. Results and Excalidraw architecture diagrams will be added as each level is benchmarked.\nRepository # Source code: github.com/zarouz/StudentDbPostgress\n","date":"5 April 2026","externalUrl":null,"permalink":"/notes/concurrency-benchmark/","section":"Notes","summary":"","title":"Designing PostgreSQL Architectures That Scale","type":"notes"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/tags/go/","section":"Tags","summary":"","title":"Go","type":"tags"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/notes/","section":"Notes","summary":"","title":"Notes","type":"notes"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/tags/postgresql/","section":"Tags","summary":"","title":"PostgreSQL","type":"tags"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/tags/systems-programming/","section":"Tags","summary":"","title":"Systems Programming","type":"tags"},{"content":"","date":"5 April 2026","externalUrl":null,"permalink":"/tags/","section":"Tags","summary":"","title":"Tags","type":"tags"},{"content":"","externalUrl":null,"permalink":"/authors/","section":"Authors","summary":"","title":"Authors","type":"authors"},{"content":"","externalUrl":null,"permalink":"/categories/","section":"Categories","summary":"","title":"Categories","type":"categories"},{"content":"","externalUrl":null,"permalink":"/series/","section":"Series","summary":"","title":"Series","type":"series"}]