Пример #1
0
 def __init__(self, db, qlist):
     self._qlist = qlist
     self._db = db
     self._consumers = [
         ConsumerThread(i, self._qlist[i]) for i in xrange(len(qlist))
     ]
     self._lb = LoadBalancer(len(qlist))
class BackendList:
    def __init__(self):
        self.load_balancer = LoadBalancer()
        self.current = 0

    def getserver(self):
        return self.load_balancer.get_server()
Пример #3
0
class ThreadPool(object):
    '''
        ThreadPool object which takes as a parameter a list of queue objects,
        the worker threads are created at startup and assigned a queue. The clients
        are then assigned by the load balancer and the threads pick up the
        tasks and run with it
    '''
    def __init__(self, db, qlist):
        self._qlist = qlist
        self._db = db
        self._consumers = [
            ConsumerThread(
                i,
                self._qlist[i]
            ) for i in xrange(len(qlist))
        ]
        self._lb = LoadBalancer(len(qlist))

    def start(self):
        for c in self._consumers:
            c.start()

    def submit(self, tq):
        self._qlist[tq.get_queue_index()].put(tq)

    def assign(self):
        return self._lb.assign()
Пример #4
0
 def __init__(self, db, qlist):
     self._qlist = qlist
     self._db = db
     self._consumers = [
         ConsumerThread(
             i,
             self._qlist[i]
         ) for i in xrange(len(qlist))
     ]
     self._lb = LoadBalancer(len(qlist))
Пример #5
0
class ThreadPool(object):
    '''
        ThreadPool object which takes as a parameter a list of queue objects,
        the worker threads are created at startup and assigned a queue. The clients
        are then assigned by the load balancer and the threads pick up the
        tasks and run with it
    '''
    def __init__(self, db, qlist):
        self._qlist = qlist
        self._db = db
        self._consumers = [
            ConsumerThread(i, self._qlist[i]) for i in xrange(len(qlist))
        ]
        self._lb = LoadBalancer(len(qlist))

    def start(self):
        for c in self._consumers:
            c.start()

    def submit(self, tq):
        self._qlist[tq.get_queue_index()].put(tq)

    def assign(self):
        return self._lb.assign()
from socket import *
import socket
import threading
import time
import sys
import logging
from lb import LoadBalancer

reverseProxy = LoadBalancer()

class ProcessTheClient(threading.Thread):
	def __init__(self, connection, address):
		self.connection = connection
		self.address = address
		threading.Thread.__init__(self)

	def run(self):
		rcv=""
		while True:
			try:
				data = self.connection.recv(8192)
				self.destination_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
				if data:
					server = reverseProxy.get_server()
					print(f"forwarded to server {server}")
					self.destination_sock.connect(server)
					self.destination_sock.sendall(data)
					data_balasan = self.destination_sock.recv(8192)
					self.connection.sendall(data_balasan)
					logging.warning(data)
					logging.warning(data_balasan)
 def __init__(self):
     self.load_balancer = LoadBalancer()
     self.current = 0