net.spy.memcached.OperationTimeoutException

2,187 views
Skip to first unread message

skp

unread,
May 31, 2010, 12:46:06 AM5/31/10
to spymemcached
Hi

Ive been getting an error,
"net.spy.memcached.OperationTimeoutException: Timeout waiting for
value". When I googled it , I found many forums on it.

One of them suggested to increase the memcached size. I increased it
to 1024MB from 512MB . But it didnt work. Another suggested to
increase the number of memcached client instances. I did that as well
(it was 1 originally). I made it to 5 and then 10 and then 20. None
worked.

Memcached server is 1.2.8 version, spymemcached is 2.5.

Please suggest what to do.

Complete error log is:
net.spy.memcached.OperationTimeoutException: Timeout waiting for value
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:
924)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:
939)
at edu.nyu.pdsg.tpcw.util.MyCache.get(MyCache.java:53)
at
edu.nyu.pdsg.tpcw.web.ExecuteSearchServlet.serveRequest(ExecuteSearchServlet.java:
51)
at edu.nyu.pdsg.tpcw.web.TPCWServlet.doGet(TPCWServlet.java:
60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
810)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
173)
at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:
96)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
202)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:
198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
104)
at
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:
81)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
102)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:
177)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
137)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
118)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
520)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:
160)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
799)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:
577)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:636)
Caused by:
net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out
waiting for operation - failing node: /127.0.0.1:11211
at
net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:
65)
at net.spy.memcached.internal.GetFuture.get(GetFuture.java:37)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:
917)


Thanks

ashish saxena

unread,
Jun 1, 2010, 11:46:00 AM6/1/10
to spymem...@googlegroups.com
what you set OperationTime in your settings... I guess u should increase dat time


--
You received this message because you are subscribed to the Google Groups "spymemcached" group.
To post to this group, send email to spymem...@googlegroups.com.
To unsubscribe from this group, send email to spymemcached...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spymemcached?hl=en.


skp

unread,
Jun 1, 2010, 11:48:30 AM6/1/10
to spymemcached
I had set the operation time this way,
MemcachedClient client=new MemcachedClient(
new ConnectionFactoryBuilder()
.setOpTimeout(15000).build(), AddrUtil
.getAddresses("127.0.0.1:11211"));

It still gave the error. Is this the right way of setting the time?


On Jun 1, 11:46 am, ashish saxena <ashis...@gmail.com> wrote:
> what you set OperationTime in your settings... I guess u should increase dat
> time
>
> > spymemcached...@googlegroups.com<spymemcached%2Bunsu...@googlegroups.com>
> > .

ashish saxena

unread,
Jun 1, 2010, 12:51:23 PM6/1/10
to spymem...@googlegroups.com
here is my spymemcache inplementation file hope this will help u
 
/*
    * Implementation of the {@link mtvi.util.cache.distributed.Memcache} interface
  * which makes use of the spy.memcached Memcache client library. ion of
  * spymemcache which include three connection factory and default one is Ketama.
 * 
 * Here CacheOperationTimeOut:Is the number of seconds that can pass before a
  * memcache operation (get, set, delete, etc.) tmes out.A default value between
  * 2 and 5 (sec) is appropriate for this setting. defaultExpirationTimeSeconds -
  * Is the number of seconds an object will remain in memcache before it expires
  * and gets removed from the cache. Once an object is put into memcache, it
  * should stay there for a long time.A default value between 3600 and 7200 (1 to   * 2 hours) is appropriate for this setting.
  * 
   
**/  
 

import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

-import mtvi.util.cache.distributed.Memcache;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.BinaryConnectionFactory;
import net.spy.memcached.KetamaConnectionFactory;
import net.spy.memcached.MemcachedClient;
+
import org.apache.commons.lang.StringUtils;
+
import com.mtvnet.platform.MTVNGenericService;
import com.mtvnet.platform.MTVNServiceException;

@@ -35,296 +36,283 @@

