Changes between Version 1 and Version 7 of Ticket #35672


Ignore:
Timestamp:
Aug 18, 2024, 6:11:35 AM (3 months ago)
Author:
André S. Hansen
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35672

    • Property Cc Florian Apolloner added
    • Property Summary Using database connection pooling raises PoolTimeout after a whileUsing database connection pooling, threads do not return the connection
  • Ticket #35672 – Description

    v1 v7  
    66}}}
    77
    8 It happened after 220 api calls within the span of 7minutes, which probably means x5-10 database calls.
    9 
    10 This forces me to turn of connection pooling.
     8Further investigation shows the reason was a Threaded Middleware orm interaction, like this simplified code.
     9
     10class TimeMonitorMiddleware(object):
     11    batched_logs: List[RequestLog] = []
     12
     13    def __call__(self, request: WSGIRequest) -> HttpResponse:
     14        # ...
     15 
     16        # Save batched logs
     17        if len(self.batched_logs) >= 50:
     18            Thread(target=RequestLog.objects.bulk_create, args=(batched_logs,)).start()
     19
     20        return response
     21
     22
    1123
    1224
Back to Top