From 009e9608b6f61dab87e91cb7a218f8074b8e2785 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C4=83lin-Andrei=20Burloiu?= Date: Fri, 17 Feb 2012 17:28:48 +0200 Subject: [PATCH] working at CIS-LB --- cis/cis_lb/__init__.py | 0 cis/cis_lb/cis_lb.py | 62 ++++++++++++++++++++++++++++++++++++++++++ cis/cis_lb/config.py | 6 ++++ js/jquery.ui.thumbs.js | 2 +- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 cis/cis_lb/__init__.py create mode 100755 cis/cis_lb/cis_lb.py create mode 100644 cis/cis_lb/config.py diff --git a/cis/cis_lb/__init__.py b/cis/cis_lb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cis/cis_lb/cis_lb.py b/cis/cis_lb/cis_lb.py new file mode 100755 index 0000000..e2ad381 --- /dev/null +++ b/cis/cis_lb/cis_lb.py @@ -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 index 0000000..a1a2c32 --- /dev/null +++ b/cis/cis_lb/config.py @@ -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 diff --git a/js/jquery.ui.thumbs.js b/js/jquery.ui.thumbs.js index f7d5d91..2ad30cc 100644 --- a/js/jquery.ui.thumbs.js +++ b/js/jquery.ui.thumbs.js @@ -17,7 +17,7 @@ $.widget( "ui.thumbs", { version: "1.0.0 beta", options: { // in milliseconds - period: 750, + period: 667, src: [] }, -- 2.20.1