[pulseaudio-discuss] Null sink and its monitor cause high CPU usage in headless environment
Georg Chini
georg at chini.tk
Tue Nov 1 09:38:54 UTC 2022
Hi Tudor,
yes, there is one sink input still active (qemu?) which is also the one
that requests the
low latency (requested latency: 0.50 ms). As long as there is an active
stream, the
sink will not be suspended.
I do not see module-loopback in the list of loaded modules. For
module-loopback, the
default latency is 200 ms, so reducing it to 5 ms will surely increase
CPU load. The
default latency is a bit on the large side, I would go for something
between 20ms and
50 ms.
Regards
Georg
On 31.10.22 22:54, Tudor Zaharia wrote:
> Hi Georg,
>
> Thank you so much for the quick response!
>
> That sounds like what I need, but unfortunately I have problems with both proposed mitigation measures:
>
> 1. Configuring the latency of the null-sink
>
> I couldn't find a setting for it in the documentation (https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/#module-null-sink) so I tried adding a module-loopback with a latency_msec=5. Unfortunately this increased CPU load even further and even without any clients connected.
>
> Sorry if I sound stupid, but I'm quite new to pulseaudio: I'm guessing that the client itself is requesting this latency when connecting to it? I looked a bit through the client's code but nowhere this value of 500us is set:
>
> pa_buffer_attr ba;
> ba.tlength = pa_usec_to_bytes (10 * 1000, &ss);
> ba.minreq = pa_usec_to_bytes (5 * 1000, &ss);
> ba.maxlength = -1;
> ba.prebuf = -1;
>
> int r = pa_stream_connect_playback (stream, dev, ba,
> PA_STREAM_INTERPOLATE_TIMING
> |PA_STREAM_ADJUST_LATENCY
> |PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL);
>
> From this I'm guessing a latency of 5000us = 5ms, so exactly what you were suggesting. But still pacmd list shows a 500us requested latency value (see below). I don't understand why!
>
> 2. Using module-suspend-on-idle
>
> This sounds like a great idea, but the output sink (emulator_out) is always running, so it doesn't get suspended, although there is no sound coming from the client. Same, I don't understand why it is still in running state!
>
> $ pacmd list
>
> Memory blocks currently allocated: 1, size: 63.9 KiB.
> Memory blocks allocated during the whole lifetime: 7789, size: 794.0 KiB.
> Memory blocks imported from other processes: 0, size: 0 B.
> Memory blocks exported to other processes: 0, size: 0 B.
> Total sample cache size: 0 B.
> Default sample spec: s16le 2ch 48000Hz
> Default channel map: front-left,front-right
> Default sink name: emulator_out
> Default source name: emulator_out.monitor
> Memory blocks of type POOL: 1 allocated/7789 accumulated.
> Memory blocks of type POOL_EXTERNAL: 0 allocated/0 accumulated.
> Memory blocks of type APPENDED: 0 allocated/0 accumulated.
> Memory blocks of type USER: 0 allocated/0 accumulated.
> Memory blocks of type FIXED: 0 allocated/0 accumulated.
> Memory blocks of type IMPORTED: 0 allocated/0 accumulated.
> 5 module(s) loaded.
> index: 0
> name: <module-null-sink>
> argument: <sink_name=emulator_out sink_properties=device.description=emulator_out format=s16le rate=48000 channels=2 channel_map=front-left,front-right>
> used: 1
> load once: no
> properties:
> module.author = "Lennart Poettering"
> module.description = "Clocked NULL sink"
> module.version = "10.0"
> index: 1
> name: <module-null-sink>
> argument: <sink_name=emulator_in sink_properties=device.description=emulator_in format=s16le rate=48000 channels=2 channel_map=front-left,front-right>
> used: 1
> load once: no
> properties:
> module.author = "Lennart Poettering"
> module.description = "Clocked NULL sink"
> module.version = "10.0"
> index: 2
> name: <module-suspend-on-idle>
> argument: <timeout=2>
> used: -1
> load once: yes
> properties:
> module.author = "Lennart Poettering"
> module.description = "When a sink/source is idle for too long, suspend it"
> module.version = "10.0"
> index: 3
> name: <module-native-protocol-unix>
> argument: <auth-anonymous=1 socket=/pa/pulse-socket>
> used: -1
> load once: no
> properties:
> module.author = "Lennart Poettering"
> module.description = "Native protocol (UNIX sockets)"
> module.version = "10.0"
> index: 4
> name: <module-cli-protocol-unix>
> argument: <>
> used: -1
> load once: no
> properties:
> module.author = "Lennart Poettering"
> module.description = "Command line interface protocol (UNIX sockets)"
> module.version = "10.0"
> 2 sink(s) available.
> * index: 0
> name: <emulator_out>
> driver: <module-null-sink.c>
> flags: DECIBEL_VOLUME LATENCY FLAT_VOLUME DYNAMIC_LATENCY
> state: RUNNING
> suspend cause:
> priority: 1000
> volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
> balance 0.00
> base volume: 65536 / 100% / 0.00 dB
> volume steps: 65537
> muted: no
> current latency: 0.38 ms
> max request: 0 KiB
> max rewind: 0 KiB
> monitor source: 0
> sample spec: s16le 2ch 48000Hz
> channel map: front-left,front-right
> Stereo
> used by: 1
> linked by: 1
> configured latency: 0.50 ms; range is 0.50 .. 2000.00 ms
> module: 0
> properties:
> device.description = "emulator_out"
> device.class = "abstract"
> device.icon_name = "audio-card"
> index: 1
> name: <emulator_in>
> driver: <module-null-sink.c>
> flags: DECIBEL_VOLUME LATENCY FLAT_VOLUME DYNAMIC_LATENCY
> state: SUSPENDED
> suspend cause: IDLE
> priority: 1000
> volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
> balance 0.00
> base volume: 65536 / 100% / 0.00 dB
> volume steps: 65537
> muted: no
> current latency: 0.00 ms
> max request: 1 KiB
> max rewind: 1 KiB
> monitor source: 1
> sample spec: s16le 2ch 48000Hz
> channel map: front-left,front-right
> Stereo
> used by: 0
> linked by: 1
> configured latency: 0.00 ms; range is 0.50 .. 2000.00 ms
> module: 1
> properties:
> device.description = "emulator_in"
> device.class = "abstract"
> device.icon_name = "audio-card"
> 2 source(s) available.
> * index: 0
> name: <emulator_out.monitor>
> driver: <module-null-sink.c>
> flags: DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
> state: IDLE
> suspend cause:
> priority: 1000
> volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
> balance 0.00
> base volume: 65536 / 100% / 0.00 dB
> volume steps: 65537
> muted: no
> current latency: 0.00 ms
> max rewind: 0 KiB
> sample spec: s16le 2ch 48000Hz
> channel map: front-left,front-right
> Stereo
> used by: 0
> linked by: 0
> configured latency: 2000.00 ms; range is 0.50 .. 2000.00 ms
> monitor_of: 0
> module: 0
> properties:
> device.description = "Monitor of emulator_out"
> device.class = "monitor"
> device.icon_name = "audio-input-microphone"
> index: 1
> name: <emulator_in.monitor>
> driver: <module-null-sink.c>
> flags: DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
> state: SUSPENDED
> suspend cause: IDLE
> priority: 1000
> volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
> balance 0.00
> base volume: 65536 / 100% / 0.00 dB
> volume steps: 65537
> muted: no
> current latency: 0.00 ms
> max rewind: 1 KiB
> sample spec: s16le 2ch 48000Hz
> channel map: front-left,front-right
> Stereo
> used by: 0
> linked by: 1
> configured latency: 0.00 ms; range is 0.50 .. 2000.00 ms
> monitor_of: 1
> module: 1
> properties:
> device.description = "Monitor of emulator_in"
> device.class = "monitor"
> device.icon_name = "audio-input-microphone"
> 2 client(s) logged in.
> index: 2
> driver: <protocol-native.c>
> owner module: 3
> properties:
> application.name = "unix:/tmp/pa-docker/pulse-socket"
> native-protocol.peer = "UNIX socket client"
> native-protocol.version = "33"
> application.process.id = "55569"
> application.process.user = "tudor"
> application.process.host = "machine"
> application.process.binary = "qemu-system-x86_64"
> application.language = "C"
> window.x11.display = ":1"
> application.process.machine_id = "c6ba133539f0416791786992742aa11c"
> index: 3
> driver: <cli.c>
> owner module: 4
> properties:
> application.name = "UNIX socket client"
> 0 card(s) available.
> 1 sink input(s) available.
> index: 0
> driver: <protocol-native.c>
> flags:
> state: DRAINED
> sink: 0 <emulator_out>
> volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
> balance 0.00
> muted: no
> current latency: 0.00 ms
> requested latency: 0.50 ms
> sample spec: s16le 2ch 48000Hz
> channel map: front-left,front-right
> Stereo
> resample method: (null)
> module: 3
> client: 2 <unix:/tmp/pa-docker/pulse-socket>
> properties:
> media.name = "qemu"
> application.name = "unix:/tmp/pa-docker/pulse-socket"
> native-protocol.peer = "UNIX socket client"
> native-protocol.version = "33"
> application.process.id = "55569"
> application.process.user = "tudor"
> application.process.host = "machine"
> application.process.binary = "qemu-system-x86_64"
> application.language = "C"
> window.x11.display = ":1"
> application.process.machine_id = "c6ba133539f0416791786992742aa11c"
> 1 source output(s) available.
> index: 0
> driver: <protocol-native.c>
> flags: START_CORKED
> state: CORKED
> source: 1 <emulator_in.monitor>
> volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
> balance 0.00
> muted: no
> current latency: 0.00 ms
> requested latency: 10.00 ms
> sample spec: s16le 2ch 48000Hz
> channel map: front-left,front-right
> Stereo
> resample method: (null)
> owner module: 3
> client: 2 <unix:/tmp/pa-docker/pulse-socket>
> properties:
> media.name = "qemu"
> application.name = "unix:/tmp/pa-docker/pulse-socket"
> native-protocol.peer = "UNIX socket client"
> native-protocol.version = "33"
> application.process.id = "55569"
> application.process.user = "tudor"
> application.process.host = "machine"
> application.process.binary = "qemu-system-x86_64"
> application.language = "C"
> window.x11.display = ":1"
> application.process.machine_id = "c6ba133539f0416791786992742aa11c"
> 0 cache entrie(s) available.
>
> Best regards,
> Tudor
More information about the pulseaudio-discuss
mailing list