mirror of https://github.com/M66B/FairEmail.git
Added operation yield
This commit is contained in:
parent
e86436898b
commit
12be9e6596
|
@ -137,6 +137,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
private static final int FAST_FAIL_COUNT = 3;
|
private static final int FAST_FAIL_COUNT = 3;
|
||||||
private static final int FETCH_YIELD_DURATION = 50; // milliseconds
|
private static final int FETCH_YIELD_DURATION = 50; // milliseconds
|
||||||
private static final long WATCHDOG_INTERVAL = 60 * 60 * 1000L; // milliseconds
|
private static final long WATCHDOG_INTERVAL = 60 * 60 * 1000L; // milliseconds
|
||||||
|
private static final long OPS_YIELD_INTERVAL = 15 * 1000L; // milliseconds
|
||||||
|
private static final long OPS_YIELD_DURATION = 1000L; // milliseconds
|
||||||
|
|
||||||
private static final String ACTION_NEW_MESSAGE_COUNT = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE_COUNT";
|
private static final String ACTION_NEW_MESSAGE_COUNT = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE_COUNT";
|
||||||
|
|
||||||
|
@ -1817,6 +1819,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
cowner.value.start();
|
cowner.value.start();
|
||||||
|
|
||||||
db.operation().liveOperations(account.id).observe(cowner.value, new Observer<List<TupleOperationEx>>() {
|
db.operation().liveOperations(account.id).observe(cowner.value, new Observer<List<TupleOperationEx>>() {
|
||||||
|
private Long last = null;
|
||||||
|
private long idle = 0, busy = 0;
|
||||||
private List<Long> handling = new ArrayList<>();
|
private List<Long> handling = new ArrayList<>();
|
||||||
private final Map<TupleOperationEx.PartitionKey, List<TupleOperationEx>> partitions = new HashMap<>();
|
private final Map<TupleOperationEx.PartitionKey, List<TupleOperationEx>> partitions = new HashMap<>();
|
||||||
|
|
||||||
|
@ -1983,11 +1987,32 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
Log.i(account.name + " folder " + folder.name + " flags=" + ifolder.getPermanentFlags());
|
Log.i(account.name + " folder " + folder.name + " flags=" + ifolder.getPermanentFlags());
|
||||||
}
|
}
|
||||||
|
|
||||||
Core.processOperations(ServiceSynchronize.this,
|
long start = new Date().getTime();
|
||||||
account, folder,
|
try {
|
||||||
partition,
|
Core.processOperations(ServiceSynchronize.this,
|
||||||
iservice, ifolder,
|
account, folder,
|
||||||
state, serial);
|
partition,
|
||||||
|
iservice, ifolder,
|
||||||
|
state, serial);
|
||||||
|
} finally {
|
||||||
|
long end = new Date().getTime();
|
||||||
|
if (last != null)
|
||||||
|
idle += (start - last);
|
||||||
|
last = end;
|
||||||
|
busy += (end - start);
|
||||||
|
if (busy + idle > OPS_YIELD_INTERVAL) {
|
||||||
|
long wait = (OPS_YIELD_DURATION - idle);
|
||||||
|
Log.i(account.name + " ops idle wait=" + wait);
|
||||||
|
if (wait > 0)
|
||||||
|
try {
|
||||||
|
Thread.sleep(wait);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
idle = 0;
|
||||||
|
busy = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.e(folder.name, ex);
|
Log.e(folder.name, ex);
|
||||||
|
|
Loading…
Reference in New Issue