Concurrent requests on a custom inventory plugin

Hi there!

I’m trying to do an inventory plugin to talk with an API. Everything works great.

Now I’m trying to improve the performance because I need to make a lot (around 60k requests at the moment) to retrieve all the information.

I cannot avoid the huge amount of requests but maybe I can make concurrent requests.

A year ago, I made a concurrent inventory script in Go, but now I’m a little lost trying to do that in Python with the Ansible SDK.

Is there any utility inside the Ansible SDK to achieve this? Any recommendations are welcome :slight_smile:

Thanks!

There is nothing within ansible itself to really help you from a concurrency perspective.

You likely can just spawn multiple threads using the threading library in Python. If it is custom, and you are not contributing it back, there are all sorts of 3rd party concurrency libraries out there (gevent for example), or those that are only included with Python3.5 or newer (asyncio, concurrent futures).

It is for a internal tool at my work so I cannot release it. I'll try to implement it using async :slight_smile:

Thanks a lot!