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

Reduce per-channel receive queue limit to 1024 #1179

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/impl/internals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const size_t DEFAULT_REMOTE_MAX_MESSAGE_SIZE = 65536; // Remote max message

const size_t DEFAULT_WS_MAX_MESSAGE_SIZE = 256 * 1024; // Default max message size for WebSockets

const size_t RECV_QUEUE_LIMIT = 1024 * 1024; // Max per-channel queue size
const size_t RECV_QUEUE_LIMIT = 1024; // Max per-channel queue size (messages)

const int MIN_THREADPOOL_SIZE = 4; // Minimum number of threads in the global thread pool (>= 2)

Expand Down
12 changes: 5 additions & 7 deletions src/impl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ template <typename T> class Queue {
public:
using amount_function = std::function<size_t(const T &element)>;

Queue(size_t limit = 0, amount_function func = nullptr);
Queue(size_t limit = 0, // elements (0 means no limit)
amount_function func = nullptr);
~Queue();

void stop();
Expand All @@ -50,10 +51,7 @@ template <typename T> class Queue {

template <typename T>
Queue<T>::Queue(size_t limit, amount_function func) : mLimit(limit), mAmount(0) {
mAmountFunction = func ? func : [](const T &element) -> size_t {
static_cast<void>(element);
return 1;
};
mAmountFunction = func ? func : []([[maybe_unused]] const T &element) -> size_t { return 1; };
}

template <typename T> Queue<T>::~Queue() { stop(); }
Expand All @@ -76,7 +74,7 @@ template <typename T> bool Queue<T>::empty() const {

template <typename T> bool Queue<T>::full() const {
std::lock_guard lock(mMutex);
return mQueue.size() >= mLimit;
return mLimit > 0 && mQueue.size() >= mLimit;
}

template <typename T> size_t Queue<T>::size() const {
Expand All @@ -91,7 +89,7 @@ template <typename T> size_t Queue<T>::amount() const {

template <typename T> void Queue<T>::push(T element) {
std::unique_lock lock(mMutex);
mPushCondition.wait(lock, [this]() { return !mLimit || mQueue.size() < mLimit || mStopping; });
mPushCondition.wait(lock, [this]() { return mLimit == 0 || mQueue.size() < mLimit || mStopping; });
if (mStopping)
return;

Expand Down
Loading