Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Membase | Membase Developer Kit

Client Manager & Memcached Client support multi-thread or not?

5 replies [Last post]
  • Login or register to post comments
Tue, 06/22/2010 - 03:09
atapie
Offline
Joined: 06/21/2010
Groups: None

Hi,

I'm new to Membase memcached and learning to using smart client library to deal with servers. I have few questions about smart client:
[LIST=1]
[*]I want to know if client manager & memcached client is thread-safe or not?
[*]Can I construct one client manager at initialize phrase and keep it for re-use purpose? Does client manager keep updating nodes list from memcached cluster?
[/LIST]

Thank you so much,

Top
Thu, 06/24/2010 - 21:11
Perry Krug
Offline
Joined: 06/02/2010
Groups: None

Hi atapie, I'm looking into this now and will provide you an answer as soon as possible.

Perry

__________________

Forum support is great for free but sometimes you need a guaranteed response time and dedicated resources for your questions or issues.
Consider purchasing enterprise-level support from Membase: http://www.membase.com/products-and-services/overview
Call or email "sales -at- membase -dot- com" today!

Top
Fri, 06/25/2010 - 15:32
Perry Krug
Offline
Joined: 06/02/2010
Groups: None

atapie,

1) Yes, both the client manager and the clients that it returns are thread safe
2) Yes, you can construct one client manager and keep re-using it. The client manager will always return the most up-to-date client that it has and refresh the node list from the cluster.

Hope that helps, let me know if you need more information.

Thanks!

Perry

__________________

Forum support is great for free but sometimes you need a guaranteed response time and dedicated resources for your questions or issues.
Consider purchasing enterprise-level support from Membase: http://www.membase.com/products-and-services/overview
Call or email "sales -at- membase -dot- com" today!

Top
Sun, 06/27/2010 - 10:18
atapie
Offline
Joined: 06/21/2010
Groups: None

Hi Perry,

Thank you for your answers.

I just do some test with Northscale memcached using java client. The process is very simple:
1) Init Client Manager object
2) Start 10 threads, each thread call getClient() method to get Memcached client and perform get/set (20,000 hits total)

Result: Only one thread perform task.

What is the problem with this test? I expect 10 threads will run concurrently and generate 200,000 hits to memcached server.

Thanks,

Perry Krug;475 wrote:
atapie,

1) Yes, both the client manager and the clients that it returns are thread safe
2) Yes, you can construct one client manager and keep re-using it. The client manager will always return the most up-to-date client that it has and refresh the node list from the cluster.

Hope that helps, let me know if you need more information.

Thanks!

Perry

Top
Sun, 06/27/2010 - 11:24
ingenthr
Offline
Joined: 03/16/2010
Groups:

Hi Atapie,

That is actually the expected behavior.

The Smart Client uses [URL=http://code.google.com/p/spymemcached/]spymemcached[/URL]. By default, spymemcached has one worker thread per memcached server. Intentionally, operations from multiple user threads are converted into multiget calls from the single worker thread spymemcached has per server.

The advantage of doing so is that the client can then do things like multiget commands and get deduplication. The multiget commands give you the benefit of much more efficient usage of network resources and deliver higher throughput with still very good latency. The get deduplication means that your 10 threads can "share" the results of any outstanding operation. If two client threads are requesting the same object at approximately the same time, the client will return the same result to both threads. This is much more efficient for both the client threads and the server. Note that if lowest possibly latency is required, you can pass a custom ClientFactoryBuilder to the ClientManager turning off spymemcached's optimization.

So, the behavior you're seeing is by design and expected. There is no good reason for doing so from a functional perspective, but if you wanted no sharing of connections/resources between threads, you can create 10 instances of the ClientManager, and then each will create its own MemcachedClient. This will be much less efficient, but you'll see your 200,000 hits to the memcached server.

I hope that helps,

- Matt

Top
Mon, 06/28/2010 - 00:31
atapie
Offline
Joined: 06/21/2010
Groups: None

Hi Matt,

Thanks for your information,

I've found out the problem in this test. When more than one thread call getClient() method, only one thread can get the client and continue process, remaining threads seem not pass getClient() call. I fixed it with synchronized code, so each thread will call getClient() one after another.

Regards,
LamTT

Top
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker