nfs-ganesha 1.4

test_handle_mapping.c

Go to the documentation of this file.
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   handle_map_param_t param;
00012   time_t now;
00013 
00014   /* Init logging */
00015   SetNamePgm("test_handle_mapping");
00016   SetDefaultLogging("TEST");
00017   SetNameFunction("main");
00018   SetNameHost("localhost");
00019   InitLogging();
00020 
00021   if(argc != 3 || (count = atoi(argv[2])) == 0)
00022     {
00023       LogTest("usage: test_handle_mapping <db_dir> <db_count>");
00024       exit(1);
00025     }
00026 
00027   dir = argv[1];
00028 
00029   strcpy(param.databases_directory, dir);
00030   strcpy(param.temp_directory, "/tmp");
00031   param.database_count = count;
00032   param.hashtable_size = 27;
00033   param.nb_handles_prealloc = 1024;
00034   param.nb_db_op_prealloc = 1024;
00035   param.synchronous_insert = FALSE;
00036 
00037   rc = HandleMap_Init(&param);
00038 
00039   LogTest("HandleMap_Init() = %d", rc);
00040   if(rc)
00041     exit(rc);
00042 
00043   gettimeofday(&tv1, NULL);
00044 
00045   /* Now insert a set of handles */
00046 
00047   now = time(NULL);
00048 
00049   for(i = 0; i < 10000; i++)
00050     {
00051       nfs23_map_handle_t nfs23_digest;
00052       fsal_handle_t handle;
00053 
00054       memset(&handle, i, sizeof(fsal_handle_t));
00055       nfs23_digest.object_id = 12345 + i;
00056       nfs23_digest.handle_hash = (1999 * i + now) % 479001599;
00057 
00058       rc = HandleMap_SetFH(&nfs23_digest, &handle);
00059       if(rc && (rc != HANDLEMAP_EXISTS))
00060         exit(rc);
00061     }
00062 
00063   gettimeofday(&tv2, NULL);
00064 
00065   timersub(&tv2, &tv1, &tvdiff);
00066 
00067   LogTest("%u threads inserted 10000 handles in %d.%06ds",
00068           count, (int)tvdiff.tv_sec, (int)tvdiff.tv_usec);
00069 
00070   /* Now get them ! */
00071 
00072   for(i = 0; i < 10000; i++)
00073     {
00074       nfs23_map_handle_t nfs23_digest;
00075       fsal_handle_t handle;
00076 
00077       nfs23_digest.object_id = 12345 + i;
00078       nfs23_digest.handle_hash = (1999 * i + now) % 479001599;
00079 
00080       rc = HandleMap_GetFH(&nfs23_digest, &handle);
00081       if(rc)
00082         {
00083           LogTest("Error %d retrieving handle !", rc);
00084           exit(rc);
00085         }
00086 
00087       rc = HandleMap_DelFH(&nfs23_digest);
00088       if(rc)
00089         {
00090           LogTest("Error %d deleting handle !", rc);
00091           exit(rc);
00092         }
00093 
00094     }
00095 
00096   gettimeofday(&tv3, NULL);
00097 
00098   timersub(&tv3, &tv2, &tvdiff);
00099 
00100   LogTest("Retrieved and deleted 10000 handles in %d.%06ds", (int)tvdiff.tv_sec,
00101           (int)tvdiff.tv_usec);
00102 
00103   rc = HandleMap_Flush();
00104 
00105   gettimeofday(&tv3, NULL);
00106 
00107   timersub(&tv3, &tv1, &tvdiff);
00108   LogTest("Total time with %u threads (including flush): %d.%06ds", count,
00109           (int)tvdiff.tv_sec, (int)tvdiff.tv_usec);
00110 
00111   exit(0);
00112 
00113 }