Django Performance Tuning Tips?

How do you tune Django for better performance? Is there some guide? I have the following questions:

  • Is mod_wsgi the best solution?
  • Is there some opcode cache like in PHP?
  • How should I tune Apache?
  • How can I set up my models, so I have fewer/faster queries?
  • Can I use Memcache?

  • Comments on a few of your questions:

    Is mod_wsgi the best solution?

    Apache/mod_wsgi is adequate for most people because they will never have enough traffic to cause problems even if Apache hasn't been set up properly. The web server is generally never the bottleneck.

    Is there some opcode cache like in PHP?

    Python caches compiled code in memory and the processes persist across requests. You thus don't need a separate opcode caching product like PHP as that is what Python does by default. You just need to ensure you aren't using a hosting mechanism or configuration that would cause the processes to be thrown away on every request or too often. Don't use CGI for example.

    How should I tune Apache?

    Without knowing anything about your application or the system you are hosting it on one can't give easy guidance as how you need to set up Apache. This is because throughput, duration of requests, amount of memory used, amount of memory available, number of processors and much much more come into play. If you haven't even written your application yet then you are simply jumping the gun here because until you know more about your application and production load you can't optimally tune Apache.

    A few simple suggestions though.

  • Don't host PHP in same Apache.
  • Use Apache worker MPM.
  • Use mod_wsgi daemon mode and NOT embedded mode.
  • This alone will save you from causing too much grief for yourself to begin with.

    If you are genuinely needing to better tune your complete stack, ie., application and web server, and not just prematurely optimising because you think you are going to have the next FaceBook even though you haven't really written any code yet, then you need to start looking at performance monitoring tools to work out what your application is doing. Your application and database are going to be the real source of your problems and not the web server.

    The sort of performance monitoring tool I am talking about is something like New Relic. Even then though, if you are very early days and haven't got anything deployed even, then that itself would be a waste of time. In other words, just get your code working first before worrying about how to run it optimally.

    链接地址: http://www.djcxy.com/p/55048.html

    上一篇: 为什么MSDN建议在委托声明中包含对象发件人?

    下一篇: Django性能调优技巧?