天天看點

Benchmarking and Profiling

Benchmark:系統的瓶頸

    測量應用現有的性能

    校驗系統可擴充性:通過增加壓力測試

    估算業務增長後,對硬體 資源 網絡的需求

    測試系統對環境變化的容忍度:短暫的并行峰值、伺服器的配置改變

    不同硬體 軟體 作業系統 raid的影響:硬碟ata/san

Benchmark政策:

    fullstack:整個應用作為一個整體

    single-component:隔離的mysql

    Goal:TPS(transaction per second), 反應時間,壓力,并發

Benchmark方法:

    錯誤方法:資料量不夠、單使用者、

    正确方法:

Benchmark tool:

    full-stack(ab http_load jMeter)

    single-component(mysqlslap sysbench mysql-bachmark-suite super-smack)

profiling: 應用程式消耗最多時間和資源的地方

1. 應用profile:開發過程記錄,頁面的時間,io時間等等

2. mysql profile:

    哪些資料通路最多

    哪些sql執行最多

    那種state mysql thread執行時間最長

    那種subsystem mysql執行query時間最長

    mysql在query期間都通路了哪些資料

    在query期間都做了哪些活動,比如index scan

3. logging:兩種 一種general log,一種slow log(記錄查詢時間大于2s的query,可配置)

    mysql從5.0開始,long_query_time=10000,隻有大于此數量的query才會記錄,其實變相禁用slow query

    general log沒有query用時資訊

    5.0的slowlog 隻能以秒為機關,但對于高性能應用這個粒度不夠

    slow log分析工具:mysql_slow_log_filter mysql_slow_log_parser mysqlsla

mysql server profile: show session status:

        Bytes_received and Bytes_sent

            The traffic to and from the server

        Com_*

            The commands the server is executing

        Created_*

            Temporary tables and files created during query execution

        Handler_*

            Storage engine operations

        Select_*

            Various types of join execution plans

        Sort_*

            Several types of sort information

Profling Queries with SHOW STATUS

1. 使用flush status和show session status分析query

2. flush status; select sql_no_cache id from table;

    show session status like 'Select*':全表掃描 全表join 子表rangeScan

    show session status like 'Handler*':存儲引擎的操作,讀寫次數,寫可能是由于有Group/OrderBy操作導緻的臨時表

    show session status like 'Sort*':Group/OrderBy操作導緻的排序

    show session status like 'Create*':

       上面導緻的建立臨時表的個數,不同的版本是不一樣的,

       mysql4是共享參數,可能會被其他session修改

Profling Queries with SHOW PROFILE

1. set profiling=1;

2. show profile;

   show profile cpu for query 1;

轉載于:https://blog.51cto.com/yingtju/718217