Ruby GServer performance
I tested the performance of GServer by implementing the most basic server and checking how many requests per second it can handle. The result was 81. That's very slow compared to the 9900 requests per second that my most basic TCPSocket server can handle. Am I doing something wrong or is GServer really that slow?
Client implementation:
require 'socket'
tStart = Time.now
u = 0
while Time.now - tStart<5
socket = TCPSocket.open('localhost', 1234)
socket.puts 'a'
socket.gets
socket.close
u += 1
end
puts u.to_s
GServer implementation:
require 'gserver'
class JServer < GServer
def initialize(*args)
super(*args)
end
def serve( io )
io.gets
io.puts( 'a' )
end
end
server = JServer.new(1234)
server.start
loop { break if server.stopped? }
Using TCPSocket Server:
require 'socket'
server = TCPServer.open(1234)
loop {
client = server.accept
puts client.gets
client.puts( 'a' )
client.close
}
+2
source to share