• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    MySQL中MyISAM引擎和Heap引擎執行速度性能測試

    發布: 2008-7-08 10:48 | 作者: lizhe1985 | 來源: 本站原創 | 查看: 144次 | 進入軟件測試論壇討論

    領測軟件測試網
    CPU: Intel Pentium4 2.66GHz
    Memory: 1GB
    Disk: 73GB/SCSI

    OS: FreeBSD 4.11
    PHP: PHP 5.2.1
    MySQL: MySQL 4.1.23b

    【 前期工作 】

    [ my.cnf ]

    max_heap_table_size = 128M

    [ 建表 ]

    use test;

    --
    -- Store engine heap
    --
    CREATE TABLE `tbl_heap` (
    `id` int(11) NOT NULL auto_increment,
    `name` varchar(32) NOT NULL default '',
    `email` varchar(32) NOT NULL default '',
    `summary` varchar(255) default '',
    KEY `id` (`id`)
    ) ENGINE=HEAP DEFAULT CHARSET=gbk;

    --
    -- Store engine myisam
    --
    CREATE TABLE `tbl_isam` (
    `id` int(11) NOT NULL auto_increment,
    `name` varchar(32) NOT NULL default '',
    `email` varchar(32) NOT NULL default '',
    `summary` varchar(255) default '',
    KEY `id` (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=gbk;





    【插入數據】

    說明:每次都是空表插入數據

    [插入10000 Record]
    Heap engine insert 10000 record used time: 3.5008587837219
    MyISAM engine insert 10000 record used time: 4.5881390571594

    [50000 Record]
    Heap engine insert 50000 record used time: 19.895354986191
    MyISAM engine insert 50000 record used time: 33.866044998169

    [100000 Record]
    Heap engine insert 100000 record used time: 36.200875997543
    MyISAM engine insert 100000 record used time: 68.34194111824

    [200000 Record]
    Heap engine insert 200000 record used time: 68.00207901001
    MyISAM engine insert 200000 record used time: 125.26263713837


    【查詢數據】

    表里分表有:200000條記錄,兩個表數據一致

    [直接select,10000次,每次取100條記錄]
    Heap engine select 10000 times, 100 record used time: 12.122506141663
    MyISAM engine select 10000 times, 100 record used time: 19.512896060944

    [直接select,1000次,每次取10000條記錄]
    Heap engine select 1000 times, 10000 record used time: 111.54126811028
    MyISAM engine select 1000 record used time: 116.79438710213

    [增加where條件,1000次,每次取10000條記錄]
    Heap engine select 1000 times, 10000 record used time: 111.52102303505
    MyISAM engine select 1000 times, 10000 record used time: 117.68481087685

    [where條件,10000次,每次從1000條起,取1000條記錄]
    Heap engine select 10000 times, 1000 record used time: 124.28988695145
    MyISAM engine select 10000 times, 1000 record used time: 139.82107305527

    [where條件增加like,10000次,每次從1000條起,取1000條記錄]
    Heap engine select 10000 times, 1000 record used time: 145.43780493736
    MyISAM engine select 10000 times, 1000 record used time: 163.56296992302

    [where條件增加索引,10000次,每次從1000條起,取1000條記錄]

    -- 建立索引 (在SQLyob下執行)
    ALTER TABLE tbl_heap ADD INDEX idx_name (name);
    ALTER TABLE tbl_isam ADD INDEX idx_name (name);

    Heap engine alter table add index used time: 2.078
    MyISAM engine alter table add index used time: 13.516

    Heap engine select 10000 times, 1000 record used time: 153.48922395706
    MyISAM engine select 10000 times, 1000 record used time: 239.86818814278

    PS: 不合適的索引還不如不要。。。-_-#

    [SQLyog下進行count操作]
    Heap engine select count used time: 4.53
    MyISAM engine select count used time: 3.28

    [SQLyob下進行select操作]
    速度都很快,都在1秒一下,不論是1000條記錄,還是200000條記錄,個人猜測可能不準確




    【更新操作】

    [更新所有name=heiyeluren的記錄為heiyeluren2,在SQLyog下執行]
    Heap engine update used time: 2.500
    MyISAM engine update used time: 16.000


    【刪除操作】

    [刪除所有name=heiyeluren2的記錄,在SQLyog下執行]
    Heap engine delete used time: 51.172
    MyISAM engine delte used time: 5.578

    【總結】

    Heap在插入、查詢、更新操作上明顯要比MyISAM快,但是刪除操作稍微比較慢,可能跟它在內存中的存儲結構有關系,所以我們完全可以把Heap作為我們一個MyISAM表的一個備份,比如可以保存一些實時性要求比較高的數據,比如點擊量、評論量、固定的用戶信息等等,因為這些信息普遍就是插入和查詢操作。

    當然了,Heap也沒有比MyISAM快太多,這樣說明我的MyISAM速度還是非?斓,所以一般情況下,MyISAM能夠滿足大部分的應用了,如果數據太多的情況,可以考慮把部分常用的數據保存到Heap表中,同時也可以結合Memcache等緩存工具來幫助緩存數據。

    另外,關于InnoDB和MyISAM的性能測試,可以參考我之前的測試數據:
    http://blog.csdn.net/heiyeshuwu/archive/2007/04/10/1559640.aspx

    【測試代碼】

    <?php
    /**
    * function lib
    */
    function conn(){
    $host = "localhost";
    $user = "root";
    $pass = "";
    $db = "test";

    $conn = mysql_connect($host, $user, $pass);
    if (!$conn || !is_resource($conn)){
    die("Connect to mysql failed: ". mysql_error());
    }
    mysql_select_db($db);
    return $conn;
    }

    function query($conn, $sql){
    $res = mysql_query($sql, $conn);
    if (!$res){
    echo mysql_error()." ";
    return false;
    }
    return true;
    }

    function get_data($conn, $sql){
    $res = mysql_query($sql, $conn);
    if (!$res){
    echo mysql_error()." ";
    return false;
    }
    $result = array();
    while($row = mysql_fetch_array($res)){
    $result[] = $row;
    }
    return $result;
    }

    function get_time()
    {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
    }

    /**
    * Insert test
    */
    $conn = conn();
    $count = 200000;

    //Heap engine
    $s1 = get_time();
    for($i=0; $i<$count; $i++){
    query($conn, "insert into tbl_heap set name = 'heiyeluren', email='heiyeluren@abc.com', summary='This message is summary'");
    }
    $e1 = get_time();
    echo "Heap engine insert $count record used time: ". ($e1-$s1) ." ";


    //MyISAM engine
    $s2 = get_time();
    for($i=0; $i<$count; $i++){
    query($conn, "insert into tbl_isam set name = 'heiyeluren', email='heiyeluren@abc.com', summary='This message is summary'");
    }
    $e2 = get_time();
    echo "MyISAM engine insert $count record used time: ". ($e2-$s2) ." ";


    /**
    * Select test
    */

    $count = 1000;
    $records = 10000;

    $s1 = get_time();
    for($i=0; $i<$count; $i++){
    $res = get_data($conn, "select * from tbl_heap limit $records");
    unset($res);
    }

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    TAG: Heap MyISAM Mysql MySQL mysql mySQL 性能測試 引擎

    21/212>

    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>