Repository navigation
demo: a TPC-C-like client, one protothread per terminal - #31
Merged
Merged
Conversation
Modeled on the client in YDB's "Making Coroutines Routine", which needed 150,000 OS threads and 600 GiB before it was rewritten with C++20 coroutines. Each terminal is a protothread written as the loop a clerk follows: keying time, a transaction, think time. Each transaction is a nested function, and each query inside it sends a request to a simulated database and blocks until the reply. The database is sharded by warehouse, each shard a queue and four worker protothreads, and transactions hold row locks (protothread_lock.h) until they finish. The clock is simulated: main() jumps it to the next timer deadline, so ten minutes of 1,000 terminals take a few hundredths of a second, and a seed reproduces a run exactly. -w 10000 runs 100,000 terminals on one OS thread (about 8 s for ten simulated minutes, 52 MiB). -u drops the locks, and the read-wait-write in New-Order and Payment then loses updates, which the consistency check reports. -H starts every terminal at once. The arguments of a pt_call(), pt_sleep() included, are evaluated again each time the call resumes, so the district and the random durations are stored in the context first. Passing rnd() directly released a lock on the wrong district. Checked with ASan and UBSan, PT_SIGNAL_WAKES_ALL=1, PT_NWAIT=1, and -std=gnu99. Built by -DPROTOTHREAD_DEMOS=ON and run in CI with the other demos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR7v9BVsFrHiEhQBSqZmAs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR7v9BVsFrHiEhQBSqZmAs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds demo/tpcc.c, modeled on the client in YDB's Making Coroutines Routine. Their original client needed 150,000 OS threads and 600 GiB. Here each terminal is a protothread running the clerk's loop, each transaction is a nested function, and each query blocks until a simulated, sharded database replies. It uses the timer, queue and lock headers, with a simulated clock.
-w 10000runs 100,000 terminals on one OS thread, about 8 to 10 s of CPU and 52 MiB for 10 simulated minutes.-udrops the row locks, and the consistency check reports the lost updates.-Hstarts every terminal at once, and the peak queue depth shows the herd.The demo also makes a case for the timer heap (227b460). Against the old sorted-list timers,
-w 1000took 38 s of CPU vs 0.56 s.It's built with
-DPROTOTHREAD_DEMOS=ONaspttpcc, and CI builds and runs it with the other demos. Checked under ASan+UBSan,PT_SIGNAL_WAKES_ALL=1,PT_NWAIT=1and-std=gnu99.🤖 Generated with Claude Code
https://claude.ai/code/session_01SR7v9BVsFrHiEhQBSqZmAs