Java-client 2.1.4 : to know the quota percent of the memory used by a bucket


#1

Hi,

We are using Couchbase community version 3.0.1 and java client 2.1.4.
We have a Couchbase bucket used for caching the data. The requirement is that if the bucket quota percent used increases beyond 80%, caching (upsert to bucket) should be stopped by the application.

Using the GET API http://localhost:8091/pools/default/buckets/bucketName will give the results it seems. Can we invoke this from our application frequently to see the quota percent used by the bucket?
Could someone suggest the best way for this.


#2

I think this solution is fine, though it depends on what you mean by “frequently” :smiley:

Notice the Java SDK has a BucketManager class that can retrieve a BucketInfo from that API, that you could use:

BucketInfo info = bucket().bucketManager().info();
JsonObject basicStats = info.raw().getObject("basicStats");
Double quotaUsedPercent = basicStats.getDouble("quotaPercentUsed");
System.out.println("Quota used at " + Math.ceil(quotaUsedPercent) + "%");
  • get the manager through the bucket.bucketManager() method
  • get the BucketInfo by calling the info() method
  • access the raw JSON returned by the server as a JsonObject through the bucketInfo.raw() method
  • read the quota or other interesting information: here the basicStats JSON object, and more particularly its quotaPercentUsed Double field
  • here I used Math.ceil to round the quota percentage (eg. 1.8202953 would become 2.0, printing “Quota used at 2.0%”)

#3

@simonbasle,

Thank you for sharing the info. As you suggested, we will use the BucketManager API to get the memory used.

The frequency to check the value of “quotaPercentUsed” is decided as every 5 min.
Will there be any performance issue if the bucketManager is invoked in every 5 min ?


#4

@CouchbaseTrial every 5 minutes should be perfectly fine