Tideways & Xhgui 性能监控

本教程基于php7运行环境进行编写

前言

由于版本迭代速度过快导致各种性能问题未能及时解决,遗留下一堆技术债。目前急需解决接口请求超过运行时间0.8s指标的接口,如果人工一句一句代码去排查,不但要耗费大量时间还会增加异常bug的产生可能性。所以Tideways(非侵入式性能分析工具)就从此诞生。

安装教程

1.安装mongodb拓展

pecl install mongodb

2.安装tideways拓展

wget --no-check-certificate https://github.com/tideways/php-xhprof-extension/archive/v4.1.7.tar.gz
tar zxvf v4.1.7.tar.gz
cd php-xhprof-extension-4.1.7
phpize && ./configure && make && make install

3.修改php配置文件,增加拓展配置

#php.ini
# mongodb 拓展加载
extension=mongodb.so
# tideways 拓展加载
extension=tideways.so
# tideways 设置不需要自动加载
tideways.auto_prepend_library=0

4.重启php-fpm

5.下载xhgui可视化工具

git clone https://github.com/yiqiang3344/xhgui-branch.git
cd xhgui-branch && php install

6.配置xhgui配置文件

<?php  //config/config.default.php ?>
<?php
/**
 * Default configuration for Xhgui
 */
return array(
    'debug' => false,
    'mode' => 'development',
    /*
     * support extension: uprofiler, tideways_xhprof, tideways, xhprof
     * default: xhprof
     */
    'extension' => 'tideways',

    // Can be either mongodb or file.
    /*
    'save.handler' => 'file',
    'save.handler.filename' => dirname(__DIR__) . '/cache/' . 'xhgui.data.' . microtime(true) . '_' . substr(md5($url), 0, 6),
    */
    'save.handler' => 'mongodb',

    // Needed for file save handler. Beware of file locking. You can adujst this file path
    // to reduce locking problems (eg uniqid, time ...)
    //'save.handler.filename' => __DIR__.'/../data/xhgui_'.date('Ymd').'.dat',
    //mongodb://root:root@192.168.109.139:27017
    'db.host' => 'mongodb链接uri',
    //db name
    'db.db' => 'xhprof',

    // Allows you to pass additional options like replicaSet to MongoClient.
    // 'username', 'password' and 'db' (where the user is added)
    'db.options' => array(),
    'templates.path' => dirname(__DIR__) . '/src/templates',
    'date.format' => 'Y-m-d H:i:s',
    'detail.count' => 6,
    'page.limit' => 25,

    // Profile 1 in 100 requests.
    // You can return true to profile every request.
    'profiler.enable' => function() {
        return true;//rand(1, 100) === 42;
    },

    'profiler.simple_url' => function($url) {
        return preg_replace('/\=\d+/', '', $url);
    },

    'profiler.filter_path' => array(
      //xhgui运行目录,如不配置则会一起监控性能
      //  '/var/www/xhgui-branch/webroot'
    )

);

7.配置xhgui nginx配置

# php_monitor.conf

server {
    listen 80;
    server_name php_monitor.dev.cn;
    root /var/www/xhgui-branch/webroot;
    index index.php index.html index.htm;


    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

}

8.配置需要监听性能目标网站nginx配置

# 目标nginx配置文件
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/xhgui-branch/external/header.php";

使用教程

查看历史请求接口

查看某个接口请求性能情况

查看某个接口火焰图(可高效分析出运行慢原因)

添加新评论 取消回复

已有 23 条评论

  1. 每一个段落都紧密相连,逻辑清晰,展现了作者高超的写作技巧。

  2. 情感真挚自然,字里行间传递出强烈的感染力。

  3. 作者的观点新颖且实用,让人在阅读中获得了新的思考和灵感。

  4. 案例丰富且贴合主题,论证逻辑环环相扣。

  5. 文化符号解读精准,展现独特审美。

  6. 内容的丰富性和深度让人仿佛置身于知识的海洋,受益匪浅。

  7. 哈哈哈,写的太好了https://www.lawjida.com/

  8. 《苏梅之歌》剧情片高清在线免费观看:https://www.jgz518.com/xingkong/77942.html

  9. 《廓尔喀:勇气之下》战争片高清在线免费观看:https://www.jgz518.com/xingkong/53549.html

  10. 《廓尔喀:勇气之下》战争片高清在线免费观看:https://www.jgz518.com/xingkong/53549.html

  11. 《被歌声迷住》日韩综艺高清在线免费观看:https://www.jgz518.com/xingkong/148862.html

  12. 《我的邻居山田君》动画片高清在线免费观看:https://www.jgz518.com/xingkong/92950.html

  13. 《天才萌宝:这个妈咪我要了!》短片剧高清在线免费观看:https://www.jgz518.com/xingkong/22161.html

  14. 《苏梅之歌》剧情片高清在线免费观看:https://www.jgz518.com/xingkong/77942.html

  15. 《天才萌宝:这个妈咪我要了!》短片剧高清在线免费观看:https://www.jgz518.com/xingkong/22161.html

  16. 《龙虎会风云》动作片高清在线免费观看:https://www.jgz518.com/xingkong/68687.html

  17. 文章的确不错啊https://www.cscnn.com/

  18. 想想你的文章写的特别好www.jiwenlaw.com

  19. 不错不错,我喜欢看 www.jiwenlaw.com

  20. 看的我热血沸腾啊https://www.237fa.com/

  21. 叼茂SEO.bfbikes.com

  22. 想想你的文章写的特别好https://www.jiwenlaw.com/

  23. 博主真是太厉害了!!!

文章状态:已收录~