Fatal1ty / aioapns

An efficient APNs Client Library for Python/asyncio
Apache License 2.0
122 stars 52 forks source link

One connection per request? #25

Closed ganesh93 closed 3 years ago

ganesh93 commented 3 years ago

Hi, I had a quick question for you. You have put together a useful library. Is there one connection being made per request? And also can send_notification take a list of device tokens? I am trying to minimize opening and closing connections with APNS2. Thanks, Ganesh

Fatal1ty commented 3 years ago

Hi,

This library is designed to maximize the efficient use of network resources, so it has a connection pool with a maximum number of max_connections connections, which by default is ten. Each connection has a channel pool that allows up to 1000 notification requests to be processed in a single connection in parallel. All this works in a single thread asynchronously. Therefore, even if you set a large number to "max_connections" parameter and at the same time send a few notifications per second, one connection will be reused in the pool and no other connections will be created. Also, each connection has an inactivity timer that allows you to keep as many active connections in the pool as needed and adapt to the increasing number of notification requests.

As for the list of tokens, as far as I know, APNs doesn't provide such functionality and neither does this library. But thanks to all of the above, you can simply send notification requests in bulk using asyncio.wait for example.