0

I created my own manager since I will eventually need to pass classes into different processes. I did this using the following code.

class MyManager(BaseManager):
   pass
MyManager.register('modeling', modelingClass)
manager = MyManager()
manager.start()
model = manager.modeling()

for counter in count(start=0, step=1): # counts up infinitely starting at 0
   # get the latest image from the camera
   frame = get_latest_frame()
   if frame is None:
      break

   # run the model
   t1 = time.time()
   boxes, confidences, classIDs = model.get_bounding_boxes(frame, 1, 1)
   print("TIME",(time.time()-t1))

The issue is that this each iteration of the model takes around .12 seconds to run, but if I run the model without multiprocessing and the manager, and just the normal initialization of the class, it runs in around .07 seconds. Any idea how I can speed up the multiprocessing implementation? Thank You.

V. M.
  • 65
  • 1
  • 5
  • 3
    Starting a new process is expensive. This seems like an expectable result. IMO you should not run a new process for something that can be done in 0.07 seconds. – zvone Jan 08 '21 at 01:13
  • So when I call the get_bounding_boxes(...) method, the manager spawns a new process everytime? I assumed that it didn't spawn another process and that the manager was just to have shared objects. – V. M. Jan 08 '21 at 02:25
  • It is not visible from this code where new processes are started, but you wrote yourself that _"without multiprocessing [...] it runs in around .07 seconds"_, which implies that here you are spawning new processes and that slows it down. – zvone Jan 08 '21 at 16:41
  • When I said without multiprocessing, I referred to initializing the modeling class without the manager and then calling the get bounding boxes method. When I say with multiprocessing, I’m referring to initializing the modeling class through the manager and calling the get bounding boxes method. I never openly spawn a new process, my question is why is calling a method of the modeling class so slow with the manager initialization rather than regular initialization? – V. M. Jan 08 '21 at 17:34
  • And what is `BaseManager` doing, if not spawning processes? Show the code. – zvone Jan 09 '21 at 14:04

0 Answers0