1   // +build ignore
2 
3  #include <stdio.h>
4  #include <stdlib.h>
5  #include <string.h>
6  #include <stdint.h>
7  #include <time.h>
8  #include <sys/time.h>
9  #if !defined(WIN32) && !defined(_WIN32)
10  #include <unistd.h>
11  #endif
12 
13  #include "libforestdb/forestdb.h"
14 
do_test1null15  void do_test1()
16  {
17 
18     printf("***** TEST1 SINGLE KV STORE 10M INSERT *****\n");
19 
20     fdb_file_handle *dbfile;
21     fdb_kvs_handle *main, *back;
22 
23     char keybuf[256], bodybuf[256];
24 
25     fdb_config fconfig = fdb_get_default_config();
26     fconfig.durability_opt = FDB_DRB_ASYNC;
27     fdb_kvs_config kvs_config = fdb_get_default_kvs_config();
28 
29     fdb_open(&dbfile, "./ctest1", &fconfig);
30     fdb_kvs_open(dbfile, &main, "main", &kvs_config);
31 
32     int i;
33     int n = 10000000;
34 
35     char **keyarr = (char **)malloc(n * sizeof(char *));
36     char **bodyarr = (char **)malloc(n * sizeof(char *));
37 
38     for (i=0;i<n;++i){
39           keyarr[i] = (char *)malloc(25);
40           bodyarr[i] = (char *)malloc(25);
41           sprintf(keyarr[i], "key%d", i);
42           sprintf(bodyarr[i], "body%d", i);
43     }
44 
45     struct timeval ts_begin, ts_cur, ts_gap;
46     gettimeofday(&ts_begin, NULL);
47     for (i=0;i<n;++i){
48           fdb_set_kv(main, (void*)keyarr[i], strlen(keyarr[i]), (void*)bodyarr[i], strlen(bodyarr[i]));
49     }
50 
51     fdb_commit(dbfile, FDB_COMMIT_MANUAL_WAL_FLUSH);
52 
53     gettimeofday(&ts_cur, NULL);
54     timersub(&ts_cur, &ts_begin, &ts_gap);
55 
56     printf("***** RESULT : Docs Inserted %d Time Taken %d secs\n", n, (int)ts_gap.tv_sec);
57 
58     fdb_kvs_close(main);
59     fdb_close(dbfile);
60     fdb_shutdown();
61     system("rm ./ctest1");
62 }
63 
do_test2null64  void do_test2()
65  {
66 
67     printf("***** TEST2 TWO KV STORES 5M INSERT EACH *****\n");
68 
69     fdb_file_handle *dbfile;
70     fdb_kvs_handle *main, *back;
71 
72     char keybuf[256], bodybuf[256];
73 
74     fdb_config fconfig = fdb_get_default_config();
75     fconfig.durability_opt = FDB_DRB_ASYNC;
76     fdb_kvs_config kvs_config = fdb_get_default_kvs_config();
77 
78     fdb_open(&dbfile, "./ctest2", &fconfig);
79     fdb_kvs_open(dbfile, &main, "main", &kvs_config);
80     fdb_kvs_open(dbfile, &back, "back", &kvs_config);
81 
82     int i;
83     int n = 5000000;
84 
85     char **keyarr = (char **)malloc(n * sizeof(char *));
86     char **bodyarr = (char **)malloc(n * sizeof(char *));
87 
88     for (i=0;i<n;++i){
89           keyarr[i] = (char *)malloc(25);
90           bodyarr[i] = (char *)malloc(25);
91           sprintf(keyarr[i], "key%d", i);
92           sprintf(bodyarr[i], "body%d", i);
93     }
94 
95     struct timeval ts_begin, ts_cur, ts_gap;
96     gettimeofday(&ts_begin, NULL);
97     for (i=0;i<n;++i){
98           fdb_set_kv(back, (void*)keyarr[i], strlen(keyarr[i]), (void*)bodyarr[i], strlen(bodyarr[i]));
99           fdb_set_kv(main, (void*)keyarr[i], strlen(keyarr[i]), NULL, 0);
100     }
101 
102     fdb_commit(dbfile, FDB_COMMIT_MANUAL_WAL_FLUSH);
103 
104     gettimeofday(&ts_cur, NULL);
105     timersub(&ts_cur, &ts_begin, &ts_gap);
106     printf("***** RESULT : Docs Inserted %d Time Taken %d secs\n", n, (int)ts_gap.tv_sec);
107 
108     fdb_kvs_close(main);
109     fdb_kvs_close(back);
110     fdb_close(dbfile);
111     fdb_shutdown();
112     system("rm ./ctest2");
113 }
114 
do_test3null115  void do_test3()
116  {
117 
118     printf("***** TEST3 TWO KV STORES 5M INSERT EACH WITH GET *****\n");
119 
120     fdb_file_handle *dbfile;
121     fdb_kvs_handle *main, *back;
122 
123     char keybuf[256], bodybuf[256];
124 
125     fdb_config fconfig = fdb_get_default_config();
126     fconfig.durability_opt = FDB_DRB_ASYNC;
127     fdb_kvs_config kvs_config = fdb_get_default_kvs_config();
128 
129     fdb_open(&dbfile, "./ctest3", &fconfig);
130     fdb_kvs_open(dbfile, &main, "main", &kvs_config);
131     fdb_kvs_open(dbfile, &back, "back", &kvs_config);
132 
133     int i;
134     int n = 5000000;
135     size_t valuelen;
136     void *value;
137 
138     char **keyarr = (char **)malloc(n * sizeof(char *));
139     char **bodyarr = (char **)malloc(n * sizeof(char *));
140 
141     for (i=0;i<n;++i){
142           keyarr[i] = (char *)malloc(25);
143           bodyarr[i] = (char *)malloc(25);
144           sprintf(keyarr[i], "key%d", i);
145           sprintf(bodyarr[i], "body%d", i);
146     }
147 
148 
149     struct timeval ts_begin, ts_cur, ts_gap;
150     gettimeofday(&ts_begin, NULL);
151     for (i=0;i<n;++i){
152           //fdb_doc_create(&doc[i], (void*)keybuf, strlen(keybuf),
153            //      null, 0, (void*)bodybuf, strlen(bodybuf));
154           //fdb_set(main, doc[i]);
155           //fdb_doc_free(doc[i]);
156           fdb_get_kv(back, (void*)keyarr[i], strlen(keyarr[i]), &value, &valuelen);
157           fdb_set_kv(back, (void*)keyarr[i], strlen(keyarr[i]), (void*)bodyarr[i], strlen(bodyarr[i]));
158           fdb_set_kv(main, (void*)keyarr[i], strlen(keyarr[i]), NULL, 0);
159     }
160 
161     fdb_commit(dbfile, FDB_COMMIT_MANUAL_WAL_FLUSH);
162 
163     gettimeofday(&ts_cur, NULL);
164     timersub(&ts_cur, &ts_begin, &ts_gap);
165     printf("***** RESULT : Docs Inserted %d Time Taken %d secs\n", n, (int)ts_gap.tv_sec);
166 
167     fdb_kvs_close(main);
168     fdb_kvs_close(back);
169     fdb_close(dbfile);
170     fdb_shutdown();
171     system("rm ./ctest3");
172 }
173 
mainnull174 int main(){
175          do_test1();
176          do_test2();
177          do_test3();
178 }
179