working at CIS-LB
authorCălin-Andrei Burloiu <calin.burloiu@gmail.com>
Fri, 17 Feb 2012 15:28:48 +0000 (17:28 +0200)
committerCălin-Andrei Burloiu <calin.burloiu@gmail.com>
Fri, 17 Feb 2012 15:28:48 +0000 (17:28 +0200)
cis/cis_lb/__init__.py [new file with mode: 0644]
cis/cis_lb/cis_lb.py [new file with mode: 0755]
cis/cis_lb/config.py [new file with mode: 0644]
js/jquery.ui.thumbs.js

diff --git a/cis/cis_lb/__init__.py b/cis/cis_lb/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/cis/cis_lb/cis_lb.py b/cis/cis_lb/cis_lb.py
new file mode 100755 (executable)
index 0000000..e2ad381
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+import sys
+import urllib
+import web
+import time
+import threading
+from Queue import Queue
+
+# Located in the parent directory; execute from that location or put it in PYTHONPATH
+import logger
+import config
+
+
+class LBWorker(threading.Thread):
+    """
+    Load Balancing Worker: chooses a CIS where the request should be forwarded
+    or broadcasts the requests to all CIS machines if required.
+    """
+    
+    def __init__(self, id):
+        """
+        Initialize Load Balancing Worker.
+        """
+
+        threading.Thread.__init__(self, name = 'LBWorker%02d' % id)
+    
+    def run(self):
+        
+        while True:
+            job = Server.queue.get()
+            
+            print '%s is working at %s...' % (self.name, repr(job))
+            time.sleep(10)
+            
+            Server.queue.task_done()
+
+
+class Server:
+    
+    def POST(self, request):
+        
+        Server.queue.put( ('POST', request, web.data()) )
+        
+        #return web.data()
+
+if __name__ == '__main__':
+    
+    Server.queue = Queue()
+    
+    # Create job threads.
+    lb_workers = []
+    for i in range(0, config.JOB_THREADS_COUNT):
+        lb_worker = LBWorker(i)
+        lb_worker.daemon = True
+        lb_worker.start()
+        lb_workers.append(lb_worker)
+    
+    # Web service.
+    urls = ('/(.*)', 'Server')
+    app = web.application(urls, globals())
+    app.run()
diff --git a/cis/cis_lb/config.py b/cis/cis_lb/config.py
new file mode 100644 (file)
index 0000000..a1a2c32
--- /dev/null
@@ -0,0 +1,6 @@
+
+# Number of threads which execute load balancing jobs through LBWorker class.
+JOB_THREADS_COUNT = 5
+# Number of threads controlled by job which make HTTP requests.
+# NOTE: Total number of threads is JOB_THREADS_COUNT * HTTP_THREADS_COUNT.
+HTTP_THREADS_COUNT = 5
\ No newline at end of file
index f7d5d91..2ad30cc 100644 (file)
@@ -17,7 +17,7 @@ $.widget( "ui.thumbs", {
        version: "1.0.0 beta",
        options: {
                // in milliseconds
-               period: 750,
+               period: 667,
                src: []
        },