blockdev --setra read ahead performance

简介:
以下CentOS 6.4 x64上的测试结果,
硬盘OCZ RevoDrive3 X2 240G
读取94393左右个数据块, 
在read ahead=256(默认)情况下的时间为2376毫秒左右. (当然还有除掉cpu tuples operator的时间, 这里不额外叙述, 只是表面read ahead的影响.)
read ahead=0时, 时间为18773毫秒左右.
read ahead=512时,  时间为2115 毫秒左右.
read ahead=1024时,  时间为 2082 毫秒左右.
一般情况下, 默认的设置256就差不多了, 无需多调.
每次查询前清理OS CACHE.
[root@db-172-16-3-150 ~]# sync
[root@db-172-16-3-150 ~]#  echo 3 > /proc/sys/vm/drop_caches

设置块设备read ahead
[root@db-172-16-3-150 ~]# blockdev --setra 512 /dev/sdb
[root@db-172-16-3-150 ~]# blockdev --setra 1024 /dev/sdb
...

digoal=# explain (analyze,verbose,costs,buffers,timing) select * from tbl_cost_align;
                                                               QUERY PLAN                                                           
    
------------------------------------------------------------------------------------------------------------------------------------
----
 Seq Scan on postgres.tbl_cost_align  (cost=0.00..195393.00 rows=10100000 width=45) (actual time=2.742..2115.588 rows=10100000 loops
=1)
   Output: id, info, crt_time
   Buffers: shared hit=256 read=94137
 Total runtime: 3148.863 ms
(4 rows)

-- 清理OS CACHE
digoal=# explain (analyze,verbose,costs,buffers,timing) select * from tbl_cost_align;
                                                               QUERY PLAN                                                           
    
------------------------------------------------------------------------------------------------------------------------------------
----
 Seq Scan on postgres.tbl_cost_align  (cost=0.00..195393.00 rows=10100000 width=45) (actual time=2.502..2082.989 rows=10100000 loops
=1)
   Output: id, info, crt_time
   Buffers: shared hit=288 read=94105
 Total runtime: 3103.415 ms
(4 rows)

-- 清理OS CACHE
digoal=# explain (analyze,verbose,costs,buffers,timing) select * from tbl_cost_align;
                                                               QUERY PLAN                                                           
     
------------------------------------------------------------------------------------------------------------------------------------
-----
 Seq Scan on postgres.tbl_cost_align  (cost=0.00..195393.00 rows=10100000 width=45) (actual time=0.652..18773.211 rows=10100000 loop
s=1)
   Output: id, info, crt_time
   Buffers: shared read=94393
 Total runtime: 19824.287 ms
(4 rows)
...



[参考]
2. man blockdev
BLOCKDEV(8)                                                        BLOCKDEV(8)

NAME
       blockdev - call block device ioctls from the command line

SYNOPSIS
       blockdev [options] commands devices
       blockdev --report [devices]

DESCRIPTION
       The utility blockdev allows one to call block device ioctls from the command line.

OPTIONS
       -V     Print version and exit.

       -q     Be quiet.

       -v     Be verbose.

       --report
              Print a report for devices.  Note that the partition StartSec is in 512-byte sectors.

COMMANDS
       --setro
              Set read-only.

       --setrw
              Set read-write.

       --getro
              Get read-only. Print 1 if the device is read-only, 0 otherwise.

       --getss
              Print sectorsize in bytes - usually 512.

       --getbsz
              Print blocksize in bytes.
       --setbsz N
              Set blocksize to N bytes.

       --getsize
              Print device size in sectors (BLKGETSIZE). Deprecated in favor of the --getsz option.

       --getsize64
              Print device size in bytes (BLKGETSIZE64)

       --getsz
              Get size in 512-byte sectors (BLKGETSIZE64 / 512).

       --setra N
              Set readahead to N 512-byte sectors.

       --getra
              Print readahead (in 512-byte sectors).

       --setfra N
              Set filesystem readahead (same like --setra on 2.6 kernels).

       --getfra
              Get filesystem readahead.

       --flushbufs
              Flush buffers.

       --rereadpt
              Reread partition table.

AUTHOR
       blockdev was written by Andries E. Brouwer.

AVAILABILITY
       The   blockdev   command   is   part  of  the  util-linux-ng  package  and  is  available  from  ftp://ftp.ker-
       nel.org/pub/linux/utils/util-linux-ng/.

                                   Jun 2007                        BLOCKDEV(8)

相关文章
|
SQL 算法 Java
《Speedy Transactions in Multicore In-Memory Databases》
Speedy Transactions in Multicore In-Memory Databases
《Speedy Transactions in Multicore In-Memory Databases》
|
关系型数据库 MySQL
Consistent Nonlocking Reads,Locking Reads 和Phantom Rows
以Consistent Nonlocking Reads,Locking Reads为突破点,用简单的例子来说明mysql常用的事务隔离级别(READ COMMITTED, REPEATABLE READ)和lock(record lock,gap lock,next-key lock, Insert Intention Lock)的关系
Consistent Nonlocking Reads,Locking Reads 和Phantom Rows
|
关系型数据库
### avoid read-on-write
### avoid read-on-write 什么是 "read-on-write" problem? 在我们使用最常见的buffer write 中 "read-on-write" 问题指的是当我需要进行小于4k 大小buffer write 的时候, 需要先将数据所在的page 从disk 中读取出放入到page cache, 在page cache 中修改好, 然后再将
1434 0
|
关系型数据库 MySQL Java
Connection is read-only. Queries leading to data modification are not allowed
看了下mysql-connector-5.1.40版本中,如果设置failoverReadOnly=true (即默认值,参考链接),当mysql连接failover时,会根据jdbc连接串将当前连接的readOnly值设置为true (第8行代码) 1 2 3 4 ...
3353 0
|
分布式计算 Hadoop