在django中放置一个中间件的成本是多少
我为我的一个非常简单的应用程序编写了。
- 要登录 facebook canvas 应用程序的用户
- 进行一些访客跟踪,大部分代码非常简单。
该应用程序可能并没有那么复杂,相当接近博客系统。然而,我想知道我的中间件架构的资源成本是多少。
让我特别担心的一件事是,每次发出唯一请求时都会创建一个新的访问者对象。这是个好主意吗?
因此,虽然中间件是一个令人惊叹的 DRY 和敏捷概念,但它们在性能方面非常出色。
谢谢
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我无法为您提供基准测试,但我的经验是,如果中间件很薄,那么它在性能方面并不重要,至少在您运行的网站流量不是很高的情况下是这样。在我的项目中(其中一些是中等流量的站点),我大量使用了中间件,并且我没有注意到明显的性能缺陷。
关于“访问者对象”:如果您使用会话,Django 会在每个请求上初始化一个用户对象,无论是否使用中间件。即使用户尚未登录,也会创建匿名用户。
因此,保持中间件较小,这样您就不会遇到麻烦。
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.