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

Scheduler shutdown capability #3149

Merged
merged 2 commits into from Oct 1, 2015
Merged

Conversation

akarnokd
Copy link
Member

Repost of #3022.

@benjchristensen
Copy link
Member

We still need to decide on the reset vs shutdown distinction: #3022 (comment)

What is your perspective? Do you have a strong opinion one way or another?

@akarnokd
Copy link
Member Author

With start/shutdown, there is a clear intention to stop everybody. With reset, any running code could respawn the threads and the new threads will resume leaking. I prefer start/shutdown.

@artem-zinnatullin
Copy link
Contributor

Agree, it will be great to have ability to stop Schedulers and prevent new workers from scheduling for apps that run in Servlets and other similar containers which can be stopped externally.

* This assumes Spsc or Spmc usage. This means only a single producer calling the on* methods. This is the Rx
* contract of an Observer (see http://reactivex.io/documentation/contract.html). Concurrent invocations of
* on* methods will not be thread-safe.
* This assumes Spsc or Spmc usage. This means only a single producer calling the on* methods. This is the Rx contract of an Observer.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change back the comment shortly.

@davidmoten
Copy link
Collaborator

I'm happy with the start/shutdown pair which seems to support my primary use cases:

  • resource release on webapp shutdown in container
  • resource release on completion of programs run by a framework that looked for unreleased threads (maven)
  • on ad-hoc basis ensuring schedulers are not running in the background on entry into a unit test (when running a suite)

Thanks @akarnokd!

@simonbasle
Copy link
Contributor

the start/shutdown semantic looks good to me, more explicit, best enforcement of shutdown 👮 and good compatibility with items mentioned by @davidmoten (which are pretty much our use cases as well) 👌

@maurcarvalho
Copy link

I'll following this thread to be notified when it's merged. Thanks @akarnokd

@simonbasle
Copy link
Contributor

@benjchristensen do you consider we have consensus on naming? after that it'd be showtime 🎬 😂

@benjchristensen benjchristensen modified the milestone: 1.0.x Aug 28, 2015
@daschl
Copy link
Contributor

daschl commented Sep 22, 2015

🆙 because so many customers from us run into this.

@maurcarvalho
Copy link

@daschl 👍

@stealthcode
Copy link

I would like a bit more context on what the goal is for the scheduler shutdown capability. @davidmoten and any others, please respond. Thanks.

resource release on webapp shutdown in container

What resources exactly need to be freed? Shutting down the schedulers would prevent new workers from being scheduled and would free up threads from the executor. Is this the desired behavior or is there some side effect that you are looking for?

resource release on completion of programs run by a framework that looked for unreleased threads (maven)

Could anyone name a framework that's impacted? Is the concern that open threads keep the framework from properly terminating?

on ad-hoc basis ensuring schedulers are not running in the background on entry into a unit test (when running a suite)

Would the TestScheduler solve this problem for you? This doesn't rely on singleton values and can be used to precisely test scheduling behavior.

@maurcarvalho
Copy link

@stealthcode I can answer the question 2. I hope it help you.

Could anyone name a framework that's impacted? Is the concern that open threads keep the framework from properly terminating?

  • Couchbase Java SDK

CB SDK are not able to finish some of they own threads because it is referring RxComputationThreadPool threads who can't be finished.

You can see more details about how this issue are affecting this framework here.
https://forums.couchbase.com/t/the-v2-of-the-java-client-leaks-rxjava-threads-on-shutdown/3890/19

@mjakubowski84
Copy link

@stealthcode I can give you the answer to your questions, too.

I'd like to use RxJava in the container (e.g. I'd like to use Jersey Rx Client on Tomcat). Unfortunately, it is impossible to shutdown RxComputationThreadPool-* threads and container has memory leaks. That causes that RxJava is inapplicable for my purposes :( And in my case - regarding question 1 - yes, shutting down all schedulers permanently is a desired behaviour. And TestScheduler is not a solution.
So, I'm really looking forward to seeing this PR accepted and released!

@maurcarvalho
Copy link

@mjakubowski84 👍 similar case here.

@stealthcode
Copy link

@mjakubowski84 understood. regarding the TestScheduler - this is meant for use in tests and highly recommended. When it comes to a container you would definitely want to use a real scheduler.

So, what I hear is that there is no desire to resume the scheduler once it is shut down. My concern is that by offering a SchedulerLifecycle.start() method we are inviting non-deterministic behavior in the case that someone wants to use this to teardown and then resume (in integration tests for example). Would it be acceptable to remove the start() method from the public interface and rename shutdown() to teardown() to more accurately describe the intent?

@stevegury
Copy link
Member

I don't have strong opinion between shutdown/teardown.
teardown makes the intent clearer, but shutdown is more idiomatic (in the context of java executor).

Otherwise the code LGTM 👍

@stevegury
Copy link
Member

Another thing, if we want to be more java idiomatic, maybe hiding the start() is the right thing to do.
It will also have the benefit of avoiding bug by misusage of the library (calling start() after a shutdown()).

@akarnokd
Copy link
Member Author

I can make Schedulers.start() package private so the tests can use it but I the Scheduler implementations have to keep their start public.

@stevegury
Copy link
Member

Please do, I believe that would be better.

@akarnokd
Copy link
Member Author

Done.

@daschl
Copy link
Contributor

daschl commented Sep 30, 2015

@akarnokd @stevegury folks, do you think its possible to get this into 1.0.15?

@stealthcode
Copy link

@akarnokd thanks.

@stealthcode
Copy link

I think this is fine 👍

@maurcarvalho
Copy link

Do you guys have a plan date to merge it?

@stealthcode
Copy link

@akarnokd I think it's appropriate that you merge this PR since you are most familiar with this code. If you think you are happy with it then feel free.

@akarnokd
Copy link
Member Author

akarnokd commented Oct 1, 2015

Oh, sorry, didn't recount the number of likes. Merging.

akarnokd added a commit that referenced this pull request Oct 1, 2015
@akarnokd akarnokd merged commit 241e154 into ReactiveX:1.x Oct 1, 2015
@chiangh123
Copy link

Where can I get the latest build with this fix? Maven central is still at 1.0.14.

@maurcarvalho
Copy link

@chiangh123 you can clone the project and build it from master. Good luck :)

@simonbasle
Copy link
Contributor

RxJava uses bintray for binaries and also publishes snapshots in JFrog's OSS artifactory, so you can add the following repository to your pom.xml:

<repository>
  <snapshots />
  <id>snapshots</id>
  <name>libs-snapshot</name>
  <url>http://oss.jfrog.org/artifactory/libs-snapshot</url>
</repository>

After that you should be able to depend on rxjava 1.0.15-SNAPSHOT.

@akarnokd akarnokd deleted the SchedulerShutdownV3 branch May 18, 2016 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet