Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#2074 closed defect (fixed)

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)

*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:

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 (5)

comment:1 Changed 7 years ago by nanang

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

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 7 years ago by ming

  • Description modified (diff)

comment:3 Changed 7 years 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 7 years ago by ming

  • Description modified (diff)

comment:5 Changed 6 years ago by ming

In 5768:

Re #2074: Remove warning of unused functions

Note: See TracTickets for help on using tickets.