home-assistant-libs / ha-ffmpeg

A python library that handling with ffmpeg for home-assistant
BSD 3-Clause "New" or "Revised" License
17 stars 13 forks source link

Refactor to avoid using the executor #139

Closed bdraco closed 6 months ago

bdraco commented 7 months ago

We currently have a problem in HA where users run out of executor threads and everything stalls. This is part of an effort to reduce the amount of executor jobs. Convert to using asyncio.create_subprocess_exec since we avoid the executor step.

I tested this with homekit cameras and everything is a bit snappier. That's the only camera use case I have though so it would be good to validate this with additional use cases before merging. I tested this with an ffmpeg camera in HA as well.

2024-02-29 21:32:32.264 INFO (MainThread) [homeassistant.setup] Setting up ffmpeg
2024-02-29 21:32:32.276 INFO (MainThread) [asyncio] execute program 'ffmpeg': <_UnixSubprocessTransport pid=47484 running stdin=<_UnixWritePipeTransport fd=28 idle bufsize=0> stdout=<_UnixReadPipeTransport fd=29 polling>>
2024-02-29 21:32:32.314 INFO (MainThread) [asyncio] <_UnixReadPipeTransport fd=29 polling> was closed by peer
2024-02-29 21:32:32.314 INFO (MainThread) [asyncio] <_UnixSubprocessTransport pid=47484 running stdin=<_UnixWritePipeTransport closed fd=28 closed> stdout=<_UnixReadPipeTransport closing fd=29 idle>> exited with return code 0
2024-02-29 21:32:32.315 INFO (MainThread) [homeassistant.setup] Setup of domain ffmpeg took 0.1 seconds
bdraco commented 6 months ago

Thanks. Got another camera setup as an ffmpeg camera in HA directly to validate this change.