-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: Memory stats #2162
Merged
Merged
feat: Memory stats #2162
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule helio
updated
5 files
+4 −0 | util/fibers/simple_channel.h | |
+3 −5 | util/tls/tls_engine.cc | |
+9 −3 | util/tls/tls_engine.h | |
+19 −18 | util/tls/tls_socket.cc | |
+3 −4 | util/tls/tls_socket.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2023, DragonflyDB authors. All rights reserved. | ||
// See LICENSE for licensing terms. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <atomic> | ||
|
||
#include "core/fibers.h" | ||
|
||
namespace dfly { | ||
|
||
// SimpleQueue-like interface, but also keeps track over the size of Ts it owns. | ||
// It has a slightly less efficient TryPush() API as it forces construction of Ts even if they are | ||
// not pushed. | ||
// T must have a .size() method, which should return the heap-allocated size of T, excluding | ||
// anything included in sizeof(T). We could generalize this in the future. | ||
template <typename T, typename Queue = folly::ProducerConsumerQueue<T>> class SizeTrackingChannel { | ||
public: | ||
SizeTrackingChannel(size_t n, unsigned num_producers = 1) : queue_(n, num_producers) { | ||
} | ||
|
||
// Here and below, we must accept a T instead of building it from variadic args, as we need to | ||
// know its size in case it is added. | ||
void Push(T t) noexcept { | ||
size_.fetch_add(t.size(), std::memory_order_relaxed); | ||
queue_.Push(std::move(t)); | ||
} | ||
|
||
bool TryPush(T t) noexcept { | ||
const size_t size = t.size(); | ||
if (queue_.TryPush(std::move(t))) { | ||
size_.fetch_add(size, std::memory_order_relaxed); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool Pop(T& dest) { | ||
if (queue_.Pop(dest)) { | ||
size_.fetch_sub(dest.size(), std::memory_order_relaxed); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void StartClosing() { | ||
queue_.StartClosing(); | ||
} | ||
|
||
bool TryPop(T& dest) { | ||
if (queue_.TryPop(dest)) { | ||
size_.fetch_sub(dest.size(), std::memory_order_relaxed); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool IsClosing() const { | ||
return queue_.IsClosing(); | ||
} | ||
|
||
size_t GetSize() const { | ||
return queue_.Capacity() * sizeof(T) + size_.load(std::memory_order_relaxed); | ||
} | ||
|
||
private: | ||
SimpleChannel<T, Queue> queue_; | ||
std::atomic<size_t> size_ = 0; | ||
}; | ||
|
||
} // namespace dfly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
i used core fibers because I migrated from boost fibers. let's just reference the correct include file directly
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.
That would mean using
util::fb2::SimpleChannel
instead ofdfly
, I thought that was the purpose of that file?