django - 减少 django 上的用户 CPU 时间

标签 django performance nginx django-debug-toolbar

我实际上正在一个 Django 网站上工作,使用 django 调试工具栏,在一个 digital ocean 小水滴上。这一切都适用于 Postgresql、Django、gunicorn 和 Nginx。

困扰我的是渲染时间大约是 2.5 秒,其中大部分是关于 用户CPU时间 .

Resource         Value
User CPU time    2271.395 msec
System CPU time  86.142 msec
Total CPU time   2357.537 msec
Elapsed time     2483.655 msec
Context switches 8 voluntary, 469 involuntary

Browser Chronology
domainLookup 0 (+0)
connect 0 (+0)
request 3 (+-1419272753107)
response 5653 (+-1419272758757)
domLoading 5669 (+-1419272758773)
domInteractive -1419272753104
domContentLoadedEvent -1419272753104 (+0)
loadEvent -1419272753104 (+0)

所以,我想提高速度,我设置了一个快速的 Digital Ocean 水滴(最大的一个),时间看起来是一样的。我知道最大的水滴通常意味着更多的 CPU 核心,因此,更多的同时请求。

但问题是这两个问题:
  • 与系统 CPU 时间相对的用户 CPU 时间是多少?
  • 如何减少用户 CPU 时间?
  • 最佳答案

    我有几乎相同的场景(Digital Ocean、Postgres、uWSGI 上的小水滴……),我想知道为什么 CPU 时间在简单页面上约为 700 毫秒,而在更复杂的页面上约为 3 秒,如 Django 调试所示工具栏。但是后来我发现调试工具栏本身使用了大部分时间。当我关闭它并放置另一个分析器(中间件在 http://djangosnippets.org/snippets/727/ 上)时,我看到这些时间下降到 ~ 200 毫秒和 ~800 毫秒。

    所以回答你的问题:

  • 检查克里斯普拉特的回答 Django Debug Toolbar: understanding the time panel
  • 没有减少 CPU 时间的独特方法。您必须分析您的配置文件输出以发现 CPU 的使用位置。

  • 我从 Yugal Jindle 的回答中得到了配置文件中间件:
    How to profile django application with respect to execution time? .使用 HotShot 检查其他分析器选项。

    关于django - 减少 django 上的用户 CPU 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27607412/

    相关文章:

    php - 性能与模块化 : Integrate JS into PHP or separate custom. js

    performance - 部分评估右手操作符部分

    redirect - 重定向到 https 时 Nginx 不从 root 服务

    node.js - nginx 临时文件夹的权限设置问题

    docker - keycloak 动态客户端注册registration_client_uri docker主机名覆盖

    python - 关于Django RadioSelect初始值

    Django:在通用 View 中处理空查询集

    python - 从 Django 模型返回 JSON 格式的子属性

    python - 如何在 django 模板中循环遍历日期时间范围

    mysql - MySQL中的快速页面检索,索引使用?