-
Notifications
You must be signed in to change notification settings - Fork 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
feature: support udp large packet segmentation to send multiple times… #2351
base: master
Are you sure you want to change the base?
Conversation
… , each time to send need "zero" copy on the Lua land.
README.markdown
Outdated
- [Videos](#videos) | ||
- [Synopsis](#synopsis) | ||
- [Description](#description) | ||
- [Typical Uses](#typical-uses) |
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.
please don't change the format of the doc.
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.
ok,i just know this ,sorry
size += head_len; | ||
} | ||
} | ||
// copy msg |
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.
you should use the string.buffer instead of implement this feature.
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.
how to use string.buffer instead of implement this feature on lua land ,can you give some example? the copy occurs on the c land,but i need to split the big string on the lua land ,and also i need to make the header of the udp package on lua land. if i use the origin udpsock:send() method , sub string ( big_msg ) is inevitable ,.usually i can send big string
use udp like below,there is no need to make a new string pass to c land.
for idx = 1, totalPackage do
local header_binary = struct.pack(">i2c1c32i4c1", packageSize + 42, '1', msg_id, totalPackage, zip_type or '0')
local serial_binary
if totalPackage == 1 then
serial_binary = struct.pack(">i4", 0)
else
msgEndIndex = msgStartIndex + packageSize - 1
serial_binary = struct.pack(">i4", idx - 1)
end
ok, err = udpsock:sendbuf(header_binary, serial_binary, big_msg, msgStartIndex, msgEndIndex)
---sub string use origin method
---ok, err = udpsock:send({ header_binary, serial_binary, string.sub(msg, msgStartIndex, msgEndIndex) })
msgStartIndex = msgEndIndex + 1
end
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.
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 a lot,but we can't assume that from the beginning the user can use string.buffer to build the string content on the lua land ,sometimes is really hard for it , and more scenario is that the user can only accept a large string which was already built before.
I think we still need to copy a string on lua land, event if we use the string buffer.that is because openresty only provides a udp send method which can accepts only a string or table object.
Limited by udp message size , it’s necessary to split an existing big string, so you need to avoid a new large number of substring , The new udp send method that i provided is to adapt to this scenario.
Thank you very much!
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.
gotcha
update error message
remove line tailing spaces
remove line tailing spaces
add new udp send method like this:
local ok, err = udpsock:sendbuf(udp_header_str1,udp_header_str2,udp_header_str3,...,big_body_str,start,end)
This method can send udp message without copy or split sub string in Lua land. Usually, in the udp sending scenario, you may have to split the message and send for many times when the string needed to sent is too long, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers,the copy order is like this: udp_header_str1,udp_header_str2,udp_header_str3,...,big_body_str[start,end],which usually may helps to improve your system performance.