Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Looking at the UDP code in question in brightcove/hot-shots [1]. The createUdpTransport() function creates an object with a send() method that forwards to socket.send(), calling the underlying function with the same host and port argument each time. It seems to me that this code should call socket.connect(args.host, args.port) once instead, and skip the host and port arguments to the send() calls. Presumably this would result in just a single DNS lookup.

Bonus: the createUdpTransport() function also has a DNS cache, which the author of the article could have enabled with just "cacheDns: true". But if the library code used socket.connect(), this internal cache shouldn't be needed either.

1: https://github.com/brightcove/hot-shots/blob/564ac7bfdaaf366...



The DNS cache in hot-shots is broken. That is why we added the UDP socket options.

https://github.com/brightcove/hot-shots/issues/223


I think connect() is for TCP, at least it is in C. As UDP is stateless you have to call send() for each packet.


You can actually use connect(2) for UDP. From the manual https://man7.org/linux/man-pages/man2/connect.2.html:

> If the socket sockfd is of type SOCK_DGRAM, then addr is the address to which datagrams are sent by default, and the only address from which datagrams are received.

After that, you can use send() instead of sendmsg(), so it saves you on having to pass the host on each call to sendmsg.

It can also avoid extra DNS lookups: everything is handled for you by the kernel. See also: https://stackoverflow.com/a/51296247


Same in Java. For both TCP and UDP, you build a socket and write to that.

Actually, I don't know what happens if the DNS record expires during the connection. I would presume nothing -- that the socket will stay open with the same (possibly now invalid) destination IP until closed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: