#9878: Database backend leaves idling connections when used in multiple threads
------------------------------------------+---------------------------------
 Reporter:  Fredde                        |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.0       
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 When creating and saving model instances in multiple threads, the database
 backend leaves idling connections. This will finally cause a "Too many
 connections"-exception.

 I'm using Django 1.0 with a MySQL database

 This script will leave ~10-20 open connections
 {{{
 def createArticle():
     a = Article(title = '...', text = '...')
     a.save()

 threads = []
 for i in xrange(200):
     t = threading.Thread(target = createArticle)
     t.start()
     threads.append(t)

 for t in threads:
     t.join()
 }}}

 To see the active connections in the mysql client
 {{{
 mysql> show full processlist;
 
+--------+------+-----------+------+---------+------+-------+-----------------------+
 | Id     | User | Host      | db   | Command | Time | State | Info
 |
 
+--------+------+-----------+------+---------+------+-------+-----------------------+
 | 463987 | ---- | localhost | NULL | Query   |    0 | NULL  | show full
 processlist |
 | 463994 | ---- | localhost | ---- | Sleep   |   44 |       | NULL
 |
 | 464020 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464042 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464045 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464048 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464067 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464093 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464105 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464136 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464139 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464165 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464166 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 | 464183 | ---- | localhost | ---- | Sleep   |   85 |       | NULL
 |
 
+--------+------+-----------+------+---------+------+-------+-----------------------+
 14 rows in set (0.00 sec)
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9878>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to