I'm currently using tornado to develop an API that will have multiple users. For performance reasons, it would be beneficial for the entire API to be asynchronous. In the current code, I utilize cursor.fetchmany(# of rows) to fetch many lines from a database and write to a specified file (csv,json). I am attempting to make this process asynchronous but am having trouble doing so. The fetch deals with a large amount of data so if multiple people use the API, it will significantly slow it down as people are "waiting" for the fetch of other users to be completed.
I have tried using IOLoop with little success
Also I tried something like this
async def loop(self):
I = await val.cursor.fetchmany(100)
But there are errors with this because the function fetchmany isn't a native tornado function and isn't structured to support this. Some of my questions are...
1)Has anyone been able to implement a solution to make this async fetching process possible
2) Is this even possible or does the database limit the functionality of tornado asynchronous coding
3) If this is not possible, could I implement something like "ThreadPoolExecutor"to speed up the process by multithreading, or using a substitute for fetchmany? (I don't think this is possible but just trying to outline some of my thought process)
Any help would be greatly appreciated.