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

ThreadPools: schedule a timeout check after adding command to queue #12319

Conversation

bleskes
Copy link
Contributor

@bleskes bleskes commented Jul 17, 2015

Our thread pools have support for timeout on a task. To support this, a special background task is schedule to run at timeout. That background task fires and check if the main task is still in the executor queue and then cancels it if needed. Currently we schedule this background task before adding the main task to the queue. If the timeout is very small (in tests we often use numbers like 2 ms) the background task can fire before the main one is added to the queue causing the timeout to be missed.

See http://build-us-00.elastic.co/job/es_g1gc_master_metal/11780/testReport/junit/org.elasticsearch.cluster/ClusterServiceTests/testTimeoutUpdateTask/

@bleskes
Copy link
Contributor Author

bleskes commented Jul 17, 2015

@imotov can you take a look?

Our thread pools have support for timeout on a task. To support this, a special background task is schedule to run at timeout. That background task fires and check if the main task is still in the executor queue and then cancels it if needed. Currently we schedule this background task before adding the main task to the queue. If the timeout is very small (in tests we often use numbers like 2 ms)  the background task can fire before the main one is added to the queue causing the timeout to be missed.

See http://build-us-00.elastic.co/job/es_g1gc_master_metal/11780/testReport/junit/org.elasticsearch.cluster/ClusterServiceTests/testTimeoutUpdateTask/
@@ -175,6 +177,7 @@ public Pending(Object task, Priority priority, long insertionOrder, boolean exec

@Override
public void run() {
started = true;
FutureUtils.cancel(timeoutFuture);
Copy link
Contributor

Choose a reason for hiding this comment

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

It would have helped me a lot to understand the logic if you added a comment here saying that timeoutFuture might not have been initialized here yet and because of this we have to try cleaning it here and in scheduleTimeout.

@imotov
Copy link
Contributor

imotov commented Jul 17, 2015

LGTM

@bleskes bleskes added v1.7.1 and removed v1.7.1 labels Jul 20, 2015
@bleskes bleskes closed this in e40eee5 Jul 20, 2015
@bleskes bleskes deleted the threadpool_schedule_timeout_after_execute branch July 20, 2015 08:51
bleskes added a commit to bleskes/elasticsearch that referenced this pull request Jul 20, 2015
Our thread pools have support for timeout on a task. To support this, a special background task is schedule to run at timeout. That background task fires and check if the main task is still in the executor queue and then cancels it if needed. Currently we schedule this background task before adding the main task to the queue. If the timeout is very small (in tests we often use numbers like 2 ms) the background task can fire before the main one is added to the queue causing the timeout to be missed.

See http://build-us-00.elastic.co/job/es_g1gc_master_metal/11780/testReport/junit/org.elasticsearch.cluster/ClusterServiceTests/testTimeoutUpdateTask/

Closes elastic#12319
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Core Core issues without another label v1.7.1 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants