Skip to content
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

APIs for easily changing the thread priority of default schedulers via hook. #3724

Closed
2 of 6 tasks
JakeWharton opened this issue Feb 21, 2016 · 4 comments
Closed
2 of 6 tasks

Comments

@JakeWharton
Copy link
Contributor

JakeWharton commented Feb 21, 2016

On Android, the main thread is a sacred holy land at which we must all worship. As such this means other threads (ideally) shouldn't be favorably scheduled in priority with it. For network and filesystem operations this usually means using low priority threads.

One solution is to just use low priority threads on our own schedulers, but this doesn't affect code using the standard io() and computation() schedulers. Unfortunately there's a whole bunch of ceremony around how various schedulers are initialized which includes a mixed bag of public vs. non-public types and APIs which makes replacing them in a scheduler hook difficult.

I think the most easy way to accomplish this is the following:

  • RxThreadFactory constructor overload which takes a thread priority to use. Not needed.
  • Factory methods on Schedulers for creating instances of io(), computation(), and newThread() except using a supplied ThreadFactory
    • Schedulers.createIoScheduler(ThreadFactory)
    • Schedulers.createComputationScheduler(ThreadFactory)
    • Schedulers.createNewThreadScheduler(ThreadFactory)

Nice to have:

  • Schedulers using these factory methods to create the default implementations. This involves moving the thread factories from the individual types "up" to Shedulers.
@JakeWharton
Copy link
Contributor Author

Happy to do some of the work if this sounds acceptable.

@stevegury
Copy link
Member

@JakeWharton I think that sound acceptable, I'm happy to review your PR.

@JakeWharton
Copy link
Contributor Author

This is a little more tricky than I had initially anticipated. Perhaps it's worth talking about a means of setting the default priority of the internal thread pools through a mechanism like properties as a separate, easier first step? Plus that would be a lot lower-overhead for Android users anyway, and we could even use the existing Android platform detection to lower the thread priority by default.

@JakeWharton
Copy link
Contributor Author

JakeWharton commented Jan 21, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants