常听人说,fseek很快!到底多快?如果不知道多快,就一个劲的争论很快!好像不必担心的快一样。这种常识性的东西不知道,妄谈系统设计,就会出笑话的。下面做个实验,测测fseek的量级。
测试的方法:
1. 一个文件512M
2. 一个线程对应一个文件,然后在这个文件里边进行rand fseek,然后读1K字节
1. 机器配置
硬盘:
类型:希捷 酷鱼7200.9/ST3160812AS
容量:160G
转速:7200rpm
缓存容量:8M
20080201104250 NT 5171.3075500976 thread:1,time:33211
20080201104250 NT 5171.3085990832 thread:0,time:33480
20080201104250 NT 5171.3085993664 complete to seek!
20080201105502 NT 5312.3076189104 thread:1,seeknum:1000,time:27757
20080201105517 NT 5312.3086678960 thread:0,seeknum:1000,time:42990
20080201105518 NT 5312.3065699248 thread:2,seeknum:1000,time:43848
20080201105518 NT 5312.3044719536 thread:4,seeknum:1000,time:43936
20080201105518 NT 5312.3055209392 thread:3,seeknum:1000,time:43956
20080201105518 NT 5312.3086681792 complete to seek!
20080201105557 NT 5320.2991479728 thread:9,seeknum:1000,time:6
20080201105632 NT 5320.3075398576 thread:1,seeknum:1000,time:34968
20080201105632 NT 5320.3085888432 thread:0,seeknum:1000,time:35699
20080201105648 NT 5320.3064908720 thread:2,seeknum:1000,time:51508
20080201105649 NT 5320.3033439152 thread:5,seeknum:1000,time:52242
20080201105650 NT 5320.3054418864 thread:3,seeknum:1000,time:52789
20080201105654 NT 5320.3001969584 thread:8,seeknum:1000,time:57389
20080201105657 NT 5320.3043929008 thread:4,seeknum:1000,time:60030
20080201105659 NT 5320.3022949296 thread:6,seeknum:1000,time:61854
20080201105659 NT 5320.3012459440 thread:7,seeknum:1000,time:61960
20080201105659 NT 5320.3085891264 complete to seek!
20080201105902 NT 5363.3076279216 thread:1,seeknum:100,time:1736
20080201105902 NT 5363.3086769072 thread:0,seeknum:100,time:1749
20080201105902 NT 5363.3086771904 complete to seek!
结论:每秒100多次的频率
2. 希捷 ST3146845LC(SCSI/15000转/3.5) 硬盘容量 146GB
20080201111345 NT 11512.3086085040 thread:0,seeknum:1000,time:6322
20080201111345 NT 11512.3075595184 thread:1,seeknum:1000,time:6592
20080201111345 NT 11512.3086087872 complete to seek!
20080201111436 NT 11516.3065846704 thread:2,seeknum:1000,time:1516
20080201111439 NT 11516.3086826416 thread:0,seeknum:1000,time:4843
20080201111440 NT 11516.3076336560 thread:1,seeknum:1000,time:4984
20080201111440 NT 11516.3086829248 complete to seek!
20080201111014 NT 11394.2991508400 thread:9,seeknum:1000,time:7
20080201111019 NT 11394.3001998256 thread:8,seeknum:1000,time:5910
20080201111021 NT 11394.3064961968 thread:2,seeknum:1000,time:7713
20080201111023 NT 11394.3054472112 thread:3,seeknum:1000,time:9722
20080201111024 NT 11394.3012488112 thread:7,seeknum:1000,time:10040
20080201111025 NT 11394.3033492400 thread:5,seeknum:1000,time:11918
20080201111025 NT 11394.3023002544 thread:6,seeknum:1000,time:11929
20080201111026 NT 11394.3043982256 thread:4,seeknum:1000,time:12528
20080201111027 NT 11394.3075455920 thread:1,seeknum:1000,time:13119
20080201111027 NT 11394.3085945776 thread:0,seeknum:1000,time:13574
20080201111027 NT 11394.3085948608 complete to seek!
20080201113340 NT 11671.2956921776 thread:12,seeknum:1000,time:11054
20080201113340 NT 11671.2967411632 thread:11,seeknum:1000,time:11718
20080201113341 NT 11671.2977901488 thread:10,seeknum:1000,time:12378
20080201113341 NT 11671.2946431920 thread:13,seeknum:1000,time:12555
20080201113343 NT 11671.2935942064 thread:14,seeknum:1000,time:14755
20080201113345 NT 11671.3065510832 thread:2,seeknum:1000,time:16908
20080201113346 NT 11671.3053452208 thread:3,seeknum:1000,time:17139
20080201113346 NT 11671.2988391344 thread:9,seeknum:1000,time:17249
20080201113346 NT 11671.3042962352 thread:4,seeknum:1000,time:17454
20080201113346 NT 11671.3076000688 thread:1,seeknum:1000,time:17648
20080201113347 NT 11671.3086490544 thread:0,seeknum:1000,time:18470
20080201113347 NT 11671.2998885296 thread:8,seeknum:1000,time:18917
20080201113348 NT 11671.3021982640 thread:6,seeknum:1000,time:19228
20080201113348 NT 11671.3009379248 thread:7,seeknum:1000,time:19555
20080201113348 NT 11671.3032472496 thread:5,seeknum:1000,time:19576
20080201113348 NT 11671.3086493376 complete to seek!
每秒不到1000次。
也就是说:如果要是seek读,每次读1K,只有1M/秒。
(这个结论只供参考)
也可以把这个实验扩展,
比如:如果必须seek,那么读多少数据才是最经济的?
这些经常用到的性能参数是非常有用的。那往往都是一个系统的瓶颈所在。