I have written for a very simple app of mine .
- To login facebook canvas users of the app
- 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 architectu开发者_如何学Cre 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
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.
精彩评论