rb: Tweak the benchmark to allow running the server in a separate process

Add a thin server library that can be run by hand


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669021 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/benchmark/fairness.rb b/lib/rb/benchmark/fairness.rb
index 67543f3..a032013 100644
--- a/lib/rb/benchmark/fairness.rb
+++ b/lib/rb/benchmark/fairness.rb
@@ -31,6 +31,7 @@
   end
 
   def self.start_server(serverClass, trans = nil)
+    return if serverClass == Object
     handler = BenchmarkHandler.new
     processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
     transport = trans || ServerSocket.new(HOST, PORT)
@@ -49,6 +50,7 @@
   end
 
   def self.shutdown
+    return if @server.nil?
     if @server.respond_to? :shutdown
       @server.shutdown
     else
diff --git a/lib/rb/benchmark/thin_server.rb b/lib/rb/benchmark/thin_server.rb
new file mode 100644
index 0000000..e7640a2
--- /dev/null
+++ b/lib/rb/benchmark/thin_server.rb
@@ -0,0 +1,25 @@
+$:.unshift File.dirname(__FILE__) + '/../lib'
+require 'thrift'
+require 'thrift/server/nonblockingserver'
+$:.unshift File.dirname(__FILE__) + "/gen-rb"
+require 'BenchmarkService'
+HOST = 'localhost'
+PORT = 42587
+
+class BenchmarkHandler
+  # 1-based index into the fibonacci sequence
+  def fibonacci(n)
+    seq = [1, 1]
+    3.upto(n) do
+      seq << seq[-1] + seq[-2]
+    end
+    seq[n-1] # n is 1-based
+  end
+end
+
+handler = BenchmarkHandler.new
+processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
+transport = Thrift::ServerSocket.new(HOST, PORT)
+transportFactory = Thrift::FramedTransportFactory.new
+Thrift::NonblockingServer.new(processor, transport, transportFactory).serve
+