关于mysql archive存储引擎-专门存储审计和日志数据
來源:http://60.29.242.49/?p=60
政府還有一個讓數(shù)據(jù)庫專家攤上更多事情的職能,就是安全控制和數(shù)據(jù)審計。 那些管理著海量數(shù)據(jù)倉庫的企業(yè)官員常常得回答諸如“何人何時修改了什么”或者“何人何時查看了什么”這樣的提問。那些擁有數(shù)以千計的員工,開展著不計其數(shù) 的業(yè)務的企業(yè),每天都會產(chǎn)生出大量的日志記錄數(shù)據(jù),而且必須將其好好保存。為了幫助數(shù)據(jù)庫專家應對數(shù)據(jù)爆炸的挑戰(zhàn),MySQL5.0引入了一種新的數(shù)據(jù)存 儲引擎,叫做Archive。這個先進的數(shù)據(jù)管理工具,讓MySQL的專家們擁有了處理和管理海量數(shù)據(jù)的新式武器。
?
?
Archive引擎作用:?為大量很少 引用的歷史、歸檔、或安全審計信息的存儲和檢索提供了完美的解決方案,區(qū)別于InnoDB、MyISAM提供壓縮功能,沒有索引。
?
?
?
?
關(guān)于Archive存儲引擎的介紹和性能測試的文章:http://dev.mysql.com/tech-resources/articles/storage-engine.html
不喜歡英文的童鞋可以看這篇翻譯過來的文章(推薦,翻譯的不錯):http://guangxin.name/2009/04/mysql50-archive-1.html
?
?
根據(jù)英文的測試結(jié)論來看,Archive表比MyISAM表要小 大約75%,比支持事務處理的InnoDB表小大約83%。當數(shù)據(jù)量非常大的時候Archive的插入性能表現(xiàn)會較MyISAM為佳。
?
?
Archive表的性能是否可能超過MyISAM?答案是肯定 的。根據(jù)MySQL工程師的資料,當表內(nèi)的數(shù)據(jù)達到1.5GB這個量級,CPU又比較快的時候,Archive表的執(zhí)行性能就會超越MyISAM表。因為 這個時候,CPU會取代I/O子系統(tǒng)成為性能瓶頸。別忘了Archive表比其他任何類型的表執(zhí)行的物理I/O操作都要少。
?
?
較小的空間占用也能在你移植MySQL數(shù)據(jù)的時候發(fā)揮作用。當你 需要把數(shù)據(jù)從一臺MySQL服務器轉(zhuǎn)移到另一臺的時候,Archive表可以方便地移植到新的MySQL環(huán)境,你只需將保存Archive表的底層文件復 制過去就可以了。
?
?
本著懷疑一切的精神,本人進行了如下的測試:
?
①建立一個iplog的表:
mysql> create table iplog(id int auto_increment not null primary key,userid int,ip char(15),visit_time datetime) engine=innodb;
?
②使用python腳本插入50w數(shù)據(jù):
?
?
#!/usr/bin/mysql
import MySQLdb
?
conn = MySQLdb.connect(host=”localhost”,user=”root”,passwd=”asdf”,db=”test”,unix_socket=”/data/mysql_3306/mysql.sock”)
cursor = conn.cursor()
for i in range(0,500000):
sql = “insert into iplog(userid,ip,visit_time) values(%s,’127.0.0.1′,now())”%i
cursor.execute(sql)
cursor.close()
conn.commit()
conn.close()
?
③分別創(chuàng)建iplog對應的archive、 InnoDB、MyISAM對應表格并插入數(shù)據(jù)
?
?
mysql> create table iplog_archive engine=archive as select * from iplog;
Query OK, 500000 rows affected (2.73 sec)
Records: 500000 ?Duplicates: 0 ?Warnings: 0
?
mysql> create table iplog_myisam engine=myisam as select * from iplog;
Query OK, 500000 rows affected (1.39 sec)
Records: 500000 ?Duplicates: 0 ?Warnings: 0
?
mysql> create table iplog_innodb engine=innodb as select * from iplog;
Query OK, 500000 rows affected (4.78 sec)
Records: 500000 ?Duplicates: 0 ?Warnings: 0
?
?
④比較它們的大小
?
?
mysql> select table_name,engine,ROUND(data_length/1024/1024,2) total_size_mb,table_rows from information_schema.tables
-> where table_schema = ‘test’ and table_name like ‘iplog_%’;
+—————+———+—————+————+
| table_name ? ?| engine ?| total_size_mb | table_rows |
+—————+———+—————+————+
| iplog_archive | ARCHIVE | ? ? ? ? ?2.10 | ? ? 500000 |
| iplog_innodb ?| InnoDB ?| ? ? ? ? 30.56 | ? ? 500289 |
| iplog_myisam ?| MyISAM ?| ? ? ? ? 29.56 | ? ? 500000 |
+—————+———+—————+————+
3 rows in set (0.01 sec)
?
⑤測試select性能:
?
?
mysql> select * from iplog_archive where userid=250000;
+——–+——–+———–+———————+
| id ? ? | userid | ip ? ? ? ?| visit_time ? ? ? ? ?|
+——–+——–+———–+———————+
| 750001 | 250000 | 127.0.0.1 | 2010-02-01 10:54:20 |
+——–+——–+———–+———————+
1 row in set (0.31 sec)
?
mysql> select * from iplog_innodb where userid=250000;
+——–+——–+———–+———————+
| id ? ? | userid | ip ? ? ? ?| visit_time ? ? ? ? ?|
+——–+——–+———–+———————+
| 750001 | 250000 | 127.0.0.1 | 2010-02-01 10:54:20 |
+——–+——–+———–+———————+
1 row in set (0.48 sec)
?
mysql> select * from iplog_myisam where userid=250000;
+——–+——–+———–+———————+
| id ? ? | userid | ip ? ? ? ?| visit_time ? ? ? ? ?|
+——–+——–+———–+———————+
| 750001 | 250000 | 127.0.0.1 | 2010-02-01 10:54:20 |
+——–+——–+———–+———————+
1 row in set (0.10 sec)
?
⑥測試insert性能():
使用python腳本再插入50w數(shù)據(jù),查看插入性能,腳本如下,沒有寫 的很復雜,測試InnoDB或者MyISAM要修改代碼
?
?
#!/usr/bin/mysql
import MySQLdb
?
conn = MySQLdb.connect(host=”localhost”,user=”root”,passwd=”asdf”,db=”test”,unix_socket=”/data/mysql_3306/mysql.sock”)
cursor = conn.cursor()
for i in range(500001,1000000):
sql = “insert into iplog_archive(userid,ip,visit_time) values(%s,’127.0.0.1′,now())”%i
cursor.execute(sql)
cursor.close()
conn.commit()
conn.close()
?
?
archive
?
real ? ?1m30.467s
user ? ?0m22.270s
sys ? ? 0m12.670s
?
?
InnoDB
?
real ? ?0m48.622s
user ? ?0m18.722s
sys ? ? 0m9.322s
?
?
MyISAM
?
real ? ?1m32.129s
user ? ?0m13.183s
sys ? ? 0m5.624s
?
?
?
?
測試結(jié)果是archive可以大規(guī)模的減少空間減少%93(這個 與表有關(guān)系),select性能介于MyISAM和InnoDB之間,大規(guī)模insert時效率比MyISAM和InnoDB高,至于原因“因為這個時 候,CPU會取代I/O子系統(tǒng)成為性能瓶頸。別忘了Archive表比其他任何類型的表執(zhí)行的物理I/O操作都要少。”
?
歡迎大家共同探討,包括測試用例以及任何想法。
?
關(guān)于time命令的執(zhí)行結(jié)果關(guān)于real、user、sys說明
1)實際時間(real time): 從command命令行開始執(zhí)行到運行終止的消逝時間;
2)用戶CPU時間(user CPU time): 命令執(zhí)行完成花費的用戶CPU時間,即命令在用戶態(tài)中執(zhí)行時間總和;
3)系統(tǒng)CPU時間(system CPU time): 命令執(zhí)行完成花費的系統(tǒng)CPU時間,即命令在核心態(tài)中執(zhí)行時間總和。
轉(zhuǎn)載于:https://www.cnblogs.com/itcomputer/articles/4660780.html
總結(jié)
以上是生活随笔為你收集整理的关于mysql archive存储引擎-专门存储审计和日志数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 烟雨江湖龙隐峡怎么进去?
- 下一篇: 电信一年宽带多少钱啊?