Bug 1533848 - Make the control server multithreaded, r=rwood.
authorBob Clary <bclary@bclary.com>
Tue, 16 Apr 2019 19:26:26 +0000
changeset 469775 219832d78e12
parent 469774 4aab82c04e9c
child 469776 dc74bceea27b
push id35882
push usercbrindusan@mozilla.com
push dateWed, 17 Apr 2019 15:54:01 +0000
treeherdermozilla-central@37185c0ae520 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrwood
bugs1533848
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1533848 - Make the control server multithreaded, r=rwood. Differential Revision: https://phabricator.services.mozilla.com/D26972
testing/raptor/raptor/control_server.py
--- a/testing/raptor/raptor/control_server.py
+++ b/testing/raptor/raptor/control_server.py
@@ -98,16 +98,29 @@ def MakeCustomHandlerClass(results_handl
             self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
             self.send_header("Access-Control-Allow-Headers", "X-Requested-With")
             self.send_header("Access-Control-Allow-Headers", "Content-Type")
             self.end_headers()
 
     return MyHandler
 
 
+class ThreadedHTTPServer(BaseHTTPServer.HTTPServer):
+    # See
+    # https://stackoverflow.com/questions/19537132/threaded-basehttpserver-one-thread-per-request#30312766
+    def process_request(self, request, client_address):
+        thread = threading.Thread(target=self.__new_request,
+                                  args=(self.RequestHandlerClass, request, client_address, self))
+        thread.start()
+
+    def __new_request(self, handlerClass, request, address, server):
+        handlerClass(request, address, server)
+        self.shutdown_request(request)
+
+
 class RaptorControlServer():
     """Container class for Raptor Control Server"""
 
     def __init__(self, results_handler, debug_mode=False):
         self.raptor_venv = os.path.join(os.getcwd(), 'raptor-venv')
         self.server = None
         self._server_thread = None
         self.port = None
@@ -125,17 +138,17 @@ class RaptorControlServer():
 
         # pick a free port
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sock.bind(('', 0))
         self.port = sock.getsockname()[1]
         sock.close()
         server_address = ('', self.port)
 
-        server_class = BaseHTTPServer.HTTPServer
+        server_class = ThreadedHTTPServer
         handler_class = MakeCustomHandlerClass(self.results_handler,
                                                self.shutdown_browser,
                                                self.write_raw_gecko_profile)
 
         httpd = server_class(server_address, handler_class)
 
         self._server_thread = threading.Thread(target=httpd.serve_forever)
         self._server_thread.setDaemon(True)  # don't hang on exit