有什么聪明的方法可以在业务逻辑中找到瓶颈吗?例如,我们有一个在大项目中执行HttpResponse('1')的应用程序。我们确信,中间件中不存在SQL查询。但是HttpResponse的工作非常慢(在clear项目上,50个rps对200个rps )。
发布于 2011-11-30 15:40:57
调试工具栏运行良好,但我也喜欢运行django-devserver。它可以给你更多的信息,有时你可以处理。
DEVSERVER_MODULES = (
'devserver.modules.sql.SQLRealTimeModule',
'devserver.modules.sql.SQLSummaryModule',
'devserver.modules.profile.ProfileSummaryModule',
# Modules not enabled by default
'devserver.modules.ajax.AjaxDumpModule',
#'devserver.modules.profile.MemoryUseModule',
'devserver.modules.cache.CacheSummaryModule',
#'devserver.modules.profile.LineProfilerModule',
)这是我打开的模块,启动后一次点击管理页面:
Django version 1.3.1, using settings 'myproject.settings' Running django-devserver 0.3.1 Threaded django server is running at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
[sql] SELECT ...
FROM "auth_message"
WHERE "auth_message"."user_id" = 1
[sql] SELECT ...
FROM "django_admin_log"
INNER JOIN "auth_user" ON ("django_admin_log"."user_id" = "auth_user"."id")
LEFT OUTER JOIN "django_content_type" ON ("django_admin_log"."content_typ_id" = "django_content_type"."id")
WHERE "django_admin_log"."user_id" = 1
ORDER BY "django_admin_log"."action_time" DESC LIMIT 10
[sql] 4 queries with 0 duplicates
[profile] Total time to render was 0.54s
[cache] 0 calls made with a 100% hit percentage (0 misses) [30/Nov/2011 08:36:34] "GET /admin/ HTTP/1.1" 200 21667 (time: 0.69s; sql: 0ms (4q))
[sql] SELECT ...
FROM "django_flatpage"
INNER JOIN "django_flatpage_sites" ON ("django_flatpage"."id" = "django_fatpage_sites"."flatpage_id")
WHERE ("django_flatpage"."url" = /favicon.ico/
AND "django_flatpage_sites"."site_id" = 1)
[sql] 1 queries with 0 duplicates
[profile] Total time to render was 0.02s
[cache] 0 calls made with a 100% hit percentage (0 misses) [30/Nov/2011 08:36:34] "GET /favicon.ico/ HTTP/1.1" 404 2587 (time:
0.89s; sql: 0ms (1q))发布于 2011-11-30 15:23:50
使用django调试工具栏吗?您可以找到使用它运行的查询,中间件或非中间件。如何监视视图的性能?大项目中的用户比新项目的用户多吗?
发布于 2011-11-30 15:50:16
我猜你的瓶颈不在你的或者django代码里。您使用什么the服务器,以及由工作进程处理多少请求?
如果您使用mod_wsgi,请确保有足够的辅助进程,并且最大请求是高的。
当然,要确保没有设置settings.DEBUG。
Apache日志可以以微秒为单位包括请求处理时间:http://httpd.apache.org/docs/current/mod/mod_log_config.html检查%D
检查您的中间件解释器在your+django代码中的时间。
# Middleware to check how long the request was in the wsgi queue:
class FooMiddleware:
def process_request(self, request):
...
queue_start=request.META.get('HTTP_X_QUEUE_START', None)
if queue_start is not None:
# How long was the request waiting in the wsgi queue?
# In Apache Config:
# RequestHeader add X-Queue-Start "%t" (in <VirtualHost>)
queue_start = int(queue_start[2:])/1000000.0
wait_in_queue=time.time()-queue_start
if wait_in_queue>1:
logging.error('Request was too long (%.3fs) in wsgi-queue: %s' % (
wait_in_queue, request.build_absolute_uri()))https://stackoverflow.com/questions/8327300
复制相似问题