nfs-ganesha 1.4
|
00001 #include "config.h" 00002 #include "handle_mapping_db.h" 00003 #include <sys/time.h> 00004 00005 int main(int argc, char **argv) 00006 { 00007 unsigned int i; 00008 struct timeval tv1, tv2, tv3, tvdiff; 00009 int count, rc; 00010 char *dir; 00011 time_t now; 00012 00013 if(argc != 3 || (count = atoi(argv[2])) == 0) 00014 { 00015 LogTest("usage: test_handle_mapping <db_dir> <db_count>"); 00016 exit(1); 00017 } 00018 00019 dir = argv[1]; 00020 00021 /* Init logging */ 00022 SetNamePgm("test_handle_mapping"); 00023 SetNameFileLog("/dev/tty"); 00024 SetNameFunction("main"); 00025 SetNameHost("localhost"); 00026 00027 /* count databases */ 00028 00029 rc = handlemap_db_count(dir); 00030 00031 LogTest("handlemap_db_count(%s)=%d", dir, rc); 00032 00033 if(rc != 0 && count != rc) 00034 { 00035 LogTest("Warning: incompatible thread count %d <> database count %d", count, rc); 00036 } 00037 00038 rc = handlemap_db_init(dir, "/tmp", count, 1024, FALSE); 00039 00040 LogTest("handlemap_db_init() = %d", rc); 00041 if(rc) 00042 exit(rc); 00043 00044 rc = handlemap_db_reaload_all(NULL); 00045 00046 LogTest("handlemap_db_reaload_all() = %d", rc); 00047 if(rc) 00048 exit(rc); 00049 00050 gettimeofday(&tv1, NULL); 00051 00052 /* Now insert a set of handles */ 00053 00054 now = time(NULL); 00055 00056 for(i = 0; i < 10000; i++) 00057 { 00058 nfs23_map_handle_t nfs23_digest; 00059 fsal_handle_t handle; 00060 00061 memset(&handle, i, sizeof(fsal_handle_t)); 00062 nfs23_digest.object_id = 12345 + i; 00063 nfs23_digest.handle_hash = (1999 * i + now) % 479001599; 00064 00065 rc = handlemap_db_insert(&nfs23_digest, &handle); 00066 if(rc) 00067 exit(rc); 00068 } 00069 00070 gettimeofday(&tv2, NULL); 00071 00072 timersub(&tv2, &tv1, &tvdiff); 00073 00074 LogTest("%u threads inserted 10000 handles in %d.%06ds", count, (int)tvdiff.tv_sec, 00075 (int)tvdiff.tv_usec); 00076 00077 rc = handlemap_db_flush(); 00078 00079 gettimeofday(&tv3, NULL); 00080 00081 timersub(&tv3, &tv1, &tvdiff); 00082 LogTest("Total time with %u threads (including flush): %d.%06ds", count, 00083 (int)tvdiff.tv_sec, (int)tvdiff.tv_usec); 00084 00085 LogTest("Now, delete operations"); 00086 00087 for(i = 0; i < 10000; i++) 00088 { 00089 nfs23_map_handle_t nfs23_digest; 00090 00091 nfs23_digest.object_id = 12345 + i; 00092 nfs23_digest.handle_hash = (1999 * i + now) % 479001599; 00093 00094 rc = handlemap_db_delete(&nfs23_digest); 00095 if(rc) 00096 exit(rc); 00097 } 00098 00099 gettimeofday(&tv2, NULL); 00100 timersub(&tv2, &tv3, &tvdiff); 00101 00102 LogTest("%u threads deleted 10000 handles in %d.%06ds", count, (int)tvdiff.tv_sec, 00103 (int)tvdiff.tv_usec); 00104 00105 rc = handlemap_db_flush(); 00106 00107 gettimeofday(&tv1, NULL); 00108 timersub(&tv1, &tv3, &tvdiff); 00109 LogTest("Delete time with %u threads (including flush): %d.%06ds", count, 00110 (int)tvdiff.tv_sec, (int)tvdiff.tv_usec); 00111 00112 exit(0); 00113 00114 }