4

I have written for a very simple app of mine .

  1. To login facebook canvas users of the app
  2. To do some visitor tracking , most of the code is very simple.

The app probably is not that complicated , fairly close to a blogging system . However I wish to know how costly in terms of resources my architecture of middleware going to be.

One of things that is specifically worrying me is the fact that a new visitor object is created every time a unique request is made . Is that a good idea ?

So while middleware are an amazing DRY and agile concept how well do they standout in terms of performance.

Thanks

dusual
  • 2,097
  • 3
  • 19
  • 26
  • 4
    Try it! If there are performance issues then think about how to fix them. You can spend a lot of time figuring out the what-if's but it's easier to do it, see if it's a problem and then address it. – Timmy O'Mahony Oct 07 '11 at 11:25

1 Answers1

6

While I can't serve you with benchmarks, my experience is that, if a middleware is thin, it does not really matter in terms of performance, at least if you're not running a really high-traffic site. In my projects (some of them middle-traffic sites), I make heavy use of middleware, and I did not notice a remarkable performance drawbacks.

About the "visitor object": If you are using sessions, Django initializes a user object on every request, independently of using a middleware or not. Even if the user has not been logged in, an anonymous user will be created.

So keep your middleware small and you might not get into trouble.

schneck
  • 10,556
  • 11
  • 49
  • 74