tvm icon indicating copy to clipboard operation
tvm copied to clipboard

[RFC] Android RPC service performance issues

Open alex-weaver opened this issue 8 years ago • 4 comments

Using a service process for RPC in Android is causing significant performance regressions (approximately by a factor of 3 on my test device).

@merrymercy identified the watchdog process commit as the cause in #1426 The service/watchdog process was added in #1387

I've confirmed that on my device performance returns to its previous level if I roll back MainActivity.java to before the service/watchdog was introduced.

It is unclear precisely why this is occurring, but I've done some debugging on this and found the following:

  • The issue persists if the RPCProcessor is launched in a service but the watchdog is removed. This demonstrates the performance issue is not due to the interaction with the watchdog, but simply due to running in the service process.
  • Adding a timer in C++ around GraphRuntime::Run confirms that almost all of the processing time is taken by this function, and not by java code.
  • I have tried setting the service as a foreground service (how to do this correctly is somewhat poorly documented), since by default service processes in Android are given lower priority than app processes[1]. This did not make any difference :(

Any ideas as to why this might be occurring would be appreciated

[1] https://medium.com/google-developers/who-lives-and-who-dies-process-priorities-on-android-cb151f39044f

@tqchen @eqy

alex-weaver avatar Jul 14 '18 19:07 alex-weaver

Thanks for looking into this! We’re currently in the process of refactoring the watchdog implementation in the way you suggested (moving back to the activity process). This requires getting the watchdog (moving to a service) to persist when the main activity dies, which may be tricky, but we have a WIP that looks fairly promising. If this does not work then we may move to a two-app solution, but ideally one app is less clunky to use. On Sat, Jul 14, 2018 at 12:11 PM alex-weaver [email protected] wrote:

Using a service process for RPC in Android is causing significant performance regressions (approximately by a factor of 3 on my test device).

@merrymercy https://github.com/merrymercy identified the watchdog process commit as the cause in #1426 https://github.com/dmlc/tvm/pull/1426 The service/watchdog process was added in #1387 https://github.com/dmlc/tvm/pull/1387

I've confirmed that on my device performance returns to its previous level if I roll back MainActivity.java to before the service/watchdog was introduced.

It is unclear precisely why this is occurring, but I've done some debugging on this and found the following:

  • The issue persists if the RPCProcessor is launched in a service but the watchdog is removed. This demonstrates the performance issue is not due to the interaction with the watchdog, but simply due to running in the service process.
  • Adding a timer in C++ around GraphRuntime::Run confirms that almost all of the processing time is taken by this function, and not by java code.
  • I have tried setting the service as a foreground service (how to do this correctly is somewhat poorly documented), since by default service processes in Android are given lower priority than app processes[1]. This did not make any difference :(

Any ideas as to why this might be occurring would be appreciated

[1] https://medium.com/google-developers/who-lives-and-who-dies-process-priorities-on-android-cb151f39044f

@tqchen https://github.com/tqchen @eqy https://github.com/eqy

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dmlc/tvm/issues/1433, or mute the thread https://github.com/notifications/unsubscribe-auth/ACIsgB98RgfUrEHsdKhACFL_nwVrih_Aks5uGkI7gaJpZM4VP9-h .

eqy avatar Jul 14 '18 19:07 eqy

That sounds great :)

Bringing the RPCProcessor back into the activity will definitely resolve the issue, I've just been digging into this because it's somehow unsatisfying without knowing why it was broken in the first place!

EDIT: PS if you find yourself needing foreground services, this may be helpful (especially around the changes in Android O): https://proandroiddev.com/deep-dive-into-android-services-4830b8c9a09

alex-weaver avatar Jul 14 '18 19:07 alex-weaver

https://github.com/dmlc/tvm/pull/1457

tqchen avatar Jul 19 '18 22:07 tqchen

close this for now as @merrymercy confirmed that the performance regression is fixed by #1457 @alex-weaver it would be great if you can also verify independently

tqchen avatar Jul 20 '18 03:07 tqchen