1. Jesper Nøhr
  2. puck

Commits

Jesper Nøhr  committed 93aaaac

adding simple benchmark, commit before making hub async

  • Participants
  • Parent commits 942530d
  • Branches default

Comments (0)

Files changed (3)

File README

View file
-Stateful remote procedure call's for python over a persistent tcp
+Stateful remote procedure calls for python over a persistent TCP
 connection.
 
-The general idea of puck is to do transperent RPC in python over
-the wire, while transfering all infomation needed. This means, that
+The general idea of puck is to do transparent RPC in python over
+the wire, while transferring all information needed. This means, that
 each time you would do a method invocation, the endpoint will be
 contacted, the method will be run and the remote stack will be
-updated, and the result sent back to the callee.
-
-Example:
-
-$ cat endpoint.py
-from puck.endpoint import Endpoint
-class Dummy(object):
-  MAX_DEPTH = 10
-  def __init__(self, depth, parent=None):
-    self.depth = depth
-    self.parent = parent
-  def dummy(self):
-    if self.depth < self.MAX_DEPTH:
-      return Dummy(self.depth + 1, self)
-    raise ValueError('Maximum depth of %d reached' % self.MAX_DEPTH)
-
-def get_dummy(depth=1):
-  return Dummy(depth)
-
-p = Endpoint('localhost', 8080)
-p.register_function(get_dummy)
-p.serve_forever()
-
-$ cat client.py
-from puck.client import Client
-c = Client('localhost', 8080)
-dummy = c.get_dummy()
-assert d.depth == 1, 'Depth was not 1'
-
-dummies = [dummy]
-for i in range(dummy.MAX_DEPTH):
-  dummies.append(dummies[-1].dummy())
-
-assert len(dummies) == dummy.MAX_DEPTH, 'Not enough dummies created'
+updated, and the result sent back to the caller.

File puck/hub.py

View file
         else:
             obj = { 'reply': 'ok.', 'objects': self.to_dict() }
 
-        print "sending", simplejson.dumps(obj)
-
         return simplejson.dumps(obj, skipkeys=True)
 
 class Hub(LineOnlyReceiver):
     REPLY_FAIL = simplejson.dumps({"reply":"fail."})
 
     def connectionMade(self):
+        self.bytes = 0
         self.stack = { }
         
     def respond(self, msg):
+        self.bytes += len(msg+"\r\n")
         return self.transport.write(msg+"\r\n")
         
     def find_command(self, meth):
             else:
                 self.respond(Hub.REPLY_FAIL)
         except Exception, e:
-            print "exc, dso is", dso
             self.respond(EndPointException(e).to_json())
             
     def connectionLost(self, reason):
         del self
             
     def __del__(self):
+        print "Stack dying, bytes sent %d, stack was %d" % (self.bytes, len(self.stack.keys()))
         self.stack = { }
          
 class HubFactory(Factory):

File tests/hghub/bench.py

View file
+#!/usr/bin/python
+import os, sys, time
+sys.path.append('../../')
+
+from mercurial import ui, hg, node
+from puck.client import PuckClient
+
+u = ui.ui(interactive=False)
+
+if __name__ == "__main__":
+
+    begin = time.time()
+
+    c = PuckClient('localhost', 8080)
+
+    print "Remote:",
+    ids = set()
+
+    for i in xrange(1, 501):
+        if (i % 100) == 0:
+            print i,
+    
+        repo = c.repository('/Users/jespern/Work/puck')
+        ctx = repo.changectx('tip')
+        assert node.short(ctx.node()) == '942530d8fd03'
+        assert repo.id not in ids
+        ids.add(repo.id)
+            
+    end = time.time()
+    
+    remote_time = (end-begin)
+    
+    print "\nExecution time: %.5f" % remote_time
+
+    begin = time.time()
+
+    print "Local:",
+
+    for i in xrange(1, 501):
+        if (i % 100) == 0:
+            print i,
+    
+        repo = hg.repository(u, '/Users/jespern/Work/puck')
+        ctx = repo.changectx('tip')
+        assert node.short(ctx.node()) == '942530d8fd03'
+            
+    end = time.time()
+    
+    local_time = (end-begin)
+    
+    print "\nExecution time: %.5f" % local_time
+    
+    print "Local speed vs. remote: %.2f%% faster" % ((remote_time/local_time)*100)
+        
+    
+