[DOCS] make an explicit warning not to create clients for each request (#324)

Co-authored-by: Steven Silvester <steve.silvester@mongodb.com>
This commit is contained in:
Scott 2025-02-26 17:29:57 -05:00 committed by GitHub
parent e2e967b610
commit e036c6382d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 9 deletions

View File

@ -18,3 +18,4 @@ The following is a list of people who have contributed to
- Steven Silvester
- Julius Park
- Doeke Buursma
- Scott Luu

View File

@ -454,11 +454,10 @@ to an :class:`aiohttp.web.Application`:
:start-after: main-start
:end-before: main-end
Note that it is a common mistake to create a new client object for every
request; this comes at a dire performance cost. Create the client
when your application starts and reuse that one client for the lifetime
of the process. You can maintain the client by storing a database handle
from the client on your application object, as shown in this example.
.. warning::
It is a common mistake to create a new client object for every request; this comes at a dire performance cost.
Create the client when your application starts and reuse that one client for the lifetime of the process.
You can maintain the client by storing a database handle from the client on your application object, as shown in this example.
Visit ``localhost:8080/pages/page-one`` and the server responds "Hello!".
At ``localhost:8080/pages/page-two`` it responds "Goodbye." At other URLs it

View File

@ -152,10 +152,11 @@ makes it available to request handlers::
def get(self):
db = self.settings['db']
It is a common mistake to create a new client object for every
request; **this comes at a dire performance cost**. Create the client
when your application starts and reuse that one client for the lifetime
of the process, as shown in these examples.
.. warning::
It is a common mistake to create a new client object for every
request; **this comes at a dire performance cost**. Create the client
when your application starts and reuse that one client for the lifetime
of the process, as shown in these examples.
The Tornado :class:`~tornado.httpserver.HTTPServer` class's :meth:`start`
method is a simple way to fork multiple web servers and use all of your