Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abnormally high CPU usage for OBS 31.0.0-betaX versions caused by obs-browser #11485

Open
w0nd3r365 opened this issue Nov 4, 2024 · 18 comments

Comments

@w0nd3r365
Copy link

w0nd3r365 commented Nov 4, 2024

Operating System Info

Other

Other OS

Kali GNU/Linux Rolling 2024.3

OBS Studio Version

31.0.0-beta3

OBS Studio Version (Other)

No response

OBS Studio Log URL

https://obsproject.com/logs/9BLCtWdbxYJWBBhM

OBS Studio Crash Log URL

No response

Expected Behavior

"Normal" CPU usage stats after creating a browser source. Normal in my case is about 3-5% when no other sources are present.

Current Behavior

After creating a browser source, OBS CPU usage spikes to 25-27% and does not fall down whatsoever until I delete the created browser source and restart OBS.

Steps to Reproduce

  1. I cloned OBS repo.
git clone --recursive --jobs 10 [email protected]:obsproject/obs-studio
cd obs-studio
git switch --detach 31.0.0-beta3
  1. I configured OBS using cef_binary_5060_linux_x86_64 from here.
cmake -S . -B build -G Ninja \
-DCEF_ROOT_DIR="/opt/repos/obs-studio/cef_binary/cef_binary_5060_linux_x86_64" \
-DENABLE_BROWSER=ON \
-DENABLE_WEBRTC=1 \
-DENABLE_FFMPEG_LOGGING=OFF \
-DENABLE_LIBFDK=ON \
-DENABLE_SNDIO=ON \
-DENABLE_JACK=ON \
-DENABLE_AJA=OFF \
-DOBS_BUILD_NUMBER=8 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr
  1. I built OBS debian package and installed it.
ninja -j6 -C build
cmake --build build --target package
sudo apt install ./build/obs-studio-31.0.0-beta3-Linux.deb
  1. Launched OBS. Currently CPU usage is ~3% on an empty scene. I create a browser source with the default settings including URL. CPU usage spikes to ~26% and doesn't fall at all as time goes. I delete the dummy browser source and transition. Still the CPU usage stays at the high of ~26%. I restart OBS and it's CPU usage is now the normal of ~3%. If I create a browser source, the issue occurs again. In htop, obs process is maxing out 1 of the 4 logical CPU cores to ~100%.

Anything else we should know?

I have rebuilt OBS using several different CEF binaries from spotify and adamcake but CPU spike issue still occurs for every build. So maybe it's not caused by CEF but by OBS internals?

To be certain it's not an OBS regression, I tried building versions 30.2.3 and below but failed because of the configuration error below. I can only configure versions 31+ successfully. Thus I don't know more about the OBS regression hypothesis. How can I fix this build configuration error?

CMake Error at plugins/obs-browser/cmake/os-linux.cmake:23 (set_target_properties_obs):
  Unknown CMake command "set_target_properties_obs".
Call Stack (most recent call first):
  plugins/obs-browser/CMakeLists.txt:53 (include)


-- Configuring incomplete, errors occurred!

Maybe my build environment is to blame? I don't know yet how to ascertain this. I had older OBS debian pkg builds which were very good but couldn't install them due to missing deps thanks to dist-upgrade. I can't install from your PPA repo either because of dependency conflicts that can't be sanely satisfied. My only functional OBS instance is a flatpak installation ,version 30.2.3, which has no such CPU spike issue.

@kkartaltepe
Copy link
Collaborator

I cannot replicate this, enable debug information and profile obs if this replicates on your side.

@w0nd3r365
Copy link
Author

w0nd3r365 commented Nov 5, 2024

Okay. I've rebuilt OBS with -DCMAKE_BUILD_TYPE=Debug and profiled with perf record -F 1000 --stat -g --call-graph dwarf obs --verbose. I've attached the perf.data and obs log file below. If I should have done this some other way, please do tell.

Profiling data: perf.data.gz
OBS log file: https://obsproject.com/logs/QxFFEl7b4OVdaIav

PS: I think the difference time zones may make conversations intermittent, rather than real-time.

@kkartaltepe
Copy link
Collaborator

kkartaltepe commented Nov 5, 2024

I do not have symbols for your system and custom obs, you must do the analysis with symbols available. I recommend installing the flamegraph collection of tools (flamegraph and flamegraph-stackcollapse-perf on fedora for example). Then you can run perf script | stackcollapse-perf.pl | flamegraph.pl > obs_slow.svg to produce a useful svg to upload from the sample perf.data.

@w0nd3r365
Copy link
Author

w0nd3r365 commented Nov 5, 2024

I created the flamegraph with:

perf script | ./stackcollapse-perf.pl | ./stackcollapse-recursive.pl | ./flamegraph.pl > obs_cpu_spike.svg

Flame graph: obs_cpu_spike.svg

(Sorry, I can't interpret that data.)

@kkartaltepe
Copy link
Collaborator

kkartaltepe commented Nov 6, 2024

There were no symbols for OBS in that, so its mostly unhelpful except that obs is spending the majority of your cpu time in getting the current time.

@w0nd3r365
Copy link
Author

Okay. I created another flame graph with LBR call graph profiling. maybe it has better accuracy in showing OBS symbols.
flame graph: obs_cpu_spike_lbr.svg

I've noticed too that there is clock_gettime symbol from libc.so.6 and __vdso_clock_gettime symbol from kernel which are very CPU instensive for the task of just getting time information I think. Why does this happen?
Screenshot_20241106_140816

From image below, you can see that OBS has been running for ~30min but still CPU usage hasn't dropped to the "normal" one. OBS is basically idle but my laptop has started heating up, spinning up the fans. Could it be caused by a misconfiguration in my system? Because you said you couldn't replicate this.
Screenshot_20241106_141432

@kkartaltepe
Copy link
Collaborator

the problems is the lack of OBS symbols for your data, so changing perf's stack analysis is not going to do anything significant. You need to solve your symbol problem before any analysis of the stacks can be useful.

@w0nd3r365
Copy link
Author

w0nd3r365 commented Nov 6, 2024

I see. I've now installed obs-studio-31.0.0-beta3-debug-Linux-dbgsym.ddeb package. I profiled OBS again and recreated the flame graph. inotifywait shows OBS debug symbols being read from files at /usr/lib/debug/.build-id when running perf.
flame graph: obs_cpu_spike_with_symbols

I'm not sure this is enough. If not sufficient, kindly tell me what to do. I'm new to this kind of debugging. Thanks.

@kkartaltepe
Copy link
Collaborator

This seems correct, thanks.

@w0nd3r365
Copy link
Author

w0nd3r365 commented Nov 7, 2024

I got the source tarball for OBS 30.2.3 from github releases and built it with the same CEF. When creating a browser source, there's no CPU spike issue. This could mean the CPU usage abnormality is found in versions >=31.0.0-beta1. It's probable that it's not my system misconfiguration, but an OBS regression. Perhaps to rule this out further, I may need an LXC container for testing ¯\_(ツ)_/¯, but I'll only do it if asked to.

Also, I haven't seen anyone report experiencing this issue and you could not reproduce it as well. So I don't really know what that indicates.

I couldn't get across the build configuration error stated in my first comment. I think there's some breaking changes in the configs related to cmake since they are in .gitignore, thus not tracked by git, making it hard to build older versions <=30.2.3 from the git repo after git switch. I was so irked by this build error till I remembered release tarballs exist, lol.

@RytoEX
Copy link
Member

RytoEX commented Nov 7, 2024

Your build error on 30.2.x is likely because you did not update submodules to match the obs-studio checkout, so you're trying to build OBS Studio 30.2.3 with a newer version of obs-browser which is not compatible.

Have you tried the 31.0.0-beta3 Flatpak instead of building from source? Your post indicates that you were using a different version of CEF than what we now use.

I am not yet convinced this is our bug.

@w0nd3r365
Copy link
Author

w0nd3r365 commented Nov 7, 2024

Mmh, I hadn't thought of checkout on submodules as well. I did git switch for respective submodules and there is no longer a build configuration error. Thanks for pointing that out.

I've installed OBS 31.0.0-beta3 from the flatpak beta branch and tested it. The CPU spike issue still occurs with your build.

@w0nd3r365
Copy link
Author

w0nd3r365 commented Nov 8, 2024

I've set up an LXC container for Kali Linux (same as host) and went on to build OBS 31.0.0-beta3 in the container. I installed the build in the container as well as host OS and tested both instances. CPU spike issue still occurs when OBS is run in either guest or host. Maybe this is an issue with Kali Linux as I haven't tested any other OS in LXC ¯\_(ツ)_/¯

@treviasxk
Copy link

I'm using version 30.2.3 on Linux (I installed it via AUR, obs-studio-git), and I have the same problem. Whenever I use a browser, OBS consumes a lot of CPU.

Without a browser, the CPU is 2%.
image

With a browser, it's 25%.
image

I'm using Wayland with KDE on Arch. In X11, I can use the line command --enable-gpu, and the CPU consumption is 16%. In Wayland, this command doesn't work.

@kkartaltepe
Copy link
Collaborator

I'm using version 30.2.3 on Linux (I installed it via AUR, obs-studio-git), and I have the same problem. Whenever I use a browser, OBS consumes a lot of CPU.

That is unrelated and you should use the support channels if you have questions about performance, this issue is about when all browser sources have been removed there is high cpu usage.

@treviasxk
Copy link

treviasxk commented Nov 9, 2024

I'm using version 30.2.3 on Linux (I installed it via AUR, obs-studio-git), and I have the same problem. Whenever I use a browser, OBS consumes a lot of CPU.

That is unrelated and you should use the support channels if you have questions about performance, this issue is about when all browser sources have been removed there is high cpu usage.

Yes it is related!, it is the same problem, when I remove the browser the CPU continues to be high, and only returns to normal when I restart it.

image

@kkartaltepe
Copy link
Collaborator

Post a log from obs then after you trigger this issue. Thanks.

@treviasxk
Copy link

treviasxk commented Nov 9, 2024

The log does not report any problems, I believe the problem is in the browser plugin's webkit that is not configured correctly for Linux. Once the obs loads it, it will always be using it (even if you remove the browser from the source, I think the plugin stays in the background).

Log: 2024-11-09 17-31-05.txt

The amount of CPU usage of this browser is abnormal (not even my default browser, discord or anything that uses webkit, does not have this abnormal CPU usage), in X11 it is also 25% of CPU, but if you start obs with --enable-gpu, it is 16%, this means that webkit is not rendering with hardware, but perhaps via software.

I think the problem is the webkit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants