what dispatcher are you guys using for IO operations on Android? If someone use a custom one with a pool, how many threads are you using in the pool? Thanks in advance
igorvd
05/28/2018, 7:17 PM
@louiscad Looks good.
But for curiosity, I want a dispatcher for my
useCases
(or interactors), but I'm not sure what to use. I was thinking about using my custom pool, but I'm not sure how many threads it would have.
Maybe I can use yours IO dispatcher, and if my usecases do any cpu bound operations, switch to another context. What do you think about that?
Thanks in advance.
l
louiscad
05/28/2018, 7:25 PM
@igorvd I personally use this already configured
ioDispatcher
, and use
CommonPool
for CPU bound operations, unless it's not worth switching dispatcher for a short operation in a coroutine already running on a background thread.
i
igorvd
05/28/2018, 7:29 PM
>> unless it's not worth switching
igorvd
05/28/2018, 7:29 PM
How do I know that is not worth? Is this approach working fine for you? Are you experiencing any lazyness because of threads waiting the pool become available?
igorvd
05/28/2018, 7:30 PM
Sorry for so many questions! Thank you 😃
l
louiscad
05/29/2018, 12:53 PM
@igorvd Very very lightweight operations can happen on any thread (UI, CommonPool, ioDispatcher...). Examples are a single integer multiplication, a low frequency allocation (in order to not block the UI thread for too long and avoid dropping frames). Short CPU bound operations can happen on both CommonPool and ioDispatcher (anything non UI thread). By short, I mean less than a second, or even less than half a second. Longer CPU bound operations should happen on CommonPool only. Any I/O operations should happen on ioDispatcher or other non UI thread, but not CommonPool so CPU bound operations are never stuck waiting for I/O.
i
igorvd
05/29/2018, 2:23 PM
@louiscad thanks man, I get it and I'll probably follow your approach