So I have this process that can be massively parallelized (up to 81x increase) but can't seem to get it to run in parallel with asyncio in a docker container.
The original code
def kernel(xarg):
// this actually calls to another library which launches a subprocess.
// Takes about 16 seconds
return xarg**2
def main():
foo = [i for i in range(81)]
ret_vals = [kernel(i) for i in foo]
As you can imagine this is quite slow. So I decided to speed it up a bit using asyncio
import asyncio
async def kernel(xarg):
return xarg**2
def main():
loop = asyncio.get_event_loop()
foo = [i for i in range(81)]
ret_vals = loop.run_until_complete(asyncio.gather(*[kernel(i) for i in foo]))
However there is absolutely no speedup even when I increase cpu requests for the docker container this runs in.
Please let me know why this isn't working to speed things up. Sorry if it is really basic!