Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changes
=======

(TBD)
-----

* Connections are no longer reused between requests.
This reduces the amount of ``ServerDisconnectedError`` exceptions.

0.4.2 (2022-10-28)
------------------
* Bump minimum ``aiohttp`` version to 3.8.0, as earlier versions don't support
Expand Down
9 changes: 5 additions & 4 deletions zyte_api/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def create_session(connection_pool_size=100, **kwargs) -> aiohttp.ClientSession:
""" Create a session with parameters suited for Zyte API """
kwargs.setdefault('timeout', AIO_API_TIMEOUT)
if "connector" not in kwargs:
kwargs["connector"] = TCPConnector(limit=connection_pool_size)
kwargs["connector"] = TCPConnector(limit=connection_pool_size,
force_close=True)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the reconnect overhead should not be a problem given the overall response time if the ping is good.
It might probably be in seconds for some percentile since it should (AFAIR) 3xRTT time.

Do we need a follow-up on that to try to optimise in in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it'd be nice to get to the root of it.
Probably it would make sense to focus on http2 support in the client though, not on http 1.1 keep-alive. It would require switching to a different http library.

return aiohttp.ClientSession(**kwargs)


Expand Down Expand Up @@ -132,9 +133,9 @@ def request_parallel_as_completed(self,

``queries`` is a list of requests to process (dicts).

``session`` is an optional aiohttp.ClientSession object;
use it to enable HTTP Keep-Alive. Set the session TCPConnector
limit to a value greater than the number of connections.
``session`` is an optional aiohttp.ClientSession object.
Set the session TCPConnector limit to a value greater than
the number of connections.
"""
sem = asyncio.Semaphore(self.n_conn)

Expand Down