-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
misc: Improve OutputBufferManager initialization #11350
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for meta-velox canceled.
|
velox/exec/OutputBufferManager.cpp
Outdated
return instance_; | ||
std::weak_ptr<OutputBufferManager> OutputBufferManager::getInstance( | ||
const Options* optionsPtr) { | ||
auto options = optionsPtr ? *optionsPtr : Options(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We lose some check to make sure no new option is passed in if the instance is already created. On the other hand, it seems OutputBufferManager::initialize
is not used anywhere. Maybe just drop the option parameter altogether?
Also I don't see why it needs to be a weak_ptr
. Should just return const shared_ptr<OutputBufferManager>&
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Yuhta I have updated the code to
std::shared_ptr<OutputBufferManager> OutputBufferManager::getInstance() {
static std::shared_ptr<OutputBufferManager> instance =
std::make_shared<OutputBufferManager>(Options());
return instance;
}
Appreciate your review again!
velox/exec/OutputBufferManager.cpp
Outdated
instance_ = std::make_shared<OutputBufferManager>(Options()); | ||
} | ||
return instance_; | ||
std::shared_ptr<OutputBufferManager> OutputBufferManager::getInstance() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can return const std::shared_ptr<OutputBufferManager>&
to avoid a copy and atomic add (thus cache invalidation).
189aea0
to
67d13ea
Compare
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@yingsu00 CI is red. Please, take a look. We need a green CI to merge. |
CI is green now. Thanks for porting it. |
Thanks for working on this! |
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@yingsu00 Seeing failures in Prestissimo. If this change is not backwards compatible it needs to be fixed.
|
I'll send a PR to Presto repo to fix this. |
Draft Presto PR: prestodb/presto#23970. How do you want to proceed? |
@yingsu00 We cannot merge Velox PR that breaks Prestissimo. The changes need to be made in backward-compatible manner. |
@mbasmanova Thanks for the examples, but could you elaborate a bit how to follow these examples? Since Also I don't quite understand why merging this PR would break Presto given that Presto needs to advance Velox version to pick up this change. Presto won't break unless someone else advances Velox for Presto without merging prestodb/presto#23970 together. To avoid that situation, I will add "Advance Velox" change to prestodb/presto#23970 once I get the hash after this change is merged to Velox. Do you think if it works this way? Or do you have other suggestions? Appreciate it if you could elaborate more. Thanks! |
@ManManson @mbasmanova @Yuhta Can anyone provide some advice how to proceed? Thank you! |
The most straightforward way would be to split the work into several pieces as follows:
|
Cool! Thanks for the idea @ManManson. I have updated this PR to the state of 1) as you suggested. Please re-review. |
@ManManson @Yuhta Will you folks be able to review this PR again? |
velox/exec/OutputBufferManager.cpp
Outdated
const std::shared_ptr<OutputBufferManager>& | ||
OutputBufferManager::getInstanceStrong() { | ||
static const std::shared_ptr<OutputBufferManager> instance = | ||
std::make_shared<OutputBufferManager>(Options()); | ||
return instance; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OutputBufferManager::getInstance()
should be implemented in terms of getInstanceStrong()
. Something like this:
std::weak_ptr<OutputBufferManager> OutputBufferManager::getInstance() {
return getInstanceStrong();
}
Otherwise it will break any existing consumer of Velox since getInstance()
and getInstanceStrong()
would return different instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you @ManManson ! @Yuhta @mbasmanova Do you have other comments? If not I'm marking this PR to be "ready-to-merge" again. Once this one is merged I'll send follow up PRs as @ManManson suggested. |
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@yingsu00 Ying, would you rebase so we can try landing this PR? |
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@yingsu00 Thank you for rebasing. Seeing CI failures. Would you take a look? |
@mbasmanova Thanks for importing it! The test failures seems to be caused by #11737 which was exported and not reviewed. #11743 is supposed to fix it. We can wait it to be merged first then I'll rebase again. |
Starting from C++11, the C++ standard guarantees that the initialization of function-local static variables is thread-safe. This is better than using a global mutex, especially for subsequent getInstance() calls. This is because the overhead of using a static local variable only needs to do a simple check to see if the variable has already been initialized, while for the global mutex case, all getInstance() calls need to aquire this lock exclusively.
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
CI is still red. |
hi @mbasmanova All tests pass now except the Facebook internal ones: Facebook Internal - Builds & Tests: I'm unable to view them though. Would it be possible to show me what the warnings are? I can fix them once I know what's wrong. Thank you! |
Starting from C++11, the C++ standard guarantees that the initialization
of function-local static variables is thread-safe. This is better than
using a global mutex, especially for subsequent getInstance() calls. This
is because the overhead of using a static local variable only needs to do
a simple check to see if the variable has already been initialized, while
for the global mutex case, all getInstance() calls need to aquire this
lock exclusively.