public class SpyMemcache extends MTVNGenericService implements Memcache {

- // Distributed spymemcached client instance
- private MemcachedClient client;
- private String[] servers;
- private int cacheOperationTimeoutSeconds;
- private long defaultExpirationTimeSeconds;
- private String connectionType;
- private String spyLoggerClassName;
+    // Distributed spymemcached client instance
+    private MemcachedClient client;
+    private String[] servers;
+    private int cacheOperationTimeoutSeconds;
+    private long defaultExpirationTimeSeconds;
+    private String connectionType;
+    private String spyLoggerClassName;

- /**
- * default constructor injected
- */
- public SpyMemcache(MemcachedClient client) {
- if(client==null)
- this.client=client;
-  
- }
+    /**
+     * Constructor with no arguments for class to be used as nucleus component
+     */
+    public SpyMemcache() {

- public void doStartService() throws MTVNServiceException {
+    }

- super.doStartService();
- setupClient();
- }
+    /**
+     * default constructor injected
+     */
+    public SpyMemcache(MemcachedClient client) {
+        if (client == null)
+            this.client = client;

- /**
- * Cleans up asynchronous-refresh threads
- */
- public void doStopService() throws MTVNServiceException {
- shutdown();
- }
+    }

- /**
- * Get a memcached client connected to server
- */
- public void setupClient() throws MTVNServiceException {
- System.setProperty("net.spy.compat.log.LoggerImpl",getSpyLoggerClassName());
- try {
- if (getConnectionType().equalsIgnoreCase("default")) {
- // Create a defaultConnectionFactory.
- client = new MemcachedClient(AddrUtil.getAddresses(StringUtils
- .join(getServers(), ' ')));
- if (isLoggingDebug()) {
- logDebug("Msg: SimpleConnection : " + client);
- }
- } else if (getConnectionType().equalsIgnoreCase("binary")) {
- // Create a binaryConnectionFactory with the default parameters.
- client = new MemcachedClient(new BinaryConnectionFactory(),
- AddrUtil.getAddresses(StringUtils.join(getServers(),
- ' ')));
- if (isLoggingDebug()) {
- logDebug("Msg: BinaryConnection : " + client);
- }
- } else {
- // Create a KetamaConnectionFactory with the default parameters.
- client = new MemcachedClient(new KetamaConnectionFactory(),
- AddrUtil.getAddresses(StringUtils.join(getServers(),
- ' ')));
- if (isLoggingDebug()) {
- logDebug("Msg: KetamaConnection : " + client);
- }
- }
- } catch (IOException e) {
- if (isLoggingError()) {
- throw new MTVNServiceException("fail to get"
- + getConnectionType() + "connection client", e
- .getCause());
- }
- }
+    public void doStartService() throws MTVNServiceException {

- }
+        super.doStartService();
+        setupClient();
+    }

- /**
- * Method returns the Object against the key or a null value if key value is
- * not available.
- *
- * @param key
- *            value in the cache
- * @return the Object
- */
+    /**
+     * Cleans up asynchronous-refresh threads
+     */
+    public void doStopService() throws MTVNServiceException {
+        shutdown();
+    }

- public Object get(String key) {
- Object myObj = null;
- Future<Object> future = client.asyncGet(key);
- try {
- myObj = future.get(getCacheOperationTimeoutSeconds(),
- TimeUnit.SECONDS);
- } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
- logError("Timeout attempting get item from memcache after "
- + getCacheOperationTimeoutSeconds() + " seconds");
- } catch (Exception e) {
- logError("Failed to get an item from memcache", e.getCause());
- }
- if (isLoggingDebug()) {
- logDebug("Msg: Get myObj " + myObj);
- }
- return myObj;
- }
+    /**
+     * Get a memcached client connected to server
+     */
+    private void setupClient() throws MTVNServiceException {
+        System.setProperty("net.spy.compat.log.LoggerImpl", getSpyLoggerClassName());
+        try {
+            if (getConnectionType().equalsIgnoreCase("default")) {
+                // Create a defaultConnectionFactory.
+                client = new MemcachedClient(AddrUtil.getAddresses(StringUtils.join(getServers(),
+                        ' ')));
+                if (isLoggingDebug()) {
+                    logDebug("Configuring memcache client with default connection protocol ");
+                }
+            } else if (getConnectionType().equalsIgnoreCase("binary")) {
+                // Create a binaryConnectionFactory with the default parameters.
+                client = new MemcachedClient(new BinaryConnectionFactory(), AddrUtil
+                        .getAddresses(StringUtils.join(getServers(), ' ')));
+                if (isLoggingDebug()) {
+                    logDebug("Configuring memcache client with binary connection protocol");
+                }
+            } else {
+                // Create a KetamaConnectionFactory with the default parameters.
+                client = new MemcachedClient(new KetamaConnectionFactory(), AddrUtil
+                        .getAddresses(StringUtils.join(getServers(), ' ')));
+                if (isLoggingDebug()) {
+                    logDebug("Configuring memcache client with Ketama connection protocol");
+                }
+            }
+        } catch (IOException e) {
+            if (isLoggingError()) {
+                throw new MTVNServiceException("fail to get   " + getConnectionType()
+                        + "  connection client", e.getCause());
+            }
+        }

- /**
- * Add an object to the cache if it does not exist.
- *
- * @param key
- *            value in the cache
- * @param the
- *            Object of key value pair
- * @param expiration
- *            the time in seconds value will be there in cache
- * @return boolean for sucess/failure to add in cache
- */
+    }

