[cachebox] - Setting up couchbase server for caching

Running into a bit of an issue setting up our caches on couchbase and wondering how other people have done it. We have about 7 cache areas set up for the different types of things we are caching on the site, which allows us to more easily configure the times and max items, etc. for the different items. Also to more easily view each of these in the cachebox report module and see how they are performing, hits vs. misses, evictions, etc.

But in configuring them for couchbase buckets, we ran into a problem which is that if you use the same bucket for different caches, the cachebox report tool does not seem to be able to separate them and you get all cache items on each cache report.

So we set up buckets for each cache area, but then we run into problems with couchbase limits when we tried to add a second set for our staging server. There is a max of 10 buckets, with 5 or less recommended. They recommend using a bucket similar to a database, which should mean using the same bucket for all our items. But you’re supposed to set a “type” and index on that to improve performance and doesn’t look like cachebox does that? And I know our client is not going to be happy with all the cache items showing up in one big giant report in the admin tool.

So I either have to combine a few caches to get it down to 5 per server setup, or consider installing couchbase on the staging server directly.

Thoughts?

Mary Jo

For now, I’ve dropped 2 of the smaller caches and moved them into another one so we only have 5 total and can set up two sets of caches on our couchbase server to cover staging and production. Still would like to know if that sounds like a reasonable approach.

One thing that was also driving me nuts was a couple of our caches simply would NOT save items. No errors, you just never got data back and they did not show up in either the couchbase or cachebox admin panels as saved documents/keys. It seems that the cache config had an objectDefaultTimeout value that was really high (looks like it was calculated to seconds, not minutes). Didn’t seem to cause issues on the cachebox provider, but couchbase seems to have an issue with it and just doesn’t set the key at all. Something to note in case anyone else runs into the same problem! Not sure what the max value it allows is, but I have other caches with a value of 7200 (120 hours) and those seem to be fine.

Mary Jo

Hi MaryJo, sorry for the delay in responding. It’s been busy around here :slight_smile:

> We have about 7 cache areas set up for the different types of things we are caching on the site, which allows us to more easily configure the times and max items, etc.

Note, that there are a number of cache configurations that ONLY apply to the “cachebox” cache providers because it has its own stores that implement those settings (concurrent, JDBC, disk, etc) The Couchbase provider, for instance doesn’t have a max items configuration. You can set it, but it will be ignored. That’s because Couchbase server has no concept of max items.

All the possible config values that the Couchbase provider can use are here in the docs:
http://wiki.coldbox.org/wiki/CacheBox-Couchbase.cfm#Properties

> see how they are performing, hits vs. misses, evictions, etc.

Along the same lines, the Couchbase provider does not report misses or evictions because the underlying Couchbase server has no concept of them. Just something to keep in mind.

> when we tried to add a second set for our staging server.

I would set up a Couchbase cluster for each environment.

There is a max of 10 buckets, with 5 or less recommended

Yeah, there’s a lot of async processes that run for each bucket. Note, if you’re not using any views or XDCR that is reduced so you can probably get away with more. I don’t think the 10 is a hard limit (unless they changed that), if your buckets see very little use on your dev server you can try it and watch the CPU usage.

> They recommend using a bucket similar to a database, which should mean using the same bucket for all our items.

Well, maybe not an entire database, but one bucket for each functional area of related data. Here’s the thing though-- that advice applies to using Couchbase as a NoSQL document store and doesn’t really apply to caching. You’ll find that Couchbase courts the NoSQL crowd a lot more than the caching crowd so much of their advice is tailored to that usage scenario. If you’re not querying against a bucket, but just getting individual keys by ID, there’s not much reason not to just use one giant bucket with a key naming strategy to create “regions”. That’s how Memcahed works.

> But you’re supposed to set a “type” and index on that to improve performance and doesn’t look like cachebox does that?

Again, that’s talking about using Couchbase as NoSQL document store. Look at their beer sample bucket to see what they mean. They store beers and breweries in the same bucket and use a “type” property to tell them apart. That only matters because they are running queries against their views to select stuff out. None of that really applies to a cache.

Now I’ll note, CacheBox does wrap your data in a small JSON document just so we can store some extra meta data related to your payload, but it’s a transparent thing.

> And I know our client is not going to be happy with all the cache items showing up in one big giant report in the admin tool.

Well, I’ll be honest with you-- most caches don’t have an admin tool that shows you everything for one basic reason-- no one cares. I mean, people stick millions of items in caches and there’s just no value in bothering to look at them individually. In fact, if you get past several thousand items I wouldn’t recommend looking at the CacheBox monitor :slight_smile: It will work, but there’s no pagination so it will be slow as crap. In fact, other mega-popular caching engines like Memcached have no way to even get a list of items! Generally, enterprise cache reporting is done at a macro level, not a per-item level. So basically, I wouldn’t get too married to a fun little report screen that shows the items even though it is cool.

So, that being said-- if your client feels they get good business value out of manually perusing large numbers of cached items, I would recommend building a custom paginated interface that just uses the underlying services. Though honestly, at that point, you really might as well just give them read-only access to the Couchbase admin where that work is already done for you.
http://docs.couchbase.com/admin/admin/UI/ui-settings-account-mgmt.html

> So I either have to combine a few caches to get it down to 5 per server setup, or consider installing couchbase on the staging server directly.

So, like I said before, I would totally have a separate stage server-- and Couchbase recommends being on dedicated hardware too-- sticking on your ColdFusion server could make it really fight for RAM and CPUs-- especially if you have a DB on that server too. And I would also recommend just one bucket if you can. There’s really no functional difference between 1 bucket for 7-- the main difference is reporting.

So, while I’ve been typing this E-mail I’ve formulated an idea-- it would be possible to have the Couchbase CacheBox provider FAKE cache regions to allow you to have a bunch of caches that pretend their separate but they really all just dump in one bucket. We would basically add a config for ‘cacheRegion’ and add that to the small JSON wrapper around each piece of data and prepend the item keys with the region name. The bucket-level reporting of hits, etc might still be global, but it would let you do some reporting on just the subset of keys that are in that “region”.

So, if that sounds useful-- here’s the skinny. We put out the Couchbase provider as our first Couchbase project-- before we even wrote the official SDK. Now even our SDK is going out of date because Couchbase rewrote their entire Java SDK from scratch :confused: So that said, Luis is unlikely to spend too much time enhancing the CacheBox provider right now just since it generates zero revenue for us. The two options that come to mind would be for you to give it a try and submit a pull request. The other would be if your company wanted to sponsor a project to update the Couchbase CacheBox provider.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

NP - thanks for the reply Brad. Figured this all might be useful if anyone else decides to look into using couchbase as well!

  • Thanks for the notes on the things couchbase doesn’t support. Yeah, the max items probably won’t be too much of a concern anyway since the server will have tons of room for as much as we want to put into it. So timeouts will be far more critical.

  • I don’t see us setting up a separate server for our staging environment, cost of the server even being Linux for our enterprise-level hosting is a bit too much to justify it right now. Just to be clear though, we do the vast majority of dev and testing on a local cfwebtools server, so what we call “staging” is much closer to production than what most people would consider it to be. If need be we could always run couchbase for staging directly on that server itself since it needs so little memory and space.

  • The 10 buckets does seem to be an absolute limit, we weren’t able to add any more than that.

  • The cachebox admin tool definitely was a big reason why we moved over to using it versus just making use of default CF cache. Particularly being able to see the result of adding items to cache from our searches and seeing how much data ended up cached as a result. Our client as well LOVES reports and data and being able to see what is going on so much that he actually wasn’t happy with only seeing the admin report for one server in our cluster, I had to come up with a way to let him see both of the server results. Right now as well they often change data in their PowerBuilder desktop tool and need to be able to go in and clear items from cache manually from time to time. This is a big reason why we have been using separate cache areas, at least until such time as I can build them a better way to do this. I guess we can switch to having them do this in couchbase but you have to know the exact key to find things in the couchbase admin, I believe. Basically we just find the cachebox report tool really excellent and particularly easy to use for what we are looking for in terms of data as well as locating and clearing keys. And yeah I know there’s no pagination in there. So far that has been more a blessing than a curse for us. :wink: That might change when we have this couchbase server up and can safely cache a lot more but we’ll see!

What you describe with the “cacheRegion” is more what I was looking for. Not sure when I would have time to do it so I will have a chat with the client and see if that might be something they would want to contract with you on.

Thanks!

Regarding clearing keys, you could write a service to clear individual items and even write in an API if you wanted so a button in the PowerBuilder app could clear stuff. Just a thought since the entire API is there for you to automate as much as you want.

Just let us know if your client wants to sponsor any changes :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Well it’s a bit more complicated than that since some changes can mean many keys that need to be cleared. But the real issue is their PB guy quit so there’s no one right now to even make such an addition! :wink: It’s not a huge problem since only one person has access to the kind of changes that can be a problem (mainly renaming high-level items like the categories on the site) but I do need to make sure when needed we can get in there and clear stuff.

Mary Jo

PowerBuilder is a blast from the past. The first place I worked used PB and CF together. When their PB guy quit, they paid MUCHO dinero for some contractor to come make changes.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com