Revision 2467e0d3 daemons/ganeti-masterd
b/daemons/ganeti-masterd | ||
---|---|---|
66 | 66 |
cleanup at shutdown. |
67 | 67 |
|
68 | 68 |
""" |
69 |
QUEUE_PROCESSOR_SIZE = 5 |
|
70 |
|
|
71 | 69 |
def __init__(self, address, rqhandler, context): |
72 | 70 |
"""IOServer constructor |
73 | 71 |
|
... | ... | |
79 | 77 |
""" |
80 | 78 |
SocketServer.UnixStreamServer.__init__(self, address, rqhandler) |
81 | 79 |
self.do_quit = False |
82 |
self.queue = jqueue.QueueManager() |
|
83 | 80 |
self.context = context |
84 |
self.processors = [] |
|
85 | 81 |
|
86 | 82 |
# We'll only start threads once we've forked. |
87 | 83 |
self.jobqueue = None |
... | ... | |
92 | 88 |
def setup_queue(self): |
93 | 89 |
self.jobqueue = jqueue.JobQueue(self.context) |
94 | 90 |
|
95 |
def setup_processors(self): |
|
96 |
"""Spawn the processors threads. |
|
97 |
|
|
98 |
This initializes the queue and the thread processors. It is done |
|
99 |
separately from the constructor because we want the clone() |
|
100 |
syscalls to happen after the daemonize part. |
|
101 |
|
|
102 |
""" |
|
103 |
for i in range(self.QUEUE_PROCESSOR_SIZE): |
|
104 |
self.processors.append(threading.Thread(target=PoolWorker, |
|
105 |
args=(i, self.queue.new_queue, |
|
106 |
self.context))) |
|
107 |
for t in self.processors: |
|
108 |
t.start() |
|
109 |
|
|
110 | 91 |
def process_request_thread(self, request, client_address): |
111 | 92 |
"""Process the request. |
112 | 93 |
|
... | ... | |
150 | 131 |
try: |
151 | 132 |
self.server_close() |
152 | 133 |
utils.RemoveFile(constants.MASTER_SOCKET) |
153 |
for i in range(self.QUEUE_PROCESSOR_SIZE): |
|
154 |
self.queue.new_queue.put(None) |
|
155 |
for idx, t in enumerate(self.processors): |
|
156 |
logging.debug("waiting for processor thread %s...", idx) |
|
157 |
t.join() |
|
158 |
logging.debug("threads done") |
|
159 | 134 |
finally: |
160 | 135 |
if self.jobqueue: |
161 | 136 |
self.jobqueue.Shutdown() |
... | ... | |
428 | 403 |
return |
429 | 404 |
|
430 | 405 |
try: |
431 |
master.setup_processors() |
|
432 | 406 |
master.setup_queue() |
433 | 407 |
try: |
434 | 408 |
master.serve_forever() |
Also available in: Unified diff