[Swift-commit] r2848 - in usertools/cio: bin libexec

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Apr 8 17:38:46 CDT 2009


Author: aespinosa
Date: 2009-04-08 17:38:45 -0500 (Wed, 08 Apr 2009)
New Revision: 2848

Modified:
   usertools/cio/bin/chtget.rb
   usertools/cio/bin/chtput.rb
   usertools/cio/libexec/hashserver.rb
Log:
Reimplemented hash service using raw TCP sockets.  DRb support
was removed.  Typical torus requests now takes 10-20 milliseconds


Modified: usertools/cio/bin/chtget.rb
===================================================================
--- usertools/cio/bin/chtget.rb	2009-04-08 14:12:19 UTC (rev 2847)
+++ usertools/cio/bin/chtget.rb	2009-04-08 22:38:45 UTC (rev 2848)
@@ -1,16 +1,13 @@
-#!/home/espinosa/local/bin/ruby
+#!/usr/bin/env ruby
 
-require 'drb'
+# Script: chtget.rb [file] [hashserver_ip]
+# Description: Registers a file [file] with rank rank to the hash service
+#              [hashserver_ip]
 
-DRb.start_service
-cht = DRbObject.new(nil, 'druby://10.128.0.0:9000')
+require 'socket'
 
-#cht.put("/x/y", 0)
-#cht.put("/x/z", 0)
-#cht.put("/x/a", 3)
-#cht.put("/x/b", 2)
-#cht.put("/x/c", 2)
-#cht.put("/x/d", 2)
+client = TCPSocket.new(ARGV[1], 9000)
 
-  puts cht.get(ARGV[0])
-
+client.print("get #{ARGV[0]}\n")
+puts client.read
+client.close

Modified: usertools/cio/bin/chtput.rb
===================================================================
--- usertools/cio/bin/chtput.rb	2009-04-08 14:12:19 UTC (rev 2847)
+++ usertools/cio/bin/chtput.rb	2009-04-08 22:38:45 UTC (rev 2848)
@@ -1,16 +1,12 @@
-#!/home/espinosa/local/bin/ruby
+#!/usr/bin/env ruby
 
-require 'drb'
+# Script: chtput.rb [file] [rank] [hashserver_ip]
+# Description: Registers a file [file] with rank rank to the hash service
+#              [hashserver_ip]
 
-DRb.start_service
-cht = DRbObject.new(nil, 'druby://10.128.0.0:9000')
+require 'socket'
 
-#cht.put("/x/y", 0)
-#cht.put("/x/z", 0)
-#cht.put("/x/a", 3)
-#cht.put("/x/b", 2)
-#cht.put("/x/c", 2)
-puts ARGV[0]
-puts ARGV[1]
-cht.put(ARGV[0], ARGV[1])
+client = TCPSocket.new(ARGV[2], 9000)
 
+client.print "put #{ARGV[0]} #{ARGV[1]}"
+client.close

Modified: usertools/cio/libexec/hashserver.rb
===================================================================
--- usertools/cio/libexec/hashserver.rb	2009-04-08 14:12:19 UTC (rev 2847)
+++ usertools/cio/libexec/hashserver.rb	2009-04-08 22:38:45 UTC (rev 2848)
@@ -1,26 +1,19 @@
-#!/home/espinosa/local/bin/ruby
+#!/usr/bin/env ruby
 
-require 'drb'
+require 'socket'
+require 'scanf'
 
-class HashServer
-  attr_reader :file
+server = TCPServer.new( nil, 9000 )
+file = Hash.new { |hash, key| hash[key] = Array.new }
 
-  def initialize
-    @file = Hash.new { |hash, key| hash[key] = Array.new }
+while true
+  Thread.start server.accept do |session|
+    (method, fname, rank) = session.gets.scanf "%s %s %d\n"
+    if method == "put"
+      file[fname] << rank
+    elsif method == "get"
+      session.print "#{file[fname][ rand( file[fname].size ) ]}\n"
+    end
+    session.close
   end
-
-  def put(fname, rank)
-    @file[fname] << rank
-  end
-
-  def get(fname)
-    @file[fname][ rand( @file[fname].size ) ]
-  end
-
 end
-
-server = HashServer.new
-
-DRb.start_service('druby://*:9000', server)
-DRb.thread.join
-




More information about the Swift-commit mailing list