Skip to content

Commit

Permalink
Add ability to configure timeoutThreshold
Browse files Browse the repository at this point in the history
By default, the timeout threshold for Spymemcached is set to 998, which means
that each connection will wait for 998 timeouts before considering the connection
to be dead and then re-establishing a new one.

This changeset adds the ability to configure the threshold from Shade.

Also, bump Spymemcached version to the latest one.
  • Loading branch information
lloydmeta committed May 6, 2017
1 parent cb3ebb6 commit 1c373f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resolvers ++= Seq(
)

libraryDependencies ++= Seq(
"net.spy" % "spymemcached" % "2.12.2",
"net.spy" % "spymemcached" % "2.12.3",
"org.slf4j" % "slf4j-api" % "1.7.23",
"io.monix" %% "monix-eval" % "2.3.0",
"ch.qos.logback" % "logback-classic" % "1.1.7" % Test,
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/shade/memcached/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ import scala.concurrent.duration._
* @param operationTimeout is the default operation timeout; When the limit is reached, the
* Future responses finish with Failure(TimeoutException)
*
* @param timeoutThreshold is the maximum number of timeouts for a connection that will be tolerated before
* the connection is considered dead and will not be retried. Once this threshold is breached,
* the client will consider the connection to be lost and attempt to establish a new one.
* If None, the default Spymemcached implementation is used (998)
*
* @param shouldOptimize If true, optimization will collapse multiple sequential get ops.
*
* @param opQueueFactory can be used to customize the operations queue,
Expand All @@ -63,6 +68,7 @@ case class Configuration(
protocol: Protocol.Value = Protocol.Binary,
failureMode: FailureMode.Value = FailureMode.Retry,
operationTimeout: FiniteDuration = 1.second,
timeoutThreshold: Option[Int] = None,
shouldOptimize: Boolean = false,
opQueueFactory: Option[OperationQueueFactory] = None,
writeQueueFactory: Option[OperationQueueFactory] = None,
Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/shade/memcached/MemcachedImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,21 @@ class MemcachedImpl(config: Configuration, ec: ExecutionContext) extends Memcach
builder
}

val withTimeoutThreshold = config.timeoutThreshold match {
case Some(threshold) => withTimeout.setTimeoutExceptionThreshold(threshold)
case _ => withTimeout
}

val withAuth = config.authentication match {
case Some(credentials) =>
withTimeout.setAuthDescriptor(
withTimeoutThreshold.setAuthDescriptor(
new AuthDescriptor(
Array("PLAIN"),
new PlainCallbackHandler(credentials.username, credentials.password)
)
)
case None =>
withTimeout
withTimeoutThreshold
}

withAuth
Expand Down

0 comments on commit 1c373f8

Please sign in to comment.