Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

early redirector

 Please enter the commit message for your changes. Lines starting
  • Loading branch information...
commit 7e16c6f9da8d0954605ac45e134b697d4c244a44 1 parent 9dc52a3
BuzzTroll authored
View
7 cumulus/cb/pycb/cbPosixBackend.py
@@ -206,9 +206,10 @@ def next(self):
def read(self, size=None):
if size == None:
- return self.file.read(self.blockSize)
- else:
- return self.file.read(size)
+ size = self.blockSize
+
+ #return ''.join(['a' for x in xrange(size)])
+ return self.file.read(size)
# def readline(self, size=None):
# def readlines(self, size=None):
View
27 cumulus/cb/pycb/cbRedirector.py
@@ -32,18 +32,41 @@ def __init__(self, parser):
self.connection_count = 0
self.host_file = parser.get("load_balanced", "hostfile")
self.max = int(parser.get("load_balanced", "max"))
+ self.last_host_ndx = 0
def new_connection(self, request):
h = None
self.connection_count = self.connection_count + 1
if self.connection_count > self.max:
- h = self.get_next_host()
+ h = self.get_hosts_min()
return h
def end_connection(self, request):
self.connection_count = self.connection_count - 1
+
+ def get_hosts_min(self):
+ try:
+ hosts = []
+ f = open(self.host_file, "r")
+ for l in f.readlines():
+ hosts.append(l.strip())
+ f.close()
+
+ self.last_host_ndx = self.last_host_ndx + 1
+ if self.last_host_ndx >= len(hosts):
+ self.last_host_ndx = 0
+ h = hosts[self.last_host_ndx]
+ pycb.log(logging.INFO, "redirect last host ndx = %d redir = %s" % (self.last_host_ndx, h))
+ my_host = "%s:%d" % (pycb.config.hostname, pycb.config.port)
+ if h == my_host:
+ h = None
+ return h
+
+ except Exception, ex:
+ pycb.log(logging.ERROR, "get next host error %s" % (str(ex)))
+ return None
- def get_next_host(self):
+ def get_next_host_random(self):
try:
hosts = []
f = open(self.host_file, "r")
View
2  cumulus/cb/pycb/cumulus.py
@@ -113,7 +113,7 @@ def next_request_id(self):
# object
def request_object_factory(self, request, user, path, requestId):
- pycb.log(logging.INFO, "path %s" % (path))
+ pycb.log(logging.INFO, "New request on %s path %s" % (pycb.config.hostname, path))
# handle the one service operation
if path == "/":
if request.method == 'GET':
Please sign in to comment.
Something went wrong with that request. Please try again.