Repository: python-telegram-bot/python-telegram-bot

Issue:
Adjust defaults for `concurrent_updates` and `conenction_pool_size`
`concurrent_updates` defaults to 4096, while `connection_pool_size` defaults to 128. If there is more than 128 updates being processed in parallel, this will cause pool timeouts rather quickly (unless the pool timeout is set to a very high value).
I suggest to update the default values such that the connection pool size is bigger than the number of updates that are allowed to be processed in parallel. It could actually be bigger (not equal), as there can be even more concurrent requests spawned by e.g. jobs or `asyncio/App.create_task`.
Moreover, the documentation of should be extended a bit more to give hints on this connection between `concurrent_updates`, `connection_pool_size` and `pool_timeout`.


Discussion:

Resolving patch:
diff --git a/telegram/_bot.py b/telegram/_bot.py
--- a/telegram/_bot.py
+++ b/telegram/_bot.py
@@ -172,7 +172,7 @@ class Bot(TelegramObject, AbstractAsyncContextManager):
         private_key (:obj:`bytes`, optional): Private key for decryption of telegram passport data.
         private_key_password (:obj:`bytes`, optional): Password for above private key.
 
-    .. include:: bot_methods.rst
+    .. include:: inclusions/bot_methods.rst
 
     """
 
diff --git a/telegram/ext/_application.py b/telegram/ext/_application.py
--- a/telegram/ext/_application.py
+++ b/telegram/ext/_application.py
@@ -252,7 +252,7 @@ def __init__(
         if isinstance(concurrent_updates, int) and concurrent_updates < 0:
             raise ValueError("`concurrent_updates` must be a non-negative integer!")
         if concurrent_updates is True:
-            concurrent_updates = 4096
+            concurrent_updates = 256
         self._concurrent_updates_sem = asyncio.BoundedSemaphore(concurrent_updates or 1)
         self._concurrent_updates: int = concurrent_updates or 0
 
diff --git a/telegram/ext/_applicationbuilder.py b/telegram/ext/_applicationbuilder.py
--- a/telegram/ext/_applicationbuilder.py
+++ b/telegram/ext/_applicationbuilder.py
@@ -191,7 +191,7 @@ def _build_request(self, get_updates: bool) -> BaseRequest:
             )
         else:
             connection_pool_size = (
-                DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) or 128
+                DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) or 256
             )
 
         timeouts = dict(
@@ -424,7 +424,9 @@ def request(self: BuilderType, request: BaseRequest) -> BuilderType:
     def connection_pool_size(self: BuilderType, connection_pool_size: int) -> BuilderType:
         """Sets the size of the connection pool for the
         :paramref:`~telegram.request.HTTPXRequest.connection_pool_size` parameter of
-        :attr:`telegram.Bot.request`. Defaults to ``128``.
+        :attr:`telegram.Bot.request`. Defaults to ``256``.
+
+        .. include:: inclusions/pool_size_tip.rst
 
         Args:
             connection_pool_size (:obj:`int`): The size of the connection pool.
@@ -504,6 +506,8 @@ def pool_timeout(self: BuilderType, pool_timeout: Optional[float]) -> BuilderTyp
         :paramref:`~telegram.request.HTTPXRequest.pool_timeout` parameter of
         :attr:`telegram.Bot.request`. Defaults to :obj:`None`.
 
+        .. include:: inclusions/pool_size_tip.rst
+
         Args:
             pool_timeout (:obj:`float`): See
                 :paramref:`telegram.request.HTTPXRequest.pool_timeout` for more information.
@@ -770,11 +774,13 @@ def concurrent_updates(self: BuilderType, concurrent_updates: Union[bool, int])
             that your bot does not (explicitly or implicitly) rely on updates being processed
             sequentially.
 
+        .. include:: inclusions/pool_size_tip.rst
+
         .. seealso:: :attr:`telegram.ext.Application.concurrent_updates`
 
         Args:
             concurrent_updates (:obj:`bool` | :obj:`int`): Passing :obj:`True` will allow for
-                ``4096`` updates to be processed concurrently. Pass an integer to specify a
+                ``256`` updates to be processed concurrently. Pass an integer to specify a
                 different number of updates that may be processed concurrently.
 
         Returns:


Test patch:
diff --git a/tests/test_application.py b/tests/test_application.py
--- a/tests/test_application.py
+++ b/tests/test_application.py
@@ -139,7 +139,7 @@ def test_manual_init_warning(self, recwarn, updater):
         assert recwarn[0].filename == __file__, "stacklevel is incorrect!"
 
     @pytest.mark.parametrize(
-        "concurrent_updates, expected", [(0, 0), (4, 4), (False, 0), (True, 4096)]
+        "concurrent_updates, expected", [(0, 0), (4, 4), (False, 0), (True, 256)]
     )
     @pytest.mark.filterwarnings("ignore: `Application` instances should")
     def test_init(self, bot, concurrent_updates, expected):
diff --git a/tests/test_applicationbuilder.py b/tests/test_applicationbuilder.py
--- a/tests/test_applicationbuilder.py
+++ b/tests/test_applicationbuilder.py
@@ -93,7 +93,7 @@ class Client:
         )
 
         client = app.bot.request._client
-        assert client.limits == httpx.Limits(max_connections=128, max_keepalive_connections=128)
+        assert client.limits == httpx.Limits(max_connections=256, max_keepalive_connections=256)
         assert client.proxies is None
         assert client.timeout == httpx.Timeout(connect=5.0, read=5.0, write=5.0, pool=1.0)