-
Notifications
You must be signed in to change notification settings - Fork 74
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
RxHelper::blockingScheduler should order by Worker instead of by Context #245
Comments
If calling |
If The scheduler should be able to run tasks without requiring context order to be maintained, while still preserving the worker order. |
Specifically, if I ran: Scheduler s = RxHelper.createBlocking(vertx);
Context context = vertx.getOrCreateContext();
context.runOnContext(ignored -> {
Scheduler.Worker w1 = s.createWorker();
Scheduler.Worker w2 = s.createWorker();
w1.schedule(() -> /*Runnable A*/);
w1.schedule(() -> /*Runnable B*/);
w2.schedule(() -> /*Runnable C*/);
w2.schedule(() -> /*Runnable D*/);
}); Currently I will expect the run order to be one after the other |
Thanks for the details. The purpose of That being said, when Would you mind contributing a fix? |
@tsegismont I'm on it. Should the current |
@Gattag no, if it's not comliant it's a bug and should be fixed. For the fix, it might useful to create a |
I would also like to note that the scheduler introduces a potential point for drift in the private void run(Object arg) {
synchronized (TimedAction.this) {
if (disposed) {
return;
}
}
action.run();
/*Thread could pause here for any length of time*/
synchronized (TimedAction.this) {
if (!disposed) {
if (periodMillis > 0) {
schedule(periodMillis);
} else {
disposed = true;
actions.remove(this);
}
}
}
} It reschedules the task after each run with the same given period. Even though the task is rescheduled before the execution of the task is completed, this still introduces a potential accumulation of drift in the periodicity of it execution. I'm not sure if I'm am being nitpicky or not, but I think this should have just used |
Please go ahead. Make sure the periodic timer is canceled with the subscription. |
@tsegismont Unless I'm missing something, currently there is no way to provide a custom Currently, I think I have a complete scheduler that meets everything that need to be fixed and there is no more blocking code anywhere. The issue is that it implements its own queue and wraps the From here, in terms of the two things I mentioned I'm not sure how I should proceed (very new to Vert.x contribution), should I stick with I got or should I look into making changes to core? And I apologize for all the questions |
Right. We need a PR to Vert.x core that:
We agreed in previous comments that the current implementation is fine when
Yes please.
No worries |
So I talked about this more in the PR I made, but I have a delima. When To be honest, I made more fuss of this little sub issue than I should have as I can't see any reason why RxJava would be sharing workers across contexts, but maybe I'm wrong, I will do a little bit of investigating and see.
I'm already on this, it will also expose methods to force the context to ensure that when it runs the blocking handler, the thread has the correct context. (This does have a purpose, albeit small) |
Describe the feature (might be a bug? I don't know what to call it)
Currently the
RxHelper::blockingScheduler
with ordered execution enabled uses theContextScheduler
. TheContextScheduler
always executes the tasks based on the current context, all tasks on the current context are ordered one after another, irrespective of theWorker
it was created from.The rx
Scheduler.Worker
class documentation reads:Represents an isolated, sequential worker of a parent Scheduler for executing Runnable tasks
. It appears to have no requirement beyond tasks submitted to the worker being executed in order. The default rx scheduler for io tasks isio.reactivex.internal.schedulers.IoScheduler
and the implementation of eachWorker
it creates is a single threadedScheduledExecutorService
.The point of saying this is just that, tasks should be scheduled in order respective to the Worker, not the Context they were created from and this is supported by the documentation and implementation of RxJava2. I would like RxJava2 io tasks to only be run in order only when ordering is required by the spec, but not more. And to have more parallelism without breaking the expectation that tasks submitted to a Worker are executed in order, which setting ordered to false on
RxHelper::blockingScheduler
does. I believe this should improve parallelism of io tasks without breaking spec.Contribution
I'll implement it as long as I am not crazy about the premise/rational (am I?). I already sorta did in a scheduler I wrote, by storing a queue of tasks in the workers and you get the rest.
The text was updated successfully, but these errors were encountered: