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

refactor: move tl_cluster_config into cluster_config.cc #4714

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

BorysTheDev
Copy link
Contributor

if you need cluster_config you don't need cluster_family now

@BorysTheDev BorysTheDev requested a review from kostasrim March 6, 2025 10:36
@BorysTheDev BorysTheDev force-pushed the place_Tl_cluster_config_in_ClusterConfig branch 2 times, most recently from ec504bc to 72697ab Compare March 6, 2025 11:30
@BorysTheDev BorysTheDev force-pushed the place_Tl_cluster_config_in_ClusterConfig branch from 72697ab to 9bd1d77 Compare March 6, 2025 11:33
@BorysTheDev BorysTheDev requested a review from romange March 7, 2025 09:25
Copy link
Contributor

@kostasrim kostasrim left a comment

Choose a reason for hiding this comment

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

Every call to Current() is a copy of the shared pointer. Is this something we are ok with ?

@@ -17,6 +17,9 @@ using namespace std;
namespace dfly::cluster {

namespace {

thread_local shared_ptr<ClusterConfig> tl_cluster_config;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand. Why is this a shared_ptr when it's a thread local ? Why do you need atomic ref count on a non concurrent (thread local) storage ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I just realized this was moved nvm. General remark, I still think shared pointer for a single thread is an antipattern + you do atomic operations on data that is not shared among threads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we share the same config between all threads

Copy link
Contributor

Choose a reason for hiding this comment

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

Then why is it a thread local ?

Copy link
Contributor

Choose a reason for hiding this comment

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

And also, each call to current now is a copy and an atomic increment. If this is used concurrently we might stall the processors (especially on NUMA). We should really use the threadlocal when we are in scope and we know that the object won't be destructed (we did that previously)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed offline


auto config = tl_cluster_config->GetConfig();
auto config = ClusterConfig::Current()->GetConfig();
Copy link
Contributor

Choose a reason for hiding this comment

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

Before, you used the thread local directly. Now you do instead: copy of the shared_ptr which increments atomically the control block/ref count and then call GetConfig(). Is there a reason for this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't need ref count and can gurantee the lifetime, why not simply return a plain pointer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't know when the life of the config will be finished. So it is the reason of shared_ptr.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine but why then is it a thread local ?

@BorysTheDev
Copy link
Contributor Author

BorysTheDev commented Mar 7, 2025

Every call to Current() is a copy of the shared pointer. Is this something we are ok with ?

yes.

@BorysTheDev BorysTheDev requested a review from kostasrim March 7, 2025 10:03
@BorysTheDev BorysTheDev merged commit d8500c9 into main Mar 7, 2025
10 checks passed
@BorysTheDev BorysTheDev deleted the place_Tl_cluster_config_in_ClusterConfig branch March 7, 2025 10:30
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.

None yet

2 participants