Optimize Windows UDP recv(WSARecvFrom), and reduces EventPollers wake-ups (epoll_wait/wepoll)#285
Closed
PioLing wants to merge 19 commits intoZLMediaKit:masterfrom
Closed
Optimize Windows UDP recv(WSARecvFrom), and reduces EventPollers wake-ups (epoll_wait/wepoll)#285PioLing wants to merge 19 commits intoZLMediaKit:masterfrom
PioLing wants to merge 19 commits intoZLMediaKit:masterfrom
Conversation
…-ups (epoll_wait/wepoll)
…-ups (epoll_wait/wepoll)
xia-chu
reviewed
Jan 4, 2026
| return ret; | ||
| } | ||
|
|
||
| ret += nread; |
src/Network/BufferSock.cpp
Outdated
| #endif | ||
| return std::make_shared<SocketRecvFromBuffer>(kPacketCount * kBufferCapacity); | ||
|
|
||
| return std::make_shared<SocketRecvFromBuffer>(kPacketCount * kBufferCapacity, is_udp ? 32 : 1); |
Member
There was a problem hiding this comment.
udp情况下,每个udp buffer 128KB, 总共32个,会造成内存浪费,应该参考SocketRecvmmsgBuffer方案,每个buffer 4K,32个共128KB
src/Network/BufferSock.cpp
Outdated
| } | ||
|
|
||
| size_t checkIndex(size_t index) const { | ||
| return index < _batch_size ? index : 0; |
Member
There was a problem hiding this comment.
这个不用判断吧? 这个逻辑都是你自己写的,又不是外部传参进来的,这个逻辑我觉得不应该存在
| std::static_pointer_cast<BufferRaw>(_buffer)->setSize(nread); | ||
| for (size_t i = 0; i < _batch_size; ++i) { | ||
| if (!_buffers[i]) { | ||
| allocBuffer(i); |
Member
There was a problem hiding this comment.
这个allocBuffer的操作应该放在recvfrom那个循环里面,没必要单独开个循环逻辑
| nread = ::recvfrom(fd, _buffers[i]->data(), _buffers[i]->getCapacity() - 1, 0, (struct sockaddr *)&_addresses[i], &len); | ||
| if (nread > 0) { | ||
| _buffers[i]->data()[nread] = '\0'; | ||
| std::static_pointer_cast<BufferRaw>(_buffers[i])->setSize(nread); |
Member
There was a problem hiding this comment.
建议_buffer直接声明为BufferRaw::Ptr 这样不需要static_pointer_cast
src/Network/BufferSock.cpp
Outdated
| ssize_t recvFromSocket(int fd, ssize_t &count) override { | ||
| ssize_t totalread = 0; | ||
| int nread = 0, retry_count = 0; | ||
| static const int MAX_RETRIES = 5; |
Contributor
Author
|
按上面的建议修改好了 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.