V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
longmeier90
V2EX  ›  Python

有没有什么方法能够查看 djangoORM 的 SQL 语句消耗时间

  •  
  •   longmeier90 · 2021-07-06 15:46:43 +08:00 · 1803 次点击
    这是一个创建于 1018 天前的主题,其中的信息可能已经有所发展或是发生改变。

    俺们公司的主项目用 django 开发的。其中 SQL 有用自带的 ORM,还有原生的 SQL 语句混合使用,最近 mysql 服务器老是提示 cpu%占用过高。数据库服务器只部署了一个 mysql 。

    11 条回复    2021-07-06 23:37:40 +08:00
    David1119
        1
    David1119  
       2021-07-06 16:00:18 +08:00
    debug_toolbar
    4771314
        2
    4771314  
       2021-07-06 16:32:52 +08:00
    mysql 有监控的,配置一下就好了(没有的话,建议开启,裸奔还是太危险了)
    如果使用的云服务就更简单了,云服务有配套的服务,直接在控制台就能看到
    est
        3
    est  
       2021-07-06 16:43:52 +08:00   ❤️ 1
    'loggers': {
    'django.db': {
    'level': 'DEBUG',
    'handlers': ['console'],
    }
    }
    someios
        4
    someios  
       2021-07-06 17:30:54 +08:00
    profiling ?
    Vegetable
        5
    Vegetable  
       2021-07-06 17:35:59 +08:00
    orm 排查属于侵入式操作了,还是从数据库侧操作吧,如果是云服务的话排查这个应该挺方便的啊
    chenqh
        6
    chenqh  
       2021-07-06 18:22:49 +08:00
    cpu100%应该有会有 slow query 的吧
    falcon05
        7
    falcon05  
       2021-07-06 18:28:22 +08:00 via iPhone
    可以看看 mysql 的 slow log
    phithon
        8
    phithon  
       2021-07-06 21:22:35 +08:00
    ericls
        9
    ericls  
       2021-07-06 22:14:20 +08:00
    @est 3 楼才是最好用的方法
    akira
        10
    akira  
       2021-07-06 22:22:06 +08:00
    正常应该是开 mysql 的慢日志入手吧
    ysw
        11
    ysw  
       2021-07-06 23:37:40 +08:00
    可以考虑 apm 插件,elastic apm 或者其他的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2805 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:51 · PVG 13:51 · LAX 22:51 · JFK 01:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.