Anonymous
Производительность asio::async_read для многих файлов
Сообщение
Anonymous » 17 ноя 2024, 17:44
Я тестирую последнюю автономную версию Asio (asio-1.30.2) для асинхронного чтения большого количества файлов (~17000) в каталоге и всех подкаталогах, и я вижу ужасную производительность, когда это делается асинхронным способом (по сравнению с обычным путь).
Код: Выделить всё
// All necessary includes
static constexpr const char* DIR = "";
static constexpr size_t DATA_SIZE = 16 * 1024;
asio::io_context io_context;
asio::strand strand = asio::make_strand(io_context);
template
void hash(Iter begin, Iter end, uint32_t& hash) {
for (auto it = begin; it != end; it++) {
hash += *it;
}
}
std::vector start_threads(int num_threads) {
std::vector threads;
for (int i = 0; i < num_threads; ++i) {
threads.emplace_back([]() { io_context.run(); });
}
return threads;
}
asio::awaitable read_file_async(std::string fileName)
{
asio::stream_file file{ strand, fileName, asio::stream_file::flags::read_only };
std::array data;
uint32_t h = 0;
for (;;) {
auto [ec, n] = co_await asio::async_read(file, asio::buffer(data), asio::transfer_at_least(data.size()), asio::as_tuple(asio::use_awaitable));
if (!ec) {
hash(data.begin(), data.begin() + n, h);
}
else if (ec == asio::error::eof) {
hash(data.begin(), data.begin() + n, h);
co_return;
}
else {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79196298/asioasync-read-performance-for-many-files[/url]
1731854679
Anonymous
Я тестирую последнюю автономную версию Asio (asio-1.30.2) для асинхронного чтения большого количества файлов (~17000) в каталоге и всех подкаталогах, и я вижу ужасную производительность, когда это делается асинхронным способом (по сравнению с обычным путь). [code]// All necessary includes static constexpr const char* DIR = ""; static constexpr size_t DATA_SIZE = 16 * 1024; asio::io_context io_context; asio::strand strand = asio::make_strand(io_context); template void hash(Iter begin, Iter end, uint32_t& hash) { for (auto it = begin; it != end; it++) { hash += *it; } } std::vector start_threads(int num_threads) { std::vector threads; for (int i = 0; i < num_threads; ++i) { threads.emplace_back([]() { io_context.run(); }); } return threads; } asio::awaitable read_file_async(std::string fileName) { asio::stream_file file{ strand, fileName, asio::stream_file::flags::read_only }; std::array data; uint32_t h = 0; for (;;) { auto [ec, n] = co_await asio::async_read(file, asio::buffer(data), asio::transfer_at_least(data.size()), asio::as_tuple(asio::use_awaitable)); if (!ec) { hash(data.begin(), data.begin() + n, h); } else if (ec == asio::error::eof) { hash(data.begin(), data.begin() + n, h); co_return; } else { std::cout Подробнее здесь: [url]https://stackoverflow.com/questions/79196298/asioasync-read-performance-for-many-files[/url]