Skip to content

Commit

Permalink
close #1575: set retry time to be 100ms on average per client instance
Browse files Browse the repository at this point in the history
  • Loading branch information
lfcnassif committed Mar 13, 2023
1 parent 7492ea0 commit 634f47d
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import iped.data.IItem;
import iped.engine.config.ConfigurationManager;
import iped.engine.core.Manager;
import iped.engine.io.TimeoutException;
import iped.engine.task.transcript.RemoteWav2Vec2Service.MESSAGES;
import iped.exception.IPEDException;
Expand All @@ -38,8 +39,6 @@ public class RemoteWav2Vec2TranscriptTask extends AbstractTranscriptTask {

private static final int MAX_CONNECT_ERRORS = 60;

private static final int RETRY_INTERVAL_MILLIS = 100;

private static final int UPDATE_SERVERS_INTERVAL_MILLIS = 60000;

private static List<Server> servers = new ArrayList<>();
Expand All @@ -66,6 +65,14 @@ public String toString() {
}
}

// See https://github.com/sepinf-inc/IPED/issues/1576
private int getRetryIntervalMillis() {
// This depends on how much time worker nodes need to consume their queue.
// Of course audios duration, nodes queue size and performance affect this.
// This tries to be fair with clients independent of their number of threads.
return Manager.getInstance().getNumWorkers() * 100;
}

@Override
public void init(ConfigurationManager configurationManager) throws Exception {

Expand Down Expand Up @@ -259,8 +266,8 @@ protected TextAndScore transcribeAudio(File tmpFile) throws Exception {

}

private static void sleepBeforeRetry(long lastRequestTime) throws InterruptedException {
long sleep = RETRY_INTERVAL_MILLIS - (System.currentTimeMillis() - lastRequestTime);
private void sleepBeforeRetry(long lastRequestTime) throws InterruptedException {
long sleep = getRetryIntervalMillis() - (System.currentTimeMillis() - lastRequestTime);
if (sleep > 0) {
Thread.sleep(sleep);
}
Expand Down

0 comments on commit 634f47d

Please sign in to comment.