Changeset 9223

Show
Ignore:
Timestamp:
03/08/12 16:37:49 (16 months ago)
Author:
denton
Message:

Added a simple example test to ucache documentation. Test times with and without the ucache enabled are provided. The summary statics from the ucache enabled test are also provided.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/client/usrint/README_UCACHE

    r9206 r9223  
    1201204. Examples 
    121121    4.1 Simple Test Program 
     122=============================================================================== 
     123        Compiled with: 
     124gcc -g -Wall -O0 -o 14 14.c \ 
     125-L/usr/local/lib -lofs -lpvfs2 -rdynamic -lssl -lcrypto -lpthread -ldl 
     126=============================================================================== 
     127#include <stdio.h> 
     128#include <stdlib.h> 
     129#include <assert.h> 
     130#include <errno.h> 
     131#include <string.h> 
     132#include <unistd.h> 
     133#include <sys/types.h> 
     134#include <sys/stat.h> 
     135#include <fcntl.h> 
     136 
     137#define B_SIZE (1024 * 256) 
     138#define N_BLKS 679 
     139 
     140int main(int argc, char **argv) 
     141{ 
     142    /* Write buffer */ 
     143    size_t write_buff_size = N_BLKS * B_SIZE; 
     144    char *write_buff = (char *) malloc(write_buff_size); 
     145    assert(write_buff); 
     146    memset(write_buff, '0', write_buff_size); 
     147 
     148    /* Open file */ 
     149    char fullpath[]= "/mnt/pvfs2/myfile"; 
     150    int file = open(fullpath, O_RDWR | O_CREAT, 
     151        S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 
     152    if(file < 0) 
     153    { 
     154        perror("open"); 
     155        return -1; 
     156    } 
     157 
     158    /* Perform the write */ 
     159    int howmany = write(file, write_buff, write_buff_size); 
     160    if(howmany < write_buff_size) 
     161    { 
     162        perror("write"); 
     163        close(file); 
     164        return -1; 
     165    } 
     166 
     167    /* Seek back to beginning of file */ 
     168    off_t lseek_rc = lseek(file, 0, SEEK_SET); 
     169    if(lseek_rc == -1) 
     170    { 
     171        perror("lseek"); 
     172        close(file); 
     173        return -1; 
     174    } 
     175 
     176    /* Read Buffer */ 
     177    int read_count = B_SIZE; 
     178    char read_buff[N_BLKS]; 
     179 
     180    /* Perform many reads on small segments to demonstrate caching benefit */ 
     181    int i; 
     182    for(i = 0; i < read_count; i++) 
     183    { 
     184        howmany = read(file, read_buff, N_BLKS); 
     185        if(howmany != N_BLKS) 
     186        { 
     187            perror("read"); 
     188            close(file); 
     189            return -1; 
     190        } 
     191    } 
     192 
     193    /* Close File */ 
     194    if(close(file) != 0) 
     195    { 
     196        perror("file close"); 
     197        return -1; 
     198    } 
     199    return 1; 
     200} 
     201=============================================================================== 
     202 
     203    4.2 Timed Test w/o Cache 
     204        time sudo ./14 
     205 
     206        real    1m35.229s 
     207        user    0m31.900s 
     208        sys 0m11.110s 
     209 
     210    4.3 Timed Test w/ Cache 
     211        time sudo ./14 
     212 
     213        real    0m2.365s 
     214        user    0m0.860s 
     215        sys 0m0.690s 
     216 
     217    4.4 Test w/ Cache Stats Summary 
     218        SUCCESS 
     219            user cache statistics: 
     220            hits=   262822 
     221            misses= 679 
     222            hit percentage= 99.742317 
     223            pseudo_misses=  0 
     224            block_count=    0 
     225            file_count=     0 
    122226 
    1232275. Limits