From b969077d18e5d19e291daef18aad1627bdbced8b Mon Sep 17 00:00:00 2001 From: Luis Uguina Date: Wed, 20 May 2020 22:32:39 +1000 Subject: [PATCH] Optimise the retries algorithm for the "no job" server response (#230) * Implement an optimised retries algorithm for the "no job" server response * formating Co-authored-by: Laurent Clouet --- src/com/sheepit/client/Client.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/com/sheepit/client/Client.java b/src/com/sheepit/client/Client.java index bd1cdfd..3abcc68 100644 --- a/src/com/sheepit/client/Client.java +++ b/src/com/sheepit/client/Client.java @@ -69,6 +69,7 @@ public class Client { private int uploadQueueSize; private long uploadQueueVolume; + private int noJobRetryIter; public Client(Gui gui_, Configuration configuration, String url_) { this.configuration = configuration; @@ -86,6 +87,7 @@ public class Client { this.uploadQueueSize = 0; this.uploadQueueVolume = 0; + this.noJobRetryIter = 0; } public String toString() { @@ -292,8 +294,9 @@ public class Client { } if (this.renderingJob == null) { // no job - int wait = ThreadLocalRandom.current().nextInt(10, 30 + 1); // max is exclusive - int time_sleep = 1000 * 60 * wait; + int[] retrySchemeInSeconds = {300000, 480000, 720000, 900000, 1200000}; // 5, 8, 12, 15 and 20 minutes + + int time_sleep = retrySchemeInSeconds[(this.noJobRetryIter < retrySchemeInSeconds.length) ? this.noJobRetryIter++ : (retrySchemeInSeconds.length - 1)]; this.gui.status(String.format("No job available. Will try again at %tR", new Date(new Date().getTime() + time_sleep))); this.suspended = true; @@ -313,6 +316,9 @@ public class Client { this.log.debug("Got work to do id: " + this.renderingJob.getId() + " frame: " + this.renderingJob.getFrameNumber()); + // As the server allocated a new job to this client, reset the no_job waiting algorithm + this.noJobRetryIter = 0; + ret = this.work(this.renderingJob); if (ret == Error.Type.RENDERER_KILLED) { this.log.removeCheckPoint(step);