Updating a document takes 375x longer after a few updates - App freezes

Android 6
CBL 1.3.0 / 1.3.1

This is the document:

{
"_sync": {
"rev": "14-b9a6b3d8dfc5148ccaca5eaa64a0ceac",
"sequence": 7625486,
"recent_sequences": [
  7625486
],
"history": {
  "revs": [
    "9-ee2c6688c11d563e469916a26d5ef9a0",
    "6-83d7b01e1dbcae71d1cc2dbb12f73e25",
    "8-a680614c6895e72f440c7f3f5e003ebe",
    "1-cea4e6034b5ed6ee1a2c84ee74400ee7",
    "3-82510156f3076b1ec68880635659ff5a",
    "5-23838f8162b9c297b636eb9131c286e9",
    "7-a24bec629fedc635ce65b3823fac4ae0",
    "10-5c44dc47351c801fb2f8e6d77dba6f7b",
    "14-b9a6b3d8dfc5148ccaca5eaa64a0ceac",
    "2-69362e7d918898ee24aaa35cfd5ed94b",
    "4-ce2119576cb4fd50656b20131e7f4580",
    "11-7c8b769fcd93c8a9924e22c4aaecee35",
    "12-009eaf95b3ee41e0f243508660a8b433",
    "13-dce1be2f838821ca998bb8cdde46d77b"
  ],
  "parents": [
    2,
    5,
    6,
    -1,
    9,
   10,
    1,
    0,
    13,
    3,
    4,
    7,
    11,
    12
  ],
  "channels": [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    [
       "b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7"
   ],
    null,
    null,
    null,
    null,
    null
  ]
},
"channels": {
  "b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7": null
},
"time_saved": "2016-09-16T11:29:28.198126541+02:00"
},
"channels": [
"b91a8c08-5e1e-4d1b-a163-9f2b2a7ee0a7"
],
"items": {
"e585b29b-a18c-408b-a7da-8373dea261bd": {
  "bought": 0,
  "couchId": "e585b29b-a18c-408b-a7da-8373dea261bd",
  "deal": 0,
  "name": "Chocolate",
  "note": null,
  "price": "0.00",
  "qty": "0.000",
  "sortOrder": 0,
  "unit": ""
}
}
}

I click on the item “Chocolate” in Android app to mark it as “bought” and click again to change the value “bought” from 1 to 0, and then from 0 to 1, etc. I wait at least two seconds between each click. The CB method update is used:

doc.update(new Document.DocumentUpdater() { @Override public boolean update(UnsavedRevision newRevision) {

Per click on the item “Chocolate” the update method is only run once; there are no conflicts. I only use the app on one device. Here are the times when airplane mode is OFF

09-16 11:35:57.390 7522-7522 D/time-diff: =13  
09-16 11:36:00.010 7522-7522 D/time-diff: =12
09-16 11:36:03.952 7522-7522 D/time-diff: =1030
09-16 11:36:06.755 7522-7522 D/time-diff: =37
09-16 11:36:16.035 7522-7522 D/time-diff: =1105
09-16 11:36:19.660 7522-7522 D/time-diff: =558
09-16 11:36:23.385 7522-7522 D/time-diff: =1028
09-16 11:36:27.001 7522-7522 D/time-diff: =831
09-16 11:36:30.881 7522-7522 D/time-diff: =1081
09-16 11:36:34.715 7522-7522 D/time-diff: =1102
09-16 11:36:38.407 7522-7522 D/time-diff: =980
09-16 11:36:42.336 7522-7522 D/time-diff: =1231
09-16 11:36:46.067 7522-7522 D/time-diff: =1249
09-16 11:36:50.054 7522-7522 D/time-diff: =1272
09-16 11:36:54.467 7522-7522 D/time-diff: =1938
09-16 11:37:00.102 7522-7522 D/time-diff: =2532
09-16 11:37:07.471 7522-7522 D/time-diff: =4493
09-16 11:37:13.146 7522-7522 D/time-diff: =260
09-16 11:37:16.096 7522-7522 D/time-diff: =220
09-16 11:37:20.577 7522-7522 D/time-diff: =1777
09-16 11:37:25.269 7522-7522 D/time-diff: =2152

Same test when airplane mode is ON

09-16 11:40:25.258 7522-7522 D/time-diff: =22
09-16 11:40:28.030 7522-7522 D/time-diff: =20
09-16 11:40:30.771 7522-7522 D/time-diff: =20
09-16 11:40:33.308 7522-7522 D/time-diff: =17
09-16 11:40:36.001 7522-7522 D/time-diff: =20
09-16 11:40:38.862 7522-7522 D/time-diff: =20
09-16 11:40:41.605 7522-7522 D/time-diff: =36
09-16 11:40:44.195 7522-7522 D/time-diff: =19
09-16 11:40:46.883 7522-7522 D/time-diff: =16
09-16 11:40:49.226 7522-7522 D/time-diff: =19
09-16 11:40:51.796 7522-7522 D/time-diff: =15
09-16 11:40:54.204 7522-7522 D/time-diff: =16
09-16 11:40:56.862 7522-7522 D/time-diff: =17
09-16 11:40:59.614 7522-7522 D/time-diff: =26
09-16 11:41:02.226 7522-7522 D/time-diff: =13
09-16 11:41:04.801 7522-7522 D/time-diff: =13
09-16 11:41:07.746 7522-7522 D/time-diff: =14
09-16 11:41:10.355 7522-7522 D/time-diff: =13
09-16 11:41:13.129 7522-7522 D/time-diff: =12
09-16 11:41:15.579 7522-7522 D/time-diff: =21
09-16 11:41:18.327 7522-7522 D/time-diff: =43
09-16 11:41:21.027 7522-7522 D/time-diff: =19

Push and pull replication is set to continuous. Attached are two pictures of Android monitor, once when flight mode is OFF and once when flight mode is ON. When flight mode is OFF there is lots of activity in RAM usage, CPU usage and network. There is hardly any activity in RAM and CPU usage when flight mode is ON and updating the document is quick, there is no lag, app does not freeze!

Please advise!

Hi @benjamin_glatzeder,

Each release we measured performance of CBL with using internal performance test tool. And we did not observe any performance regression between v1.2.1 and v1.3.0, and also between v1.3.0 and v1.3.1.

I assume application slowness could be caused by busy Garbage Collection because of application’s memory usage when you tested (When flight mode is OFF). Could you please share log messages from logcat when flight mode is OFF?

Thanks!

@hideki

Issue found and solved!

Setup:
4x Couchbase Server 4.0 CE
4x SG 1.2

I restarted all nodes one after another and the issue is gone. Looking at the Android monitor now there is way less network activity now, and because of that there is way less CPU and RAM activity, and the lag is gone. The VMs were running for weeks without issues but I strongly believe that restarting solved the issue. That the issue was that CBL and SG or Couchbase server were communicating a lot because of an unknown issue.

Would it be helpful to send any SG logs or Couchbase server logs so that someone can investigate?

Hi @benjamin_glatzeder,

I am glad to hear you could solve the issue. I guess CBL Android was busy to replicate the changes from SG. I can not guess what caused many changes.

I am not expert of SyncGateway and Couchbase Server. I could be better to create new ticket with under Sync Gateway or Couchbase Server.

Issue is fixed by implementing client-side conflict solving and pruning of old revisions via SG

Need to add chars to get this reply accepted

Thanks for the update @benjamin_glatzeder