{"action":"opened","issue":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/898","repository_url":"https://api.github.com/repos/couchbase/couchbase-lite-android","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/898/labels{/name}","comments_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/898/comments","events_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/898/events","html_url":"https://github.com/couchbase/couchbase-lite-android/issues/898","id":159453785,"number":898,"title":"Push replication failing with large data sets","user":{"login":"swilks","id":5308731,"avatar_url":"https://avatars.githubusercontent.com/u/5308731?v=3","gravatar_id":"","url":"https://api.github.com/users/swilks","html_url":"https://github.com/swilks","followers_url":"https://api.github.com/users/swilks/followers","following_url":"https://api.github.com/users/swilks/following{/other_user}","gists_url":"https://api.github.com/users/swilks/gists{/gist_id}","starred_url":"https://api.github.com/users/swilks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swilks/subscriptions","organizations_url":"https://api.github.com/users/swilks/orgs","repos_url":"https://api.github.com/users/swilks/repos","events_url":"https://api.github.com/users/swilks/events{/privacy}","received_events_url":"https://api.github.com/users/swilks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-09T16:36:11Z","updated_at":"2016-06-09T16:36:11Z","closed_at":null,"body":"Hey,\r\n\r\nI'm developing an Android app in Kenya with a user base is that is often rural and doesn't have consistent access to the internet. We need to back up our users' data, and have just started to use couchbase lite for Android. Because of their poor connectivity they often go long periods of time without uploading any data to the server so push replications are frequently pretty huge. We need push to work with any reasonably large set of documents that take up a reasonably large amount of space. Luckily we don't need to sync any images are large files, just documents that are generally pretty small. \r\n\r\nI haven't plugged in a real dataset to test yet, and am just testing with one type of document with randomly generated data to make sure I can roll out a scalable solution before we drop that app into real-world conditions. I'm currently testing on an Alcatel One Touch (which is a pretty sub-standard tablet, but it's the kind of thing are users are likely to use, so it's a good test device) with ~65MB worth of documents (25,000 docs at ~2.5kb each). I flush the server before running the tests, so it's purely a push replication.\r\n\r\nBy the time the ChangeEvent has registered about 24,000 changes (it hasn't started uploading at this point) it starts generating Out of Memory errors.\r\n\r\nFirst of all, I'm not sure why the upload isn't incremental in this case? When I test with smaller data sets the upload starts before the CBLite has registered all of changed items. For example, when I run the push replication with 750 items, the upload starts after getChangeCount() returns 500 items, and that number is smaller (proportionally) with smaller data sets. \r\n\r\nSecond, is there anything I can do to change this behaviour? I have some hacky solutions in mind to break up the upload, but I don't want to implement them if I don't have to.\r\n\r\nHere are the OOM errors I'm getting: \r\n\r\n`06-09 19:31:20.321 6978-7368/org.mitihealth.mitihealth E/Sync: RemoteRequest.run() exception: %s\r\n                                                               java.lang.OutOfMemoryError\r\n                                                                   at com.fasterxml.jackson.core.util.BufferRecycler.calloc(BufferRecycler.java:156)\r\n                                                                   at com.fasterxml.jackson.core.util.BufferRecycler.allocCharBuffer(BufferRecycler.java:124)\r\n                                                                   at com.fasterxml.jackson.core.util.BufferRecycler.allocCharBuffer(BufferRecycler.java:114)\r\n                                                                   at com.fasterxml.jackson.core.io.IOContext.allocConcatBuffer(IOContext.java:186)\r\n                                                                   at com.fasterxml.jackson.core.json.UTF8JsonGenerator.<init>(UTF8JsonGenerator.java:126)\r\n                                                                   at com.fasterxml.jackson.core.JsonFactory._createUTF8Generator(JsonFactory.java:1284)\r\n                                                                   at com.fasterxml.jackson.core.JsonFactory.createGenerator(JsonFactory.java:1016)\r\n                                                                   at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:2801)\r\n                                                                   at com.couchbase.lite.support.RemoteRequest.setBody(RemoteRequest.java:326)\r\n                                                                   at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:96)\r\n                                                                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)\r\n                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n                                                                   at java.lang.Thread.run(Thread.java:841)\r\n06-09 19:31:23.645 6978-7371/org.mitihealth.mitihealth E/dalvikvm-heap: Out of memory on a 7817-byte allocation.\r\n06-09 19:31:23.652 6978-7371/org.mitihealth.mitihealth E/Sync: RemoteRequest.run() exception: %s\r\n                                                               java.lang.OutOfMemoryError\r\n                                                                   at com.fasterxml.jackson.core.util.ByteArrayBuilder.toByteArray(ByteArrayBuilder.java:118)\r\n                                                                   at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:2807)\r\n                                                                   at com.couchbase.lite.support.RemoteRequest.setBody(RemoteRequest.java:326)\r\n                                                                   at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:96)\r\n                                                                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)\r\n                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n                                                                   at java.lang.Thread.run(Thread.java:841)`\r\n\r\nand here's my sync function:\r\n\r\n`\r\n final Replication pull = database.createPullReplication(createSyncURL(false));\r\n        final Replication push = database.createPushReplication(createSyncURL(false));   \r\npull.setContinuous(false);\r\n        pull.addChangeListener((new Replication.ChangeListener() {\r\n            @Override\r\n            public void changed(Replication.ChangeEvent event) {\r\n                processSyncChangeEvent(event, pull, push, notifyManager, builder, appContext\r\n                        .getString(R.string.downloaded_items), appContext.getString(R.string\r\n                        .prep_downloaded_items), appContext);\r\n            }\r\n        }));\r\n        if (pullListener != null) {\r\n            pull.addChangeListener(pullListener);\r\n        }\r\n\r\n        push.setContinuous(false);\r\n\r\n        push.addChangeListener(new Replication.ChangeListener() {\r\n            @Override\r\n            public void changed(Replication.ChangeEvent event) {\r\n                processSyncChangeEvent(event, push, pull, notifyManager, builder, appContext\r\n                        .getString(R.string.uploaded_items), appContext.getString(R.string\r\n                        .prep_uploaded_items), appContext);\r\n\r\n            }\r\n        });\r\n        if (pushListener != null) {\r\n            push.addChangeListener(pushListener);\r\n        }\r\n        pull.start();\r\n        push.start();`"}}
{"actor":{"display_login":"swilks"}}