Merge pull request #426 from metamx/allow-disabling-opqueue

Disable memcached op-queue bound by default
This commit is contained in:
fjy 2014-03-11 11:36:53 -06:00
commit 455f6bea38
2 changed files with 23 additions and 4 deletions

View File

@ -32,6 +32,8 @@ import net.spy.memcached.FailureMode;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.MemcachedClientIF;
import net.spy.memcached.internal.BulkFuture;
import net.spy.memcached.ops.LinkedOperationQueueFactory;
import net.spy.memcached.ops.OperationQueueFactory;
import org.apache.commons.codec.digest.DigestUtils;
import javax.annotation.Nullable;
@ -56,7 +58,15 @@ public class MemcachedCache implements Cache
// always use compression
transcoder.setCompressionThreshold(0);
MemcachedOperationQueueFactory queueFactory = new MemcachedOperationQueueFactory(config.getMaxOperationQueueSize());
OperationQueueFactory opQueueFactory;
long maxQueueBytes = config.getMaxOperationQueueSize();
if(maxQueueBytes > 0) {
opQueueFactory = new MemcachedOperationQueueFactory(maxQueueBytes);
} else {
opQueueFactory = new LinkedOperationQueueFactory();
}
return new MemcachedCache(
new MemcachedClient(
new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
@ -68,7 +78,7 @@ public class MemcachedCache implements Cache
.setShouldOptimize(true)
.setOpQueueMaxBlockTime(config.getTimeout())
.setOpTimeout(config.getTimeout())
.setOpQueueFactory(queueFactory)
.setOpQueueFactory(opQueueFactory)
.build(),
AddrUtil.getAddresses(config.getHosts())
),

View File

@ -25,19 +25,28 @@ import javax.validation.constraints.NotNull;
public class MemcachedCacheConfig
{
// default to 30 day expiration for cache entries
// values greater than 30 days are interpreted by memcached as absolute POSIX timestamps instead of duration
@JsonProperty
private int expiration = 2592000; // What is this number?
private int expiration = 30 * 24 * 3600;
@JsonProperty
private int timeout = 500;
// comma delimited list of memcached servers, given as host:port combination
@JsonProperty
@NotNull
private String hosts;
@JsonProperty
private int maxObjectSize = 50 * 1024 * 1024;
@JsonProperty
private String memcachedPrefix = "druid";
// maximum size in bytes of memcached client operation queue. 0 means unlimited
@JsonProperty
private long maxOperationQueueSize = 256 * 1024 * 1024L; // 256 MB
private long maxOperationQueueSize = 0;
public int getExpiration()
{