-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
smarter termination of background fetches #1461
Conversation
The question was not asked at me, but I was cc'ed, so I'll look at the code and answer anyway :) The things that might take so long:
All of them look like they don't take so long, but seems like one of them does... |
Database access is blocking, so it's possible that Inbox thread is waiting to do some small transaction while Movebox thread is holding the lock, writing hundreds of messages to the database. Mvbox is not aborted until Inbox says it has finished, because Maybe stopping Mvbox thread first or, even better, stopping all of them concurrently (racing |
7802d16
to
7b56b1d
Compare
ad69f9b
to
d0c80f3
Compare
…-point finishing, reimplementation of #1221
d0c80f3
to
79219a7
Compare
while the faster termination is still a thing to do, and the long timings need to be fixed, the approach of doing things synchronous in
therefore, the previous approach, scheduling the work to a background thread is correct in general. |
this pr aims to finish background fetches as soon as possible, so when all fetching is done and all connections are "idle" again.
as a first preparation, i added some tracking for the current duration of background fetches.
currently, we do
start_io()
, wait 10 seconds,stop_io()
, wait another second and finish.i would have expected, that this should always be around 11-12 seconds, which is true in
manysome cases - but there are also durations of 1-10 minutes:EDIT: some more data:
as the app is terminated by apple after 30 seconds, this may means that the app gets "frozen" and woke up after some time, with then either being in foreground or maybe background again, without really using every slot for doing fetches.
this may also explain that we notice wakup coming regulary, but mails not fetched in that time.
so, my suspection is that
stop_io()
may not interrupt fetching but wait until things are done (which would not work then).the log is about today, i can say that no "big" messages were fetched in that time, justifying a long download, only a number of small ones, read receipts, etc, maybe 100 messages.
EDIT:
stop_io()
is surrounded by the log messages "⬅️ finishing fetch" and "⬅️ fetch done". i checked some logs, all of them look okay, there is only a second between these two calls, so that part looks good up to now. but there must be one call lasting some time, hm.@link2xt can you say what
stop_io()
is really doing? does it interrupt ongoing fetches? or at least, finishe only the current one and exists then? or does it wait until the next idle?once this is figured out and we have reliable 11-12 second fetches, we can do the next step and terminate sooner/later by listening to DC_EVENT_CONNECTIVITY_CHANGED somehow as described in #1157
targets #1157 , cc @cyBerta @Hocuri