ml-agents icon indicating copy to clipboard operation
ml-agents copied to clipboard

Is it better to use self.step_queue.get() than self.step_queue.get_nowait() in SubprocessEnvManager._step()?

Open Tyushang opened this issue 3 years ago • 2 comments

I noticed the code in SubprocessEnvManager._step():

        # Poll the step queue for completed steps from environment workers until we retrieve
        # 1 or more, which we will then return as StepInfos
        while len(worker_steps) < 1:
            try:
                while True:
                    step: EnvironmentResponse = self.step_queue.get_nowait()
                    ...

How about modifying it to:

        while not self.step_queue.empty() or len(worker_steps) == 0:
            step: EnvironmentResponse = self.step_queue.get()
            ...

Why? Coz get_nowait() will not be blocked, it will always makes CPU running in a loop, 100% ocupy a CPU core even if no env_worker is ready; but get() will be blocked if no env_worker is ready, which leads less CPU usage. I think this will be more power-saving.

Am I correct? or there's something I've missed?

Tyushang avatar May 09 '22 12:05 Tyushang

Thank you @Tyushang we will log this request and get back with you once we have investigated it

AKemendo avatar May 10 '22 15:05 AKemendo

Any progress?

Tyushang avatar Aug 12 '22 06:08 Tyushang