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):
def setup_queue(self):
self.context = GanetiContext()
self.request_workers = workerpool.WorkerPool(CLIENT_REQUEST_WORKERS,
self.request_workers = workerpool.WorkerPool("ClientReq",
CLIENT_REQUEST_WORKERS,
ClientRequestWorker)
def process_request(self, request, client_address):
......
......@@ -342,7 +342,8 @@ class HttpClientWorker(workerpool.BaseWorker):
class HttpClientWorkerPool(workerpool.WorkerPool):
def __init__(self, manager):
workerpool.WorkerPool.__init__(self, HTTP_CLIENT_THREADS,
workerpool.WorkerPool.__init__(self, "HttpClient",
HTTP_CLIENT_THREADS,
HttpClientWorker)
self.manager = manager
......
......@@ -536,7 +536,8 @@ class _JobQueueWorkerPool(workerpool.WorkerPool):
"""
def __init__(self, queue):
super(_JobQueueWorkerPool, self).__init__(JOBQUEUE_THREADS,
super(_JobQueueWorkerPool, self).__init__("JobQueue",
JOBQUEUE_THREADS,
_JobQueueWorker)
self.queue = queue
......
......@@ -153,7 +153,7 @@ class WorkerPool(object):
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.
@param num_workers: number of workers to be started
......@@ -168,6 +168,7 @@ class WorkerPool(object):
self._pool_to_worker = threading.Condition(self._lock)
self._worker_to_pool = threading.Condition(self._lock)
self._worker_class = worker_class
self._name = name
self._last_worker_id = 0
self._workers = []
self._quiescing = False
......@@ -253,7 +254,8 @@ class WorkerPool(object):
"""
self._last_worker_id += 1
return self._last_worker_id
return "%s%d" % (self._name, self._last_worker_id)
def _ResizeUnlocked(self, num_workers):
"""Changes the number of workers.
......
......@@ -62,7 +62,7 @@ class TestWorkerpool(unittest.TestCase):
"""Workerpool tests"""
def testDummy(self):
wp = workerpool.WorkerPool(3, DummyBaseWorker)
wp = workerpool.WorkerPool("Test", 3, DummyBaseWorker)
try:
self._CheckWorkerCount(wp, 3)
......@@ -75,7 +75,7 @@ class TestWorkerpool(unittest.TestCase):
self._CheckWorkerCount(wp, 0)
def testNoTasks(self):
wp = workerpool.WorkerPool(3, DummyBaseWorker)
wp = workerpool.WorkerPool("Test", 3, DummyBaseWorker)
try:
self._CheckWorkerCount(wp, 3)
self._CheckNoTasks(wp)
......@@ -84,7 +84,7 @@ class TestWorkerpool(unittest.TestCase):
self._CheckWorkerCount(wp, 0)
def testNoTasksQuiesce(self):
wp = workerpool.WorkerPool(3, DummyBaseWorker)
wp = workerpool.WorkerPool("Test", 3, DummyBaseWorker)
try:
self._CheckWorkerCount(wp, 3)
self._CheckNoTasks(wp)
......@@ -97,7 +97,7 @@ class TestWorkerpool(unittest.TestCase):
def testChecksum(self):
# Tests whether all tasks are run and, since we're only using a single
# thread, whether everything is started in order.
wp = workerpool.WorkerPool(1, ChecksumBaseWorker)
wp = workerpool.WorkerPool("Test", 1, ChecksumBaseWorker)
try:
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