0

I am using couchbase and xmemcached client in multithreaded java SE application. I am constantly observing that couchbase is unable to save last few keys whereas traditional memcached is setting all keys excellently. I am using exaclty same xmemcachedclient configuration in both cases.

Spring Configuration

<bean name="memcachedClient" class="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" destroy-method="shutdown">
<property name="configuration">
  <bean class="com.google.code.yanf4j.config.Configuration">
     <property name="handleReadWriteConcurrently" value="true" />
  </bean>
</property>
<property name="servers">
  <value>127.0.0.1:11211</value>
</property>
<!-- server's weights -->
<property name="weights">
  <list>
     <value>2</value>
  </list>
</property>
<!-- nio connection pool size -->
<!-- <property name="connectionPoolSize" value="4"></property> -->
<!-- Use binary protocol,default is TextCommandFactory -->
<property name="commandFactory">
  <bean class="net.rubyeye.xmemcached.command.BinaryCommandFactory" />
</property>
<!-- Distributed strategy -->
<property name="sessionLocator">
  <bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" />
</property>
<!-- Serializing transcoder -->
<property name="transcoder">
  <bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" />
</property>
<!-- ByteBuffer allocator -->
<property name="bufferAllocator">
  <bean class="net.rubyeye.xmemcached.buffer.SimpleBufferAllocator" />
</property>
</bean>

below is my test code that checks for missing keys

@Test
public void test100000HitMiss() 
{
    ArrayList<Integer> hits = new ArrayList<Integer>();
    ArrayList<Integer> misses = new ArrayList<Integer>();

    for(Integer i=0; i < 100000; i++)
    {
        try 
        {
            Object val = memcachedClient.get("2/C/TALAL" + i.toString());

            if(null == val)
                misses.add(i);
            else
                hits.add(i);
        } 
        catch (Exception ex) 
        {
            logger.error(ex);
        }
    }

    logger.info("Hits: " + hits.size() + " - Misses: " + misses.size());

}

Every time I run this test, I get 3 or 4 keys in misses array

Talal
  • 78
  • 6
  • Do you have a programming question, as this appears to be just an observation? – WiredPrairie Jul 01 '13 at 20:32
  • Are you receiving an error from couchbase? I assume you're using a different connection handle for each thread, if not you probably should. The only reason I can think of that you'd have trouble otherwise is if you are having resource (disk or more likely memory) issues on your couchbase server. – Don Dickinson Jul 02 '13 at 02:19
  • @WiredPrairie you can extract the question from my post... There is one for sure – Talal Jul 02 '13 at 20:41
  • @DonDickinson I am getting no error (or exception) while setting data in couchbase. What I am seeing is that Couchbase is unable to save last 3-4 keys most of the times in multithreaded settings, whereas single thread is saving all keys perfectly. I also wrote a test code that checks the missing keys and it always gives me the last few keys (in order). I guess xmemcached handles connections on its own or is there a setting that allows unique connection per thread ? – Talal Jul 02 '13 at 20:47
  • How are you checking for "missing keys"? (Again, you don't really have specific programming question ... it's missing lots of details). – WiredPrairie Jul 03 '13 at 01:05
  • @WiredPrairie check me post again, I have added my test code that checks for missing keys. What I am looking for is a solution to atleast know what couchbase is receiving when I set my key/value paris. Apparently, I am successfull in setting all 100000 keys without getting single exception then why I am unable to get all 100000 keys back ? – Talal Jul 04 '13 at 16:40
  • Have you tried with the Couchbase APIs? Could you try introducing a delay into the setting (multi-threading)? Is this clustered, etc.? – WiredPrairie Jul 04 '13 at 18:06
  • are you trying to use a single connection from a multi-threaded app? if so, you need to use a mutex or semaphore (i'm not a java guy, so i can't tell you how to do this) to protect the calls. OR use a separate connection for each thread. – Don Dickinson Sep 26 '13 at 01:24

0 Answers0