- public boolean add(String key, Object value, int expiration) {
- Future<Boolean> future = client.add(key, expiration, value);
- try {
- return future.get(getCacheOperationTimeoutSeconds(),
- TimeUnit.SECONDS);
- } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
- if (isLoggingError()) {
- logError("Timeout attempting add item in memcache after "
- + getCacheOperationTimeoutSeconds() + " seconds");
- }
- } catch (Exception e) {
- if (isLoggingError()) {
- logError("Failed to add item in memcache", e.getCause());
- }
- }
- return false;
- }
+    /**
+     * Method returns the Object against the key or a null value if key value is
+     * not available.
+     *
+     * @param key value in the cache
+     * @return the Object
+     */

- /**
- * Delete the given key from the cache.
- *
- * @param key
- *            value in the cache that needs to delete
- * @return boolean for sucess/failure to delete in cache
- */
+    public Object get(String key) {
+        Object myObj = null;
+        Future<Object> future = client.asyncGet(key);
+        try {
+            myObj = future.get(getCacheOperationTimeoutSeconds(), TimeUnit.SECONDS);
+        } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
+            logError("Timeout attempting get item from memcache after "
+                    + getCacheOperationTimeoutSeconds() + " seconds");
+        } catch (Exception e) {
+            logError("Failed to get an item from memcache", e.getCause());
+        }
+        if (isLoggingDebug()) {
+            logDebug("Msg: Get myObj " + myObj);
+        }
+        return myObj;
+    }

- public boolean delete(String key) {
- Future<Boolean> future = client.delete(key);
- try {
- return future.get(getCacheOperationTimeoutSeconds(),
- TimeUnit.SECONDS);
- } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
- if (isLoggingError()) {
- logError("Timeout attempting delete item from memcache after "
- + getCacheOperationTimeoutSeconds() + " seconds");
- }
- } catch (Exception e) {
- if (isLoggingError()) {
- logError("Failed to delete an item in memcache", e.getCause());
- }
- }
- return false;
- }
+    /**
+     * Add an object to the cache if it does not exist.
+     *
+     * @param key value in the cache
+     * @param the Object of key value pair
+     * @param expiration the time in seconds value will be there in cache
+     * @return boolean for sucess/failure to add in cache
+     */

- /**
- * Set an object in the cache regardless of any existing value.
- *
- * @param key
- *            value in the cache
- * @param the
- *            Object of key value pair
- * @param cacheTimeMillis
- * @return boolean for sucess/failure to set in cache
- */
+    public boolean add(String key, Object value, int expiration) {
+        Future<Boolean> future = client.add(key, expiration, value);
+        try {
+            return future.get(getCacheOperationTimeoutSeconds(), TimeUnit.SECONDS);
+        } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
+            if (isLoggingError()) {
+                logError("Timeout attempting add item in memcache after  "
+                        + getCacheOperationTimeoutSeconds() + " seconds");
+            }
+        } catch (Exception e) {
+            if (isLoggingError()) {
+                logError("Failed to add item in memcache ", e.getCause());
+            }
+        }
+        return false;
+    }

- public boolean set(String key, Object value, long cacheTimeMillis) {
- int expiration = (int) (cacheTimeMillis / 1000);
- if (isLoggingDebug()) {
- logDebug("Msg: In Set method: ");
- }
- Future<Boolean> future = client.set(key, expiration, value);
- try {
- return future.get(getCacheOperationTimeoutSeconds(),
- TimeUnit.SECONDS);
- } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
- if (isLoggingError()) {
- logError("Timeout attempting set item in memcache after "
- + getCacheOperationTimeoutSeconds() + " seconds");
- }
- } catch (Exception e) {
- if (isLoggingError()) {
- logError("Failed to set an item in memcache", e.getCause());
- }
- }
- return false;
- }
+    /**
+     * Delete the given key from the cache.
+     *
+     * @param key value in the cache that needs to delete
+     * @return boolean for sucess/failure to delete in cache
+     */

- /**
- * Set an object in the cache regardless of any existing value.
- *
- * @param key
- *            value in the cache
- * @param the
- *            Object of key value pair
- *
- * @return boolean for sucess/failure to set in cache
- */
+    public boolean delete(String key) {
+        Future<Boolean> future = client.delete(key);
+        try {
+            return future.get(getCacheOperationTimeoutSeconds(), TimeUnit.SECONDS);
+        } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
+            if (isLoggingError()) {
+                logError("Timeout attempting delete item from memcache after "
+                        + getCacheOperationTimeoutSeconds() + " seconds");
+            }
+        } catch (Exception e) {
+            if (isLoggingError()) {
+                logError("Failed to delete an item in memcache ", e.getCause());
+            }
+        }
+        return false;
+    }

- public boolean set(String key, Object o) {
- return set(key, o, getDefaultExpirationTimeSeconds() * 1000);
- }
+    /**
+     * Set an object in the cache regardless of any existing value.
+     *
+     * @param key value in the cache
+     * @param the Object of key value pair
+     * @param cacheTimeMillis
+     * @return boolean for sucess/failure to set in cache
+     */

- /**
- * Replace an object with the given value if there is already a value for
- * the given key.
- *
- * @param key
- *            value in the cache
- * @param the
- *            Object of key value pair
- * @param expiration
- *            the time in seconds value will be there in cache
- * @return boolean for sucess/failure to replace value in cache
- */
+    public boolean set(String key, Object value, long cacheTimeMillis) {
+        int expiration = (int) (cacheTimeMillis / 1000);
+        if (isLoggingDebug()) {
+            logDebug("Msg: In Set method: ");
+        }
+        Future<Boolean> future = client.set(key, expiration, value);
+        try {
+            return future.get(getCacheOperationTimeoutSeconds(), TimeUnit.SECONDS);
+        } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
+            if (isLoggingError()) {
+                logError("Timeout attempting set item in memcache after "
+                        + getCacheOperationTimeoutSeconds() + " seconds");
+            }
+        } catch (Exception e) {
+            if (isLoggingError()) {
+                logError("Failed to set an item in memcache ", e.getCause());
+            }
+        }
+        return false;
+    }

- public boolean replace(String key, Object value, int expiration) {
- Future<Boolean> future = client.replace(key, expiration, value);
- try {
- return future.get(getCacheOperationTimeoutSeconds(),
- TimeUnit.SECONDS);
- } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
- if (isLoggingError()) {
- logError("Timeout attempting replace item in memcache after "
- + getCacheOperationTimeoutSeconds() + " seconds");
- }
- } catch (Exception e) {
- if (isLoggingError()) {
- logError("Failed to replace an item in memcache", e.getCause());
- }
- }
- return false;
- }
+    /**
+     * Set an object in the cache regardless of any existing value.
+     *
+     * @param key value in the cache
+     * @param the Object of key value pair
+     *
+     * @return boolean for sucess/failure to set in cache
+     */

- /**
- * Array of distributed MemCached Server e.g "server1.mydomain.com:11211",
- * "server2.mydomain.com:11211", "server3.mydomain.com:11211"
- */
+    public boolean set(String key, Object o) {
+        return set(key, o, getDefaultExpirationTimeSeconds() * 1000);
+    }

- public String[] getServers() {
- return servers;
- }
+    /**
+     * Replace an object with the given value if there is already a value for
+     * the given key.
+     *
+     * @param key value in the cache
+     * @param the Object of key value pair
+     * @param expiration the time in seconds value will be there in cache
+     * @return boolean for sucess/failure to replace value in cache
+     */

- public void setServers(String[] servers) {
- this.servers = servers;
- }
+    public boolean replace(String key, Object value, int expiration) {
+        Future<Boolean> future = client.replace(key, expiration, value);
+        try {
+            return future.get(getCacheOperationTimeoutSeconds(), TimeUnit.SECONDS);
+        } catch (TimeoutException e) { // java.util.concurrent.TimeoutException
+            if (isLoggingError()) {
+                logError("Timeout attempting replace item in memcache after "
+                        + getCacheOperationTimeoutSeconds() + " seconds ");
+            }
+        } catch (Exception e) {
+            if (isLoggingError()) {
+                logError("Failed to replace an item in memcache", e.getCause());
+            }
+        }
+        return false;
+    }

- public String getConnectionType() {
- return connectionType;
- }
+    /**
+     * Array of distributed MemCached Server e.g "server1.mydomain.com:11211",
+     * "server2.mydomain.com:11211", "server3.mydomain.com:11211"
+     */

- public void setConnectionType(String connectionType) {
- this.connectionType = connectionType;
- }
+    public String[] getServers() {
+        return servers;
+    }

- public int getCacheOperationTimeoutSeconds() {
- return cacheOperationTimeoutSeconds;
- }
+    public void setServers(String[] servers) {
+        this.servers = servers;
+    }

- public void setCacheOperationTimeoutSeconds(int cacheOperationTimeoutSeconds) {
- this.cacheOperationTimeoutSeconds = cacheOperationTimeoutSeconds;
- }
+    public String getConnectionType() {
+        return connectionType;
+    }

- public long getDefaultExpirationTimeSeconds() {
- return defaultExpirationTimeSeconds;
- }
+    public void setConnectionType(String connectionType) {
+        this.connectionType = connectionType;
+    }

- public void setDefaultExpirationTimeSeconds(
- long defaultExpirationTimeSeconds) {
- this.defaultExpirationTimeSeconds = defaultExpirationTimeSeconds;
- }
+    public int getCacheOperationTimeoutSeconds() {
+        return cacheOperationTimeoutSeconds;
+    }

- public void setSpyLoggerClassName(String spyLoggerClassName) {
- this.spyLoggerClassName = spyLoggerClassName;
- }
- public String getSpyLoggerClassName() {
- return spyLoggerClassName;
- }
+    public void setCacheOperationTimeoutSeconds(int cacheOperationTimeoutSeconds) {
+        this.cacheOperationTimeoutSeconds = cacheOperationTimeoutSeconds;
+    }

- /**
- * Clear the spymemcache client
- */
- public void clear() {
- client.flush();
- }
+    public long getDefaultExpirationTimeSeconds() {
+        return defaultExpirationTimeSeconds;
+    }

- /**
- * shutdown the spymemcache client
- */
+    public void setDefaultExpirationTimeSeconds(long defaultExpirationTimeSeconds) {
+        this.defaultExpirationTimeSeconds = defaultExpirationTimeSeconds;
+    }

- public void shutdown() {
- client.shutdown();
- }
+    public void setSpyLoggerClassName(String spyLoggerClassName) {
+        this.spyLoggerClassName = spyLoggerClassName;
+    }

+    public String getSpyLoggerClassName() {
+        return spyLoggerClassName;
+    }
+
+    /**
+     * Clear the spymemcache client
+     */
+    public void clear() {
+        client.flush();
+    }
+
+    /**
+     * shutdown the spymemcache client
+     */
+
+    public void shutdown() {
+        client.shutdown();
+    }
+
}

To unsubscribe from this group, send email to spymemcached...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages