Desinerd : Dipankar's Blog

Nginx + django fcgi lessons

Published: in Technical, , , , , , , , , , , , by .

Today was a good day as i learned some valuable lessons about django and nginx.

  1. ALWAYS close the database cursor in django, it can lead to some pretty wierd memory issues going forward.
  2. FIND the most optimal number of database connections you initialize for you connection pooling. This will let you optimize on memory going forward.
  3. ENSURE that you do not set a very high client_timeout, this means that if connections are not explicitly not closed by the client then the web server will not timeout. This results in bad memory behavior for the fcgi threads.

Well, this has solved my major issues with respect to kwippy. Also learned that GIFs are very fundamentally different than JPEGs which results in a lot of problem when used in the python imaging library. All in all a good day :D.

Comments

  • Interesting point. I am using fcgi with flup. I kept getting the ‘Unhandled Exception’ error. There were lot of import statements which were pointing to nothing so once they were cleaned up the problem seemed to be solved. But we received the same error very occasionaly.
    We discovered that some of the cursors were not being closed. This might be a solution to that also.
    My question is were you also facing the same error before arriving at ‘axiom’ no 1 😉

  • Hey thanks for the response. It completely depends on how u write your application, my one has a bit more custom queries than i would like it to have honestly :). You have any more axioms to add from your experiences feel free to add.

Leave a Reply

Your email address will not be published. Required fields are marked *