Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Mobile

Replicated data size is much larger on the device compared to what is on the server

10 replies [Last post]
  • Login or register to post comments
Wed, 05/30/2012 - 08:46
thmr
Offline
Joined: 03/13/2012
Groups: None

I am working on a mobile game that uses Couchbase Mobile (iOS) on the client and Iris Couch to store data on the cloud. In order for the app to work off line each user has a database on the server which is replicated on the device. Everything looks very promising except for one detail: when the data is replicated on the deice it takes too much disk space. For example, a remote database contains 400 documents and it is approximately 100 MB, the replicated database on the device is approximately 390 MB for the same number of documents. Has anyone experienced such issues? The app also becomes very slow during the initial replication. Any help would be appreciated.

Top
  • Login or register to post comments
Wed, 05/30/2012 - 10:39
jens
Offline
Joined: 10/04/2011
Groups: None

Have you compacted the local database?

CouchDB is an append-only file format, so updating a document makes the tree grow as much as inserting a new one. Even inserting a new node adds more space than strictly necessary because the updated intermediate b-tree nodes get appended instead of overwritten. The space is reclaimed when the database is compacted.

So if you've been incrementally replicating from the upstream database, the local db will be larger. Compacting should take care of that.

--Jens

Top
  • Login or register to post comments
Wed, 05/30/2012 - 11:16
thmr
Offline
Joined: 03/13/2012
Groups: None

Thanks for the quick reply, Jens!
Yes - I compact the local database. I am aware that saving a document adds a new version. Compacting the local DB actual increased the size temporary then it went back to where it was but it did not become smaller.I am starting to think that replication alone is not the main cause for the issue. When I create a new user with its own empty database and start creating documents on the device - the local database is still nearly 3 to 4 times larger than what is replicated to the server. I still believe that this is a Couchbase mobile issue. Since my app is a couchapp(I am using Phongeap to make it "native" ) I can test in a browser on a computer running Couchbase Server -- the data size is very close to the remote database size in this case. I also checked the views and didn't find anything alarming (best practices used).

Top
  • Login or register to post comments
Wed, 05/30/2012 - 11:54
jens
Offline
Joined: 10/04/2011
Groups: None

How are you measuring database sizes, locally and remotely?

I'm not sure where a disparity in size would come from, as Couchbase Mobile is, literally, CouchDB. It's a little bit forked from 1.1 but not in any significant way.

Top
  • Login or register to post comments
Wed, 05/30/2012 - 12:08
thmr
Offline
Joined: 03/13/2012
Groups: None

On the iOS device I am looking at the usage under Settings> General > Usage - before and after the replication takes place and / or before and after I create a new empty database and add documents to it.
On the remote database I am looking at Futon's overview page (each user has separate database on the server).

Top
  • Login or register to post comments
Wed, 05/30/2012 - 12:18
jens
Offline
Joined: 10/04/2011
Groups: None

You can't really compare your app's total disk usage against just the size of the remote databases; it ignore anything else your app is storing locally, like caches.

Take a look at the .couch files in Library/Application Support/CouchbaseMobile/ and see if they correspond to the sizes you expect. If they do, look around the rest of the app data files to see what's using up space. (On the simulator you can look at the app's files directly since they're just in a directory buried in your OS X home directory; on a device you'll need an app like iExplorer.)

Top
  • Login or register to post comments
Wed, 05/30/2012 - 13:28
thmr
Offline
Joined: 03/13/2012
Groups: None

Thanks for the tip! Looking at the simulator files the file sizes actually do match - this is a great news. I don't see what else is contributing to the disk space usage reported by iOS. I will try this on an actual device - clearly not a Couch DB issue.

Top
  • Login or register to post comments
Wed, 05/30/2012 - 13:34
jens
Offline
Joined: 10/04/2011
Groups: None

Whew! My first guess would be caching by PhoneGap; those files are likely in Library/Caches. Or just run 'du' on the whole directory tree, or use a tool like OmniDiskSweeper that shows you what files are taking up the most disk space.

Top
  • Login or register to post comments
Wed, 05/30/2012 - 15:03
thmr
Offline
Joined: 03/13/2012
Groups: None

Thanks! I see the large files. Looks like the views are too large after all. It would probably make sense to clear those views when the user logs out.

Top
  • Login or register to post comments
Wed, 05/30/2012 - 15:10
jens
Offline
Joined: 10/04/2011
Groups: None

Yeah, I don't think Futon includes view sizes when reporting the size of a database.

If the views are larger than you'd like, make sure you're not putting too much in them. I've found that often people emit the entire document as the value; this isn't necessary because you can get basically the same effect by querying with the include_docs flag. (It's slightly faster if the document is embedded in the view, though; this is one of those time-space tradeoffs.)

Top
  • Login or register to post comments
Wed, 05/30/2012 - 19:37
thmr
Offline
Joined: 03/13/2012
Groups: None

Thanks for the advice! While the views in my app are not emitting documents some of them of them emit large number of fields. I will try to optimize that.

Top
  • Login or register to post comments
  • 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