Saturday, August 17, 2013

IO performance improvement by setting up a proper block size

Performance tuning is one of the major activities for a Unix Administrator. Today i will show you a practical scenario where performance can be tunned by setting up

proper block size while creating filesystem. When a file is created, system allocates set of blocks to store the files. Filesystem with larger block size containing

only smaller files, will have lot of space un-utilized.

In database where files are of bigger size, for optimal performance its better to create filesystem of larger block size.

So before creating a filesystem, find out what would be the average size of the files to be stored in the filesystem, based on that decide on that size of filesystem

blocksize

Check the block size of the filesystem

[root@linuxserver ~]# dumpe2fs /dev/sda1 | grep -i "Block size"
dumpe2fs 1.41.12 (17-May-2010)
Block size:               1024
[root@linuxserver ~]# dumpe2fs /dev/sda2 | grep -i "Block size"
dumpe2fs 1.41.12 (17-May-2010)
Block size:               4096


In this demo i am going to create a 2 filesystem with blocksize of 1024 and 4096 and create 20 files of 10MB size

[root@linuxserver /]# mkfs -t ext3 -b 1024 /dev/sdc1 - /app1 - mountpoint


#!/bin/sh
no=0
while [ $no -le 20 ]
do
dd if=/dev/zero of=test$no bs=10M count=1
no=`expr $no + 1`
done

Below is the time required to create 20 files of 10MB size

real    0m8.162s
user    0m0.005s
sys     0m1.881s

[root@linuxserver /]# mkfs -t ext3   /dev/sdb1 - /app - mountpoint

By default it creates filesystem using blocksize of 4096 bytes

#!/bin/sh
no=0
while [ $no -le 20 ]
do
dd if=/dev/zero of=test$no bs=10M count=1
no=`expr $no + 1`
done

real    0m1.268s
user    0m0.014s
sys     0m1.239s





No comments: