Repository navigation
Conversation
Every client shared one os_cpu_usage_info_t, and os_cpu_usage_info_query() moves its last times forward on every call. A client's GetStats reported the CPU usage since the last GetStats from any client, not since its own: with two clients polling, each saw only the slice since the other one's call, often 0. The query also ran without a lock while requests run in parallel on the thread pool, a data race on the shared state. Each session now has its own CPU usage state, started when it connects and queried under a lock, so cpuUsage covers the time since the same client's previous GetStats. Requests without a session (vendor requests) use the shared state, now also under a lock. Refs obs-rust/obs-studio#1346
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every client shared one
os_cpu_usage_info_t(src/obs-websocket.cppline 64).os_cpu_usage_info_query()moves its last times forward on every call, so a client'sGetStatsreported the CPU usage since the lastGetStatsfrom any client, not since its own. With two clients polling at different rates, the slower one saw only the slice since the faster one's last call: mostly 0, sometimes a whole core's worth. The query also ran without a lock, while requests run in parallel on the thread pool, which is a data race on the shared state. In the Rust obs-util it also means two&mutreferences to it at once.Each session now has its own CPU usage state. It starts when the client connects and is queried under a lock, so
cpuUsagecovers the time since the same client's previousGetStats(or since it connected). Requests without a session (vendor requests) still use the shared state, now also under a lock. ThecpuUsagedescription in the request docs and indocs/generatedsays so.Measured end to end: OBS recording a 640x360 scene, client A polling
GetStatsevery 50 ms and client B every 2 s. B'scpuUsageis compared with OBS's own CPU time over B's interval, read from/proc/<pid>/stat:cpuUsage(actual)Tested in obs-rust/obs-studio with
test_ws_cpu_usage, which sendsGetStatsthroughRequestHandlerwith two sessions. It burns CPU, polls from session a, idles as long, then polls from session b. At 0d663ee, b reports 0.000% against a's 6.250% in both libobs lanes. With this branch, b reports about half of a's usage (3.047% against 6.094%), 5 of 5 runs in each lane. A second case sendsGetStatsfrom 8 threads at once, with and without a session.Refs obs-rust/obs-studio#1346. The obs-rust/obs-studio PR that moves the submodule to this commit carries the regression test and closes the issue.