暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Block size

2011-01-01
531

JL Computer Consultancy

Picking an Oracle database block size to suit your hardware

May 1997


There are many arguments about how to choose the best Oracle block size for your application, and whether raw devices are significantly faster than file systems, and whether Fast File Systems (such as JFS a.k.a. VxFS) would be better than simple Unix File System.

The attached pair of simple C programs allows you to get an idea of how well different devices (logical and physical) on your system might work at different sizes of Oracle block. Basically there is a writer program and a reader program. Each takes several parameters to allow you to select a file, write in arbitrary sizes, an arbitrary number of times, choosing to do random or serial access, and setting a meaningful boundary to the start of read/write so that you don't get odd effects from overlapping accesses.

You may want to add some sophistication to the programs, but the key feature is in the writer program, which opens a file with the O_DSYNC call - matching the call made by Oracle for all writes: this is the 'data sync' call which updates the file without updating the file's metadata.

There are some platforms that do not use the standard file handling calls (Pyramid RM1000, for example, seem to use a SYSMIPS() call); so do check that Oracle on your platorm is opening and handling files in the same way as these programs before relying on the results they produce.

To compile the programs, all I have ever needed to do is:

        cc reader.c -o reader
复制
        cc writer.c -o writer
复制

This program is referenced in a Powerpoint presentation comparing raw (logical) devices, Unix file systems, and Fast file systems.

Go to reader program

Go to writer program


reader.c

/*
复制
        program        reader.c
复制
        author         Jonathan Lewis
复制
        date           29-May-1997
复制
        purpose        Exercise file-reading
复制
        This C program will open a file for reading, then read it repeatedly
复制
        either sequentially or randomly.  
复制
        The user specifies 
复制
               The file name
复制
               Whether reads should be sequential or random (R/S)
复制
               The size of each read request (up to 256K)
复制
               A boundary at which each read should start
复制
               The number of reads to make
复制
               A randomising seed for the random number generator
复制
        Compiling:
复制
               cc reader.c -o reader
复制
        Sample of usage:
复制
               reader /tmp/bigfile R 8192 65536 1000 17
复制
                       read /tmp/bigfile randomly, 
复制
                       8K reads on 64K boundary, 
复制
                       1000 reads
复制
               read /tmp/bigfile S 32768 32768 100
复制
                       read /tmp/bigfile 
复制
                       sequentially and contiguously 32K at a time, 
复制
                       100 reads.
复制
        Notes:
复制
               rand() returns a random number between 0 and 32767
复制
               Make sure that rand() * iSkipSize is less than the file size
复制
               You could shift rand() to restrict it further, 
复制
                       e.g. (rand() >> 1) halves the range to 0 .. 16383
复制
                       e.g. (rand() >> 2) halves it twice to 0 .. 8191
复制
               
复制
*/
复制
 
复制
#include <stdlib.h>
复制
#include <stdio.h>
复制
#include <time.h>
复制
#include <fcntl.h>
复制
#include <unistd.h>
复制
main (argc,argv)
复制
        int     argc;
复制
        char    **argv;
复制
{
复制
        char    szFilename[80];
复制
        char    szRandom[20];
复制
        size_t  mybufsize;
复制
        int     iSkipSize;
复制
        int     iReadCt;
复制
        int     iRandSeed;
复制
        int     iRandom;
复制
        int     iFileDes;
复制
        ssize_t nbytes;
复制
        char    mybuf[262144];
复制
        off_t   whereami;
复制
        int     iLoopCt;
复制
        strcpy(szFilename,argv[1]);
复制
        printf("File name:          %s\n",szFilename);
复制
        strcpy(szRandom,argv[2]);
复制
        printf("Random or Serial:   %s\n",szRandom);
复制
        
复制
        mybufsize = (size_t) atoi(argv[3]);
复制
        printf("Read Size:          %8i\n",mybufsize);
复制
        
复制
        iSkipSize = atoi(argv[4]);
复制
        printf("Boundary:           %8i\n",iSkipSize);
复制
        
复制
        iReadCt = atoi(argv[5]);
复制
        printf("Read Count:         %8i\n",iReadCt);
复制
        iRandSeed = atoi(argv[6]);
复制
        printf("Rand Seed:          %8i\n",iRandSeed);
复制
        iFileDes = open(szFilename, O_RDONLY);
复制
        printf("Descriptor:         %8i\n",iFileDes);
复制
        if (szRandom[0] == 'R')
复制
               iRandom = 1;
复制
        else
复制
               iRandom = 0;
复制
        srand(iRandSeed);
复制
        for (iLoopCt = 0 ; iLoopCt < iReadCt ; iLoopCt++ ) {
复制
               if (iRandom)
复制
                   whereami = lseek(iFileDes,(rand()) * iSkipSize, SEEK_SET);
复制
               nbytes = read(iFileDes,mybuf,mybufsize);
复制
        }
复制
        close(iFileDes);
复制
}
复制

 


writer.c

/*
复制
        program        writer.c
复制
        author         Jonathan Lewis
复制
        date           29-May-1997
复制
        purpose        Write blocks to a file using O_DSYNC like Oracle
复制
        This C program will open a file for writing, then write to it 
复制
        repeatedly either sequentially or randomly.  If the file does not
复制
        exist already it will be created (if possible)
复制
        The user specifies 
复制
               The file name
复制
               Whether writes should be sequential or random (R/S)
复制
               The size of each write request (up to 256K)
复制
               A boundary at which each write should start
复制
               The number of writes to make
复制
               A randomising seed for the random number generator
复制
        Compiling:
复制
               cc writer.c -o writer
复制
        Sample of usage:
复制
               writer /tmp/bigfile R 8192 65536 1000 17
复制
                       write /tmp/bigfile randomly, 
复制
                       8K reads on 64K boundary, 
复制
                       1000 writes
复制
               writer /tmp/bigfile S 32768 32768 100
复制
                       write /tmp/bigfile 
复制
                       sequentially and contigiously 32K at a time, 
复制
                       100 writes.
复制
        Notes:
复制
               rand() returns a random number between 0 and 32767
复制
               Make sure that rand() * iSKipSize is less than the file size
复制
               You could shift rand() to restrict it further, 
复制
                       e.g. (rand() >> 1) halves the range to 0 .. 16383
复制
                       e.g. (rand() >> 2) halves it twice to 0 .. 8191
复制
               
复制
               I had some trouble with permissions when creating new files 
复制
               with this program.  I had to create a file, then use the chmod
复制
               Unix command on it.
复制
        Suggested Strategy:
复制
               Wrap the time/timex command around the program
复制
               Use this program in serial mode to create a file.
复制
               Use chmod to make the file readable/writable
复制
               Use reader/writer to test the speed of random access
复制
*/
复制
 
复制
#include <stdlib.h>
复制
#include <stdio.h>
复制
#include <time.h>
复制
#include <fcntl.h>
复制
#include <unistd.h>
复制
#include <stdlib.h>
复制
main (argc,argv)
复制
        int     argc;
复制
        char    **argv;
复制
{
复制
        char    szFilename[80];
复制
        char    szRandom[20];
复制
        size_t  mybufsize;
复制
        int     iSkipSize;
复制
        int     iWriteCt;
复制
        int     iRandSeed;
复制
        int     iRandom;
复制
        int     iLoopCt;
复制
        int     iFileDes;
复制
        int     whereami;
复制
        ssize_t nbytes;
复制
        char mybuf[262144];
复制
        strcpy(szFilename,argv[1]);
复制
        printf("File name:          %s\n",szFilename);
复制
        strcpy(szRandom,argv[2]);
复制
        printf("Random or Serial:   %s\n",szRandom);
复制
        
复制
        mybufsize = (size_t) atoi(argv[3]);
复制
        printf("Write Size:        %8i\n",mybufsize);
复制
        
复制
        iSkipSize = (size_t) atoi(argv[4]);
复制
        printf("Boundary:          %8i\n",iSkipSize);
复制
        
复制
        iWriteCt = atoi(argv[5]);
复制
        printf("Write Count:       %8i\n",iWriteCt);
复制
        
复制
        iRandSeed = atoi(argv[6]);
复制
        printf("Rand Seed:         %8i\n",iRandSeed);
复制
        
复制
        iFileDes = open(szFilename, O_RDWR | O_CREAT | O_DSYNC);
复制
        printf("Descriptor:        %8i\n",iFileDes);
复制
        if (argv[2][0] == 'R')
复制
               iRandom = 1;
复制
        else
复制
               iRandom = 0;
复制
        srand(iRandSeed);
复制
        for (iLoopCt = 0 ; iLoopCt < iWriteCt ; iLoopCt++ ) {
复制
               if (iRandom)
复制
                   whereami = lseek(iFileDes,(rand()) * iSkipSize, SEEK_SET);
复制
               
复制
               nbytes = write (iFileDes, (void *)mybuf, mybufsize);
复制
        }
复制
        close(iFileDes);
复制
}
复制

最后修改时间:2020-04-16 14:52:38
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论