Skip to content

Commit

Permalink
Introduce rate limiter for docker daemon pinging (when testing connec…
Browse files Browse the repository at this point in the history
…tions) to resolve as a potential cause of #170
  • Loading branch information
rnorth committed Jul 10, 2016
1 parent 1f57d23 commit fcea783
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.github.dockerjava.netty.DockerCmdExecFactoryImpl;
import com.google.common.base.Throwables;
import org.jetbrains.annotations.Nullable;
import org.rnorth.ducttape.ratelimits.RateLimiter;
import org.rnorth.ducttape.ratelimits.RateLimiterBuilder;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -21,6 +23,11 @@ public abstract class DockerClientProviderStrategy {

protected DockerClientConfig config;

private static final RateLimiter PING_RATE_LIMITER = RateLimiterBuilder.newBuilder()
.withRate(2, TimeUnit.SECONDS)
.withConstantThroughput()
.build();

/**
* @throws InvalidConfigurationException if this strategy fails
*/
Expand Down Expand Up @@ -98,8 +105,11 @@ protected DockerClient getClientForConfig(DockerClientConfig config) {

protected void ping(DockerClient client, int timeoutInSeconds) {
Unreliables.retryUntilSuccess(timeoutInSeconds, TimeUnit.SECONDS, () -> {
client.pingCmd().exec();
return true;
return PING_RATE_LIMITER.getWhenReady(() -> {
LOGGER.debug("Pinging docker daemon...");
client.pingCmd().exec();
return true;
});
});
}

Expand Down

0 comments on commit fcea783

Please sign in to comment.