-
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 all 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -948,10 +948,6 @@ class RdbSaver::Impl { | |
// Multi entry compression is available only on df snapshot, this will | ||
// make snapshot size smaller and opreation faster. | ||
CompressionMode compression_mode_; | ||
|
||
struct Stats { | ||
std::atomic<size_t> pulled_bytes{0}; | ||
} stats_; | ||
}; | ||
|
||
// We pass K=sz to say how many producers are pushing data in order to maintain | ||
|
@@ -1041,26 +1037,19 @@ error_code RdbSaver::Impl::ConsumeChannel(const Cancellation* cll) { | |
continue; | ||
|
||
DVLOG(2) << "Pulled " << record->id; | ||
stats_.pulled_bytes.fetch_add(record->value.size(), memory_order_relaxed); | ||
|
||
io_error = sink_->Write(io::Buffer(record->value)); | ||
if (io_error) { | ||
break; | ||
} | ||
} while ((record = records_popper.TryPop())); | ||
} // while (records_popper.Pop()) | ||
|
||
size_t pushed_bytes = 0; | ||
for (auto& ptr : shard_snapshots_) { | ||
ptr->Join(); | ||
pushed_bytes += ptr->pushed_bytes(); | ||
} | ||
|
||
DCHECK(!record.has_value() || !channel_.TryPop(*record)); | ||
|
||
VLOG(1) << "Channel pulled bytes: " << stats_.pulled_bytes.load(memory_order_relaxed) | ||
<< " pushed bytes: " << pushed_bytes; | ||
|
||
return io_error; | ||
} | ||
|
||
|
@@ -1103,31 +1092,24 @@ void RdbSaver::Impl::Cancel() { | |
// This function is called from connection thread when info command is invoked. | ||
// All accessed variableds must be thread safe, as they are fetched not from the rdb saver thread. | ||
size_t RdbSaver::Impl::GetTotalBuffersSize() const { | ||
std::atomic<size_t> pushed_bytes{0}; | ||
std::atomic<size_t> channel_bytes{0}; | ||
std::atomic<size_t> serializer_bytes{0}; | ||
size_t pulled_bytes = stats_.pulled_bytes.load(memory_order_relaxed); | ||
|
||
auto cb = [this, &pushed_bytes, &serializer_bytes](ShardId sid) { | ||
auto cb = [this, &channel_bytes, &serializer_bytes](ShardId sid) { | ||
auto& snapshot = shard_snapshots_[sid]; | ||
pushed_bytes.fetch_add(snapshot->pushed_bytes(), memory_order_relaxed); | ||
channel_bytes.fetch_add(snapshot->GetTotalChannelCapacity(), memory_order_relaxed); | ||
serializer_bytes.store(snapshot->GetTotalBufferCapacity(), memory_order_relaxed); | ||
Comment on lines
+1098
to
1101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think we can do it without hops now (if the state doesn't change in-between) 🤔 But I think it doesn't matter for a monitoring command |
||
}; | ||
|
||
if (shard_snapshots_.size() == 1) { | ||
cb(0); | ||
} else { | ||
shard_set->RunBriefInParallel([&](EngineShard* es) { cb(es->shard_id()); }); | ||
// Note that pushed bytes and pulled bytes values are fetched at different times, as we need to | ||
// calc the pushed bytes using RunBriefInParallel. | ||
// pulled bytes might be higher untill we return here from RunBriefInParallel. | ||
} | ||
size_t total_bytes = pushed_bytes.load(memory_order_relaxed) + | ||
serializer_bytes.load(memory_order_relaxed) - pulled_bytes; | ||
VLOG(2) << "pushed_bytes:" << pushed_bytes.load(memory_order_relaxed) | ||
<< " serializer_bytes: " << serializer_bytes.load(memory_order_relaxed) | ||
<< " pulled_bytes: " << pulled_bytes << " total_bytes:" << total_bytes; | ||
|
||
return total_bytes; | ||
VLOG(2) << "channel_bytes:" << channel_bytes.load(memory_order_relaxed) | ||
<< " serializer_bytes: " << serializer_bytes.load(memory_order_relaxed); | ||
return channel_bytes.load(memory_order_relaxed) + serializer_bytes.load(memory_order_relaxed); | ||
} | ||
|
||
void RdbSaver::Impl::FillFreqMap(RdbTypeFreqMap* dest) const { | ||
|
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
Oops, something went wrong.
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?