https://kotlinlang.org logo
#android
Title
# android
s

Sergio C.

08/19/2019, 10:17 PM
Hello people. Is there any performance advantage about using retrofit with the suspend modifier to use them in coroutines? It's the version starting at 2.6.0. Which thread will retrofit use in this case? How is this working behind the scenes? Using coroutine thread or some other retrofit thread? The coroutine threads are supposed be "cheaper" and I need to make upto some hundred requests simultaneuously.
j

jw

08/19/2019, 10:27 PM
It uses Call.enqueue which uses OkHttp's thread pool. OkHttp will restrict you to a max of 5 calls in-flight and 60 total at any one time. You can adjust this by creating your own Dispatcher.
👍 1
s

Sergio C.

08/19/2019, 10:36 PM
Ok, so it's just a regular thread pool? Yes indeed I'm using a Dispatcher limiting to 25 requests in flight because I'm afraid to unleash all the threads simultaneously. 🙂 Anyway It'll hit the top 60 max right? Have you thought about changing the OkHttp thread pool to coroutines threads? Or is it not possible?..
using suspend modifier in the calls is just a matter of convenience?
so many questions
j

jw

08/19/2019, 11:36 PM
Yes it's convenience. Doing asynchronous I/O all the way through the stack provides few benefits for clients who make so few requests given the complexity it introduces. Maybe someday though.
👍 1
s

Sergio C.

08/20/2019, 8:36 AM
Cool. Hope you can do it someday!
Thanks for the help.