oxen-io / oxen-mq

Communications layer used for both the Oxen storage server and oxend
https://oxen.io
BSD 3-Clause "New" or "Revised" License
19 stars 35 forks source link

Optimizations #76

Closed jagerman closed 2 years ago

jagerman commented 2 years ago

This currently allows approximately 30% better throughput on tiny jobs (when the proxy thread is the bottleneck).

Broken down commit-by-commit.

Testing using:

#include <oxenmq/oxenmq.h>
#include <chrono>

std::atomic<int64_t> did{0};

using namespace std::literals;

int main() {

    constexpr auto target_jobs = 2'000'000;

    oxenmq::OxenMQ omq;
    omq.set_general_threads(4);
    omq.start();

    auto start = std::chrono::system_clock::now();
    while (true) {
        int64_t target = did + 1000;
        for (int i = 0; i < 1000; i++) {
            omq.job([] { did++; });
        }
        while (did < target)
            std::this_thread::sleep_for(1ms);
        if (target >= target_jobs)
            break;
    }

    std::chrono::duration<double> elapsed{std::chrono::system_clock::now() - start};
    std::cout << "Elapsed: " << elapsed.count() << " for " << target_jobs << " jobs (" << (target_jobs / elapsed.count()) << "/s)\n";
}