I’ve built a trading platform using Ktor and corou...
# coroutines
l
I’ve built a trading platform using Ktor and coroutines. This is my first experience with coroutines, and I’m pretty sure I’ve made some naive mistakes. This is what my logging activity looks like, and I have no idea why. I’ve obviously baked in these pauses, but I don’t know how. If you’re experienced with coroutines, what would you look for to get to the bottom of this behavior? What would you have to do to make this happen? Should I be looking for async/await or something else? It almost seems like thread starvation. or some other kind of deadlock, but I don’t understand how it is so regular or such large blocks of time. I am continuously consuming market data, 23 hours per day. As far as scheduled events, I send a status email at the top of every hour, and every 12 minutes I refresh access tokens. The obvious culprit seems like the 12-minute cycle, but it’s far from obvious in the logs that they are related. I can’t find any clear association between the beginning or end of the token refresh with the idle period or the busy period. I’m going to change the refresh token period to see if the nature of the cycles changes, but, while I’m gathering that data, what should I be looking for that could cause this?
According to Grok, replacing
client.newCall(request).execute().use {...}
with Ktor’s suspending calls to
client.get(url) {…}
will solve this. Does that sound reasonable?
c
You're not getting answers because there's nothing to say on this thread. You haven't given any code, so it's not possible to know what could be wrong. And yeah,
client.get(url)
is good, and it's the documented way to make requests. No idea where you even found that other code.
l
Thanks for pointing that out. I was looking for qualitative answers or debugging advice, because I have too much code to post a meaningful sample which reproduces the problem (since I don’t really know what the problem is). Fortunately, over the weekend, I was able to get things flowing as expected. I think the switch from execute() (which came from ChatGPT 😞) to Ktor’s suspending functions was part of it, but I also broke up the token refresh process, optimized the use of OkHttpClient, and other tweaks. I still can’t explain why the activity dropped to nothing for regular internals, but I was able to fix it.