-
Notifications
You must be signed in to change notification settings - Fork 865
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
The library consumes 100% CPU for iOS iOS TV #601
Comments
Hi @ogolosovskiy, please also take a look at comment
is there from initial commit and it works at least in case I described so you need to describe your library usage more precisely. According to the comment CTimer::waitForEvent() skipped for IOS because of performance :) |
Hi @alexpokotilo Gist |
Hi, |
Hello Alex, You are absolutly right. I dont like this fix too. I hope, that SRT team suppose the better solution. But I am not sure, that there is no problem for client to server connection. Can you apply my fix and check (outgoing connection) CPU usage before and after? Oleg |
Hi @ogolosovskiy,
I'm not on the SRT board and cannot accept push requests|ideas. So you have to follow standard github process to commit your fix. |
Frankly, this thing was looking very weird for me since the beginning, but unfortunately I'm not an expert for kevent. I'll tell you the situation. Currently there's no way to wait simultaneously for an event on an SRT socket and on a system socket (we haven't changed this mechanism since UDT, and I still think we can do better, we just don't have enough manpower to implement all ideas and requests). So, as a halfway solution, it is waiting up to 10ms for an event to happen on an SRT socket, and then re-checks the system sockets (with 0 timeout this time). That is, it can end prematurely waiting for this 10ms for an SRT socket (it can be interrupted by a signal from a condition variable), but the next check of a system socket will happen at worst in the next 10ms. If you can experiment a little bit and see if making this system work "default way" also on this system, I'll be appreciated. Recommended way is: add a new macro in the beginning of
And then add this as an extra condition in lines 442 (where timeout for kevent is decided) and 521 (which blocks the call to If you confirm it, we'll prepare a fix. |
To be clear -
Most client creates new connections, they don't need listen something on iOS. So they don't faces problem 1. |
What you say does completely make sense - if you don't have any system sockets to pick up, you also don't wait, even for any kevent timeout because you don't do any kevent. For 2, depends on the definition of "boost". What I understand was to gain here is to use less CPU uselessly, at least for described cases. @rndi , @jlsantiago0, can you elaborate on this? I am not able to confirm anything because I don't have this platform at hand. |
Fully agree. We should compare both - CPU and max packet rate. |
Hello @ogolosovskiy , @alexpokotilo , Could you see how well this patch works for you (it is pretty much what was originally suggested, but I would like to make sure we are testing with the same changes):
We've done some quick testing on our side and we are now getting <1% CPU usage when there is no connection in caller or listener modes (was 100% before the change). If you are still having trouble with this change in place, we will probably need to look at your API usage pattern next. If, on the other hand, you find that the issue is resolved, please open a pull request. Thanks! |
Thank you @rndi Max bandwith is insceasing or decrising after this fix? PS |
Can't do much about what was already done in UDT - I also agree that for a case when no sockets were ready until the timeout, it should simply return 0. But we can't change it so simply now that it's in use. This whole system works more-less this way - at least the default config for srt_epoll_wait:
The "very best" solution would be to find some general purpose event library and make the SRT socket state change an event triggered as a user event, whereas managing of the user FDs would be managed by this library. This way the waiting function can go to sleep no matter what and get woken up when the first socket reports readiness, no matter from which domain, without this wakeup once per 100ms. But for this very best solution we currently lack manpower and it's hard to say if we find any in the near future. So currently what can be done is to use waiting on EITHER kevent or SRT CV. The problem is that you have no guarantee that your epoll will be subscribed to any of them, although we can state that subscribing to system sockets only makes no sense. Waiting on kevent timeout may make sense, as long as you have at least one system socket subscribed to the system - so it MAY be a good idea to make a waiting timeout there, but only if you have any system sockets subscribed. If you don't - then the waiting on |
trying to get how CEPoll::wait works I've found|fixed and sent pull request 6da5bd3 |
@alexpokotilo |
I probably missed the fact that lrfds, lwfds not used by @ogolosovskiy at all :) |
@alexpokotilo |
@ogolosovskiy |
#605 approved by the way so if I better understand what's going on here I will help with fix and tests. |
The library consumes 100% CPU for iOS iOS TV
100% reproducible
Tested for iPhone 5s and 6plus
We see this problem without media connection and with media connection.
There is the loop forever here -
int CEPoll::wait(const int eid, set readfds, set writefds, int64_t msTimeOut, set lrfds, set lwfds)
{
....
while (true)
{
...
#if (TARGET_OS_IOS == 1) || (TARGET_OS_TV == 1)
#else
CTimer::waitForEvent();
#endif
}
return 0;
}
If we fix it, the problem is gone.
// #if (TARGET_OS_IOS == 1) || (TARGET_OS_TV == 1)
// #else
CTimer::waitForEvent();
// #endif
My measument results -
Without fix 100% CPU after library start
Without fix 100% CPU after start media connection (1 MBits)
After fix 1-2% CPU after library start
After fix 25-40% CPU after start media connection (1 MBits)
Profiler
https://i.gyazo.com/3334e3f324e93f7fb5637755273557a4.png
The text was updated successfully, but these errors were encountered: