Skip to content

Conversation

@kfirtoledo
Copy link
Collaborator

This PR introduces the multithreaded worker pool (thread_pool) used by the filesystem offloading connector.
Included in this PR:

  • Adds thread_pool.cpp and thread_pool.hpp
  • Implements a lightweight work queue and task execution model
  • Enables concurrent read and write operations

Copy link
Collaborator

@orozery orozery left a comment

Choose a reason for hiding this comment

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

Nice work!

General comment:
I see very long lines throughout, which is hard to read and looks not so good :)
I think we need to add some kind of a style linter to enforce on all our codebase.

std::unique_lock<std::mutex> lock(queue_mutex);

// Reject new tasks if the pool is shutting down
if (stop) throw std::runtime_error("enqueue on stopped ThreadPool");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to reject without throwing an exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

DEBUG_PRINT("IO thread " << i << " attached to preallocated pinned buffer " << (t_pinned_buffer.size / (1024 * 1024))
<< " MB");
} else {
std::cerr << "[WARN] IO thread " << i << " has no preallocated pinned buffer\n";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is warning enough? shouldn't we fail?
Also, if any thread crashes, should not the entire pool terminate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn’t fail, because a missing preallocated buffer only affects performance, not correctness. Other threads may still have buffers, and this thread will allocate its own buffer on first use. I updated the warning comment to reflect that behavior.

Comment on lines 71 to 72
// Round-robin CPUs within the NUMA node
int cpu_id = local_cpus[i % local_cpus.size()];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this cause performance issues if threads are not evenly split across CPUs?
@dannyharnik

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code spreads threads across the NUMA-local CPUs using round-robin assignment (and falls back to all CPUs if none are found). It should keep load balanced, but I can add a TODO to evaluate the impact more deeply and consider relaxing the NUMA restriction if needed.

@kfirtoledo
Copy link
Collaborator Author

General comment: I see very long lines throughout, which is hard to read and looks not so good :) I think we need to add some kind of a style linter to enforce on all our codebase.

I added a linter in this PR "268dcf1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants