Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read the footers in parallel when reading multiple Parquet files #17957

Open
wants to merge 10 commits into
base: branch-25.04
Choose a base branch
from
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ add_library(
src/utilities/cuda_memcpy.cu
src/utilities/default_stream.cpp
src/utilities/host_memory.cpp
src/utilities/host_worker_pool.cpp
src/utilities/linked_column.cpp
src/utilities/prefetch.cpp
src/utilities/stacktrace.cpp
Expand Down
32 changes: 32 additions & 0 deletions cpp/include/cudf/detail/utilities/host_worker_pool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <BS_thread_pool.hpp>

namespace cudf::detail {

/**
* @brief Retrieves a reference to the global host worker thread pool.
*
* This function returns a reference to a thread pool that can be used for executing host-only
* tasks. The pool size is potentially not optimal for tasks that include device operations, like
* copies between host and device and kernel calls.
*
* @return A reference to the host worker thread pool.
*/
BS::thread_pool& host_worker_pool();

} // namespace cudf::detail
19 changes: 15 additions & 4 deletions cpp/src/io/parquet/reader_impl_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ipc/Message_generated.h"
#include "ipc/Schema_generated.h"

#include <cudf/detail/utilities/host_worker_pool.hpp>
#include <cudf/logger.hpp>

#include <thrust/iterator/counting_iterator.h>
Expand Down Expand Up @@ -352,11 +353,21 @@ metadata::metadata(datasource* source)
std::vector<metadata> aggregate_reader_metadata::metadatas_from_sources(
host_span<std::unique_ptr<datasource> const> sources)
{
// Avoid using the thread pool for a single source
if (sources.size() == 1) { return {metadata{sources[0].get()}}; }

std::vector<std::future<metadata>> metadata_ctor_tasks;
metadata_ctor_tasks.reserve(sources.size());
for (auto const& source : sources) {
metadata_ctor_tasks.emplace_back(cudf::detail::host_worker_pool().submit_task(
[source = source.get()] { return metadata{source}; }));
}
std::vector<metadata> metadatas;
std::transform(
sources.begin(), sources.end(), std::back_inserter(metadatas), [](auto const& source) {
return metadata(source.get());
});
metadatas.reserve(sources.size());
std::transform(metadata_ctor_tasks.begin(),
metadata_ctor_tasks.end(),
std::back_inserter(metadatas),
[](std::future<metadata>& task) { return std::move(task).get(); });
return metadatas;
}

Expand Down
31 changes: 31 additions & 0 deletions cpp/src/utilities/host_worker_pool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "io/utilities/getenv_or.hpp"

#include <cudf/detail/utilities/host_worker_pool.hpp>

namespace cudf::detail {

BS::thread_pool& host_worker_pool()
{
static const std::size_t default_pool_size = std::min(32u, std::thread::hardware_concurrency());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a policy for how we choose the default threadpool size here? For a workload reading ~360 parquet files of 128 MB each, the default thread pool size of 32 might have been a little small. The overall workload took about 20 to read the data. With LIBCUDF_NUM_HOST_WORKERS=256 the overall workload took 10s. (and no parallelism, like on main, took 60s).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used 32 because it worked well for my host compression thread pool (where the tasks incude H2D/D2H copies).
I'm fine with just using hardware_concurrency, given that this is intended for host-only work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I have an Intel i9-13900K, which has 8 performance cores and 16 efficiency cores, and std::thread::hardware_concurrency() returns 32 for this. If I was reading a lot of files and my machine tried to use 32 threads, I'd have nothing available for anything else and the OS might stop responding. Perhaps 3/4 or 7/8 of hardware_concurrency() would be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thought (feel free to ignore): this will be most notable for remote file systems, we're we'll be network bound and spending a lot of time doing nothing. In Python, a single thread making all the network requests asynchronously would likely work as well as a large threadpool. Would something similar be good here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we can do the same as we do when reading the actual data - loop over all sources in a single function. This would take some surgery, but IMO it's worth a try, given that this specific use of the thread pool requires more threads than we normally want.

static const std::size_t pool_size = getenv_or("LIBCUDF_NUM_HOST_WORKERS", default_pool_size);
static BS::thread_pool pool(pool_size);
return pool;
}

} // namespace cudf::detail