Skip to content

[Architecture] Migrating thread-per-connection to libev : DB Layer Blocking Strategy #31

@dreamer-00

Description

@dreamer-00

Context

I am opening this issue to discuss the architectural approach for the GSoC '26 project: Implementing event-driven concurrency in OLTP test tool (DBT-5).

While tracing the connection flow in the BrokerageHouse module, I mapped out the current concurrency model and wanted to align on the strategy for handling the database layer before drafting a PoC patch.

Current State

Currently, the listener accepts a socket, and entryWorkerThread() spawns a detached workerThread() per connection. Each thread maintains its own DB connection and blocking receive loop.

The libev Refactor & The Bottleneck

A straightforward refactor to libev would replace the pthread_create path with per-connection ev_io watchers, moving the socket I/O entirely into the event loop.

The architectural challenge: The transaction handlers ultimately invoke synchronous, blocking database calls. If these are executed directly inside the libev event callback, a single slow DB query will block the entire event loop, freezing all other network I/O.

Discussion: Direction for the DB Layer

To prevent the event loop from blocking, how are we envisioning the database layer transition?

Are we leaning toward:

  1. Fully Asynchronous: A transition toward asynchronous DB drivers (e.g., using non-blocking calls like PQsendQuery if targeting PostgreSQL directly, wrapping them in their own libev watchers).
  2. Hybrid Thread-Pool Model: libev strictly handles network I/O (accepting connections and reading/writing buffers), but dispatches the actual blocking DB transactions to a bounded, fixed-size worker thread pool.

Would love to get the maintainers' thoughts on which direction aligns best with the long-term goals for DBT-5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions