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

Pre-bind sockets on creation #36

Closed
wants to merge 2 commits into from

Conversation

markglenn
Copy link
Contributor

When sending a datagram, non-bound sockets require a DNS lookup.
Instead, bind the socket to the given addresses when creating the
socket.

Also, lazily create the socket connections, which allows the
notify methods to capture the exceptions as expected. If the sockets
are created and bound at initialize, an exception would occur then.

Lastly, allow resetting the connections if the addresses are changed.

Fixes #31

When sending a datagram, non-bound sockets require a DNS lookup.
Instead, bind the socket to the given addresses when creating the
socket.

Also, lazily create the socket connections, which allows the
notify methods to capture the exceptions as expected.  If the sockets
are created and bound at initialize, an exception would occur then.

Lastly, allow resetting the connections if the addresses are changed.

Fixes graylog-labs#31
# Get UDPSockets that are prebound to the given addresses
def sockets
@sockets ||= addresses.map do |address|
host, port = address
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need this, you could try:

sockets ||= addresses.map do |host, port|  
  socket = UDPSocket.new
  socket.connect(host, port)
  socket
end

@markglenn
Copy link
Contributor Author

Both of these concerns are valid and would be fixed, however, I don't think this will be merged in. See #31 (comment)

@markglenn
Copy link
Contributor Author

I'm closing this since I don't believe this is the right technique because it's not safe for networks that allows the Graylog server to change IP addresses. If you believe I'm wrong, please re-open.

@markglenn markglenn closed this Jan 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GELF Benchmarks are slow vs UDP
2 participants