Add threading_performance_report.md

This commit is contained in:
2025-08-25 12:57:00 -04:00
parent 71e8fdf881
commit 36e1bf0e2d
4 changed files with 93 additions and 4 deletions

View File

@@ -67,9 +67,9 @@ struct HttpHandler : ConnectionHandler {
for (int threadId = 0; threadId < kFinalStageThreads; ++threadId) {
finalStageThreads.emplace_back([this, threadId]() {
pthread_setname_np(pthread_self(),
("stage-0-" + std::to_string(threadId)).c_str());
("stage-1-" + std::to_string(threadId)).c_str());
for (;;) {
auto guard = pipeline.acquire(0, threadId);
auto guard = pipeline.acquire(1, threadId);
for (auto it = guard.batch.begin(); it != guard.batch.end(); ++it) {
if ((it.index() % kFinalStageThreads) == threadId) {
auto &c = *it;
@@ -85,6 +85,20 @@ struct HttpHandler : ConnectionHandler {
}
});
}
stage0Thread = std::thread{[this]() {
pthread_setname_np(pthread_self(), "stage-0");
for (;;) {
auto guard = pipeline.acquire(0, 0, 0, false);
for (auto it = guard.batch.begin(); it != guard.batch.end(); ++it) {
auto &c = *it;
if (!c) {
return;
}
for (volatile int i = 0; i < 1200; i = i + 1)
;
}
}
}};
}
~HttpHandler() {
{
@@ -93,6 +107,7 @@ struct HttpHandler : ConnectionHandler {
c = {};
}
}
stage0Thread.join();
for (auto &thread : finalStageThreads) {
thread.join();
}
@@ -122,8 +137,9 @@ struct HttpHandler : ConnectionHandler {
private:
static constexpr int kFinalStageThreads = 2;
static constexpr int kLogSize = 12;
ThreadPipeline<std::unique_ptr<Connection>> pipeline{kLogSize,
{kFinalStageThreads}};
ThreadPipeline<std::unique_ptr<Connection>> pipeline{
kLogSize, {/*noop serial thread*/ 1, kFinalStageThreads}};
std::thread stage0Thread;
std::vector<std::thread> finalStageThreads;
// Route handlers