Commit 89e2b4d2 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

workerpool: Make worker ID alphanumeric



Having a proper name instead of just a number makes debugging
easier.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 71e1863e
...@@ -101,7 +101,8 @@ class IOServer(SocketServer.UnixStreamServer): ...@@ -101,7 +101,8 @@ class IOServer(SocketServer.UnixStreamServer):
def setup_queue(self): def setup_queue(self):
self.context = GanetiContext() self.context = GanetiContext()
self.request_workers = workerpool.WorkerPool(CLIENT_REQUEST_WORKERS, self.request_workers = workerpool.WorkerPool("ClientReq",
CLIENT_REQUEST_WORKERS,
ClientRequestWorker) ClientRequestWorker)
def process_request(self, request, client_address): def process_request(self, request, client_address):
......
...@@ -342,7 +342,8 @@ class HttpClientWorker(workerpool.BaseWorker): ...@@ -342,7 +342,8 @@ class HttpClientWorker(workerpool.BaseWorker):
class HttpClientWorkerPool(workerpool.WorkerPool): class HttpClientWorkerPool(workerpool.WorkerPool):
def __init__(self, manager): def __init__(self, manager):
workerpool.WorkerPool.__init__(self, HTTP_CLIENT_THREADS, workerpool.WorkerPool.__init__(self, "HttpClient",
HTTP_CLIENT_THREADS,
HttpClientWorker) HttpClientWorker)
self.manager = manager self.manager = manager
......
...@@ -536,7 +536,8 @@ class _JobQueueWorkerPool(workerpool.WorkerPool): ...@@ -536,7 +536,8 @@ class _JobQueueWorkerPool(workerpool.WorkerPool):
""" """
def __init__(self, queue): def __init__(self, queue):
super(_JobQueueWorkerPool, self).__init__(JOBQUEUE_THREADS, super(_JobQueueWorkerPool, self).__init__("JobQueue",
JOBQUEUE_THREADS,
_JobQueueWorker) _JobQueueWorker)
self.queue = queue self.queue = queue
......
...@@ -153,7 +153,7 @@ class WorkerPool(object): ...@@ -153,7 +153,7 @@ class WorkerPool(object):
guaranteed to finish in the same order. guaranteed to finish in the same order.
""" """
def __init__(self, num_workers, worker_class): def __init__(self, name, num_workers, worker_class):
"""Constructor for worker pool. """Constructor for worker pool.
@param num_workers: number of workers to be started @param num_workers: number of workers to be started
...@@ -168,6 +168,7 @@ class WorkerPool(object): ...@@ -168,6 +168,7 @@ class WorkerPool(object):
self._pool_to_worker = threading.Condition(self._lock) self._pool_to_worker = threading.Condition(self._lock)
self._worker_to_pool = threading.Condition(self._lock) self._worker_to_pool = threading.Condition(self._lock)
self._worker_class = worker_class self._worker_class = worker_class
self._name = name
self._last_worker_id = 0 self._last_worker_id = 0
self._workers = [] self._workers = []
self._quiescing = False self._quiescing = False
...@@ -253,7 +254,8 @@ class WorkerPool(object): ...@@ -253,7 +254,8 @@ class WorkerPool(object):
""" """
self._last_worker_id += 1 self._last_worker_id += 1
return self._last_worker_id
return "%s%d" % (self._name, self._last_worker_id)
def _ResizeUnlocked(self, num_workers): def _ResizeUnlocked(self, num_workers):
"""Changes the number of workers. """Changes the number of workers.
......
...@@ -62,7 +62,7 @@ class TestWorkerpool(unittest.TestCase): ...@@ -62,7 +62,7 @@ class TestWorkerpool(unittest.TestCase):
"""Workerpool tests""" """Workerpool tests"""
def testDummy(self): def testDummy(self):
wp = workerpool.WorkerPool(3, DummyBaseWorker) wp = workerpool.WorkerPool("Test", 3, DummyBaseWorker)
try: try:
self._CheckWorkerCount(wp, 3) self._CheckWorkerCount(wp, 3)
...@@ -75,7 +75,7 @@ class TestWorkerpool(unittest.TestCase): ...@@ -75,7 +75,7 @@ class TestWorkerpool(unittest.TestCase):
self._CheckWorkerCount(wp, 0) self._CheckWorkerCount(wp, 0)
def testNoTasks(self): def testNoTasks(self):
wp = workerpool.WorkerPool(3, DummyBaseWorker) wp = workerpool.WorkerPool("Test", 3, DummyBaseWorker)
try: try:
self._CheckWorkerCount(wp, 3) self._CheckWorkerCount(wp, 3)
self._CheckNoTasks(wp) self._CheckNoTasks(wp)
...@@ -84,7 +84,7 @@ class TestWorkerpool(unittest.TestCase): ...@@ -84,7 +84,7 @@ class TestWorkerpool(unittest.TestCase):
self._CheckWorkerCount(wp, 0) self._CheckWorkerCount(wp, 0)
def testNoTasksQuiesce(self): def testNoTasksQuiesce(self):
wp = workerpool.WorkerPool(3, DummyBaseWorker) wp = workerpool.WorkerPool("Test", 3, DummyBaseWorker)
try: try:
self._CheckWorkerCount(wp, 3) self._CheckWorkerCount(wp, 3)
self._CheckNoTasks(wp) self._CheckNoTasks(wp)
...@@ -97,7 +97,7 @@ class TestWorkerpool(unittest.TestCase): ...@@ -97,7 +97,7 @@ class TestWorkerpool(unittest.TestCase):
def testChecksum(self): def testChecksum(self):
# Tests whether all tasks are run and, since we're only using a single # Tests whether all tasks are run and, since we're only using a single
# thread, whether everything is started in order. # thread, whether everything is started in order.
wp = workerpool.WorkerPool(1, ChecksumBaseWorker) wp = workerpool.WorkerPool("Test", 1, ChecksumBaseWorker)
try: try:
self._CheckWorkerCount(wp, 1) self._CheckWorkerCount(wp, 1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment