Reputation: 23
I tested the performance of GServer by implementing the most basic server and checked how many requests per second it could handle. The result was 81. This is 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 this 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? }
TCPSocket server implementaion:
require 'socket'
server = TCPServer.open(1234)
loop {
client = server.accept
puts client.gets
client.puts( 'a' )
client.close
}
Upvotes: 2
Views: 1351
Reputation: 1621
You should get a significant speedup (approximately 30x from my testing) by replacing
loop { break if server.stopped? }
with
server.join
That being said, GServer uses threads and will probably be slower than a single-threaded event-based server.
Upvotes: 5