Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

use aiohttp and asyncio #27

Open
skoudoro opened this issue May 26, 2021 · 4 comments
Open

use aiohttp and asyncio #27

skoudoro opened this issue May 26, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@skoudoro
Copy link
Owner

skoudoro commented May 26, 2021

The current performance is ok but Faster is better.

For learning purposes and to improve the performance of huge mailing lists, it would be good to use aiohttp and asyncio.

EDIT:
e.g: https://towardsdatascience.com/fast-and-async-in-python-accelerate-your-requests-using-asyncio-62dafca83c33

@skoudoro skoudoro added the enhancement New feature or request label May 26, 2021
@akblissweb
Copy link

Actually the current performance is pretty bad, for me its coming in about 5 seconds slower than the raw API.

This package does seem useful, it's just right now, I cannot use it at that speed. I'm using Python 3.9.

I've compared it actually in Jupyter and on a dedicated Docker system and both come back within a second using the native API in the docs.

Are you using V2 of the API ???

@akblissweb
Copy link

I just checked you are indeed using V2.

@akblissweb
Copy link

Its this line that is causing the performance issue...

api = MailerLiteApi('xxxxx')

Because I'm using it in a web page I have to run this for every request.

In Jupyter its not so bad once I've created the api object, the actual API calls come back in a reasonable time.

@skoudoro
Copy link
Owner Author

skoudoro commented Feb 28, 2022

Hi @akblissweb,

Because I'm using it in a web page I have to run this for every request.

Can you provide an example? if you have a server running, I do not understand why you need to call api = MailerLiteApi('xxxxx') every time. I might be missing something. Can you describe more in detail your pipeline?

To be faster:

  • you do not need to instantiate all the objects. This is what api = MailerLiteApi('xxxxx') is doing because it is convenient. You can just pick what you really need. For example, if you need only the campaign on a specific webpage, just do from mailerlite.campaign import Campaigns; c = Campaigns('xxxxx').
  • You can return only the JSON object in each function instead of the convenient custom nametuple/dataclass. When you make a call, add the parameter as_json=True. It should be faster and give you the raw JSON to do whatever you want.

Also, any other suggestions/ideas/contributions are welcomed.

Thank you for the feedback

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants