Skip to content

Multithreading optimization #8086

@master255

Description

@master255

@arvidn I found a lot of std::thread in the code.

Creating a thread is a very expensive command. You need to optimize the creation of all threads (except for disk_io_thread_pool) using thread_pool.

Like this:

ThreadPool.hpp:
#pragma once
#include <boost/asio/thread_pool.hpp>

extern boost::asio::thread_pool mainPool;

ThreadPool.cpp:
unsigned n = std::thread::hardware_concurrency();
if (n == 0) n = 4; 

boost::asio::thread_pool pool(n);

And after:

#include "ThreadPool.hpp"
#include <boost/asio/post.hpp>

void doTask() {
    boost::asio::post(pool, []{
        ....
    });
}

This can significantly increase the speed of the library. And any of your programs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions