Ticket #2074 (closed defect: fixed)

Opened 5 months ago

Last modified 7 weeks ago

Blocking select() on Android

Reported by: nanang Owned by: bennylp
Priority: normal Milestone: release-2.8
Component: pjsua-lib Version: trunk
Keywords: Cc:
Backport to 1.x milestone: Backported: no

Description (last modified by ming) (diff)

*IMPORTANT*: Further testing seems to suggest that separating worker threads doesn't improve the situation. Thus, it is recommended to use the approach officially suggested by the mobile platforms (Android, Apple, Windows) themselves, i.e. to completely deactivate all worker threads and shutdown or put your application in sleep mode, and rely on push notifications to wake it up when needed. This way, application will be able to consume as minimal power as possible.


Reported that on some platforms, such as Google Pixel XL running Android 8.0, and when device is not connected to computer (via USB), select() may block much longer than the specified timeout param, for example:

pjsip-2.7.1
NDK: r10d (similar result using r15c)
Device: Google Pixel XL
OS: Android 8.0

Charging (USB to computer):
19:20:13.781            TTT  select: n=1024, rv=0, elapsed=10, timeout=10
19:20:14.811            TTT  select: n=1024, rv=0, elapsed=10, timeout=10
19:20:15.023            TTT  select: n=1024, rv=1, elapsed=5, timeout=10
19:20:15.837            TTT  select: n=1024, rv=0, elapsed=10, timeout=10

Not charging (or to AC -> Not USB to computer)
19:23:41.819            TTT  select: n=1024, rv=0, elapsed=1959, timeout=10
19:23:41.841            TTT  select: n=1024, rv=0, elapsed=10, timeout=10
19:24:09.848            TTT  select: n=1024, rv=0, elapsed=26339, timeout=10
19:24:19.140            TTT  select: n=1024, rv=0, elapsed=9164, timeout=10

As currently each worker thread (also by default there will be only one worker thread) polls both, network events and timer events, such long block in network poll will affect timer events, e.g: TCP/TLS transport get disconnected by server/router as keep-alive packet not delivered in timely manner.

This ticket introduces compile time setting PJSUA_SEPARATE_WORKER_FOR_TIMER which when it is set, timer heap and network events will be polled from different worker thread, i.e: one thread will be dedicated for timer heap events polling and other thread(s) will poll network events.

Thanks Sébastien Tardif for the report.

Change History

comment:1 Changed 5 months ago by nanang

  • Status changed from new to closed
  • Resolution set to fixed

In 5712:

Fixed #2074: Introduced compile time setting PJSUA_SEPARATE_WORKER_FOR_TIMER to allow separate polling for timer events and network events.

comment:2 Changed 5 months ago by ming

  • Description modified (diff)

comment:3 Changed 5 months ago by ming

In 5715:

Re #2074: Revert the default sample Android setting to use separate worker threads, since it doesn't seem to fix the problem.

comment:4 Changed 5 months ago by ming

  • Description modified (diff)

comment:5 Changed 7 weeks ago by ming

In 5768:

Re #2074: Remove warning of unused functions

Note: See TracTickets for help on using tickets.