Using Moxi and vBucket
Hi,
I am using spymemcached-2.7.jar, which is vBucket aware client.
Here is my code
URI base = new URI("http://<membase-server-ip>:8091/pools");
ArrayList baseURIs = new ArrayList();
baseURIs.add(base);
MemcachedClient c = new MemcachedClient(baseURIs, "bucket1", "");I wish to use the moxi as the base url instead of the actual membase server, because, that will help me adding a new membase servers to the cluster without changing this code, or a config file & without restarting application servers.
I tried
URI base = new URI("http://localhost:11211/pools"); and installed moxi on the client machine.
But it doesn't work. It didn't give any error, it just wait in order to get connected.
What am I doing wrong? Please help.
Thanks
Abhilash
Thanks Alex.
Yes, my local moxi is configured to talk to the cluster.
/opt/moxi/bin/moxi -u membase -d http://<membase-server-ip>:8091/pools/default/bucketsStreaming/bucket1
and I have created bucket1 via Admin console.
Should I use a different MemcachedClient constructor to work with Moxi & vBucket?
The only reason, why I am trying to do it with Moxi is that, I need not change the code when I add a new membase server, and I need not change this code to work with different development environments.
Thanks
Abhilash
First off, the following will not work correctly:
URI base = new URI("http://localhost:11211/pools");
The reason that you use port 8091 is that it's the cluster management port. Spymemcached will connect to this port and get the cluster configuration. So if you put one URI into the Spymemcached constructor then Spymemcached will actually connect to all of the nodes in the cluster. Let's say that later you add another server to your cluster. Since Spymemcached is connected to the cluster management port it will receive an updated configuration from the cluster and immediately begin sending requests to the new server. I will give instruction on how to connect to moxi with Symemcached below, but I think what you really want to do is do things the way that you are currently doing them because it will give you the lowest latency requests and Spymemcached will react to any type of topology change in the cluster.
Connecting to moxi:
In order to do this you should use the constructor that takes a list of InetSocketAddresses. This constructor will allow you to connect directly to moxi, but be aware that if you do this you are really just creating more work for yourself. Spymemcached already has all of the moxi capabilities built into it and we highly recommend using the constructor that takes a list of URI's.
Thanks Mike, make sense.
One another question related to this.
What is the benefit of creating multiple "buckets", and associating MemcachedClient's to each "bucket" as opposed to using "default" bucket for all MemcachedClients?
private static MemcachedClient m[] = null; MemcachedClient c0 = new MemcachedClient(baseURIs, "bucket1", ""); MemcachedClient c1 = new MemcachedClient(baseURIs, "bucket2", ""); m[0] = c0; m[1] = c1;
V/s
private static MemcachedClient m[] = null;
for(int i=0;i<2;i++){
MemcachedClient c = new MemcachedClient(baseURIs, "default", "");
m[i] = c;
}Thanks
Abhilash
We added the concept of buckets in Membase so that your system could be multi-tenant. You can think of it as the equivalent of having two databases in one mysql server. I would recommend putting everything into a single bucket unless your specific application would benefit from having multiple buckets.
Hi Abhilash,
Is your local Moxi configured to talk to the cluster?
http://www.couchbase.org/wiki/display/membase/Standalone+Moxi+Component#...
If not, that may be why you're not seeing anything.
Also, the Membase server itself runs a instance of moxi, I would configure your code to point at 2 membase server IP's and you'll get the same functionality along with reduced network hops.
hope this helps
-Alex.