开发者

How costly is it to put a middleware in django

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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