Last active
January 10, 2017 01:36
-
-
Save jots/c410731f43fdb8f66146d372494a582d to your computer and use it in GitHub Desktop.
This file contains 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
based on: | |
https://blog.myhro.info/2017/01/how-fast-are-unix-domain-sockets | |
get about 28K per second on crystal vs 20K on python. |
This file contains 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
require "socket" | |
server_addr = "/tmp/uds_server.sock" | |
duration = 1 | |
endtime = Time.now + duration.seconds | |
msgs = 0 | |
puts "Receiving messages..." | |
while Time.now < endtime | |
sock = UNIXSocket.new(server_addr) | |
data = sock.receive(32) | |
msgs += 1 | |
sock.close | |
end | |
puts "Received #{msgs} in #{duration} second(s)." |
This file contains 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
require "socket" | |
server_addr = "/tmp/uds_server.sock" | |
if File.exists?(server_addr) | |
File.delete(server_addr) | |
end | |
server = UNIXServer.new(server_addr) | |
puts "'Server ready." | |
while true | |
server.accept? do |socket| | |
socket.print "Hello there!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment