Slow Queries in CouchBase Lite - Android

556 views
Skip to first unread message

Chris M

unread,
Jul 17, 2013, 3:40:36 PM7/17/13
to mobile-c...@googlegroups.com
Hi All,
CBL-Android.
We're finding our queries are running pretty slow (4-5 seconds) with  50 records/doc

Speed does not improve on 2nd/3rd/4th runs...always the same.

I think the view is never indexing - so its running full search every run.

I'm guessing there is some setting/config that i'm missing. (index=auto?)

Anyone have a solution?

Thanks CM

Jens Alfke

unread,
Jul 17, 2013, 5:08:32 PM7/17/13
to mobile-c...@googlegroups.com

On Jul 17, 2013, at 12:40 PM, Chris M <appbr...@gmail.com> wrote:

I think the view is never indexing - so its running full search every run.
I'm guessing there is some setting/config that i'm missing. (index=auto?)

No, indexing should be automatic.

Do you have a complex reduce function? CBL doesn’t precompute reduced values the way CouchDB does, so it has to run the reduce function over all the rows on every query. But this should only get slow if you have large amounts of data.

I’m not familiar with Android dev tools, but if you could profile the app while querying to see where the time is being spent, that would help narrow it down.

—Jens

Олег Рак

unread,
Jul 18, 2013, 7:43:31 AM7/18/13
to mobile-c...@googlegroups.com
Hi Jens, i'm working with Chris M.

First of all we are not using any reduce functions.

Here is a piece of app code.

        CBLView getGadgetsByParentIdView = db.getViewNamed(gadgetsByParentIdViewName);

        if (getGadgetsByParentIdView.getMapBlock() == null) {
            getGadgetsByParentIdView.setMapReduceBlocks(
                new CBLViewMapBlock() {
                    @Override
                    public void map(Map<String, Object> stringObjectMap, CBLViewMapEmitBlock cblViewMapEmitBlock) {
                        if (Gadget.class.getSimpleName().equals(stringObjectMap.get(META_BASE_TYPE_PROP))) {
                            cblViewMapEmitBlock.emit(stringObjectMap.get(PARENT_GADGET_ID_PROP), stringObjectMap.get(ID_PROP));
                        }
                    }
                },
                null,
                VIEWS_VERSION
            );
        }


The problem is next:
Each time after app is started, first view-function call is slow(looks like db is updating index), next calls are fast.
It's strange because there are no changes in db between two app starts, so there is no reason to update index

CBLView getGadgetsByParentIdView = db.getViewNamed(gadgetsByParentIdViewName);
is returning CBLView with empty MapBlock when i'm getting it rigth after app start, so MapReduceBlock must be setted again.

I'm not sure what is the reason, but it looks like DB isn't storing MapBlock with view-function and when i'm seting it to CBLView again then indexing occurs.

Thanks in advance.

Jens Alfke

unread,
Jul 18, 2013, 12:07:43 PM7/18/13
to mobile-c...@googlegroups.com

On Jul 18, 2013, at 4:43 AM, Олег Рак <use...@gmail.com> wrote:

I'm not sure what is the reason, but it looks like DB isn't storing MapBlock with view-function and when i'm seting it to CBLView again then indexing occurs.

The MapBlock itself can’t be stored (it’s live code, not a string), so that’s what the version parameter is for — it gets stored instead. If you register the view with a different version string than the one stored in the db, the index is cleared. But you should be OK as long as “VIEWS_VERSION” is a constant that you’re not changing.

—Jens

Traun Leyden

unread,
Jul 18, 2013, 12:57:36 PM7/18/13
to mobile-c...@googlegroups.com
If VIEWS_VERSION is indeed a constant, go ahead and file an issue with instructions how to reproduce including code snippets which show how you are initializing CBLite.

Олег Рак

unread,
Jul 20, 2013, 8:03:55 AM7/20/13
to mobile-c...@googlegroups.com

If VIEWS_VERSION is indeed a constant, go ahead and file an issue with instructions how to reproduce including code snippets which show how you are initializing CBLite.

VIEWS_VERSION is a constant value. Ok guys, i'll open issue on github. Thanks!

Олег Рак

unread,
Jul 20, 2013, 9:01:39 AM7/20/13
to mobile-c...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages