Skip to content

Commit d1cf827

Browse files
committed
add clear.sh
1 parent bea9ace commit d1cf827

File tree

5 files changed

+63
-31
lines changed

5 files changed

+63
-31
lines changed

clear.sh

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ rm -rf CMakeCache.txt
44
rm -rf CMakeFiles
55
rm -rf Makefile
66
rm -rf *.cmake
7+
8+
cat CMakeLists.txt| grep add_executable | sed 's/(/\ /g' | awk '{print $2}' | xargs rm
9+
rm -rf testdb

ldb.c

+32-17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ typedef struct {
88
int max_open_files;
99
int sync;
1010
int bits_per_key;
11+
long write_buffer_size;
12+
long max_file_size;
1113

1214
char *db_name;
1315
char *compression;
@@ -87,6 +89,20 @@ static command_t cmds[] = {
8789
offsetof(ldb_options_t, range_end),
8890
""
8991
},
92+
{
93+
"",
94+
"write_buffer_size",
95+
cmd_set_size,
96+
offsetof(ldb_options_t, write_buffer_size),
97+
"16m"
98+
},
99+
{
100+
"",
101+
"max_file_size",
102+
cmd_set_size,
103+
offsetof(ldb_options_t, max_file_size),
104+
"16m"
105+
},
90106
{
91107
"",
92108
"propname",
@@ -140,7 +156,7 @@ static void ldb_get(leveldb_t *ldb, const char *db_name, const char *line, level
140156

141157
char *value = leveldb_get(ldb, ropt, line, strlen(line), &vallen, &errstr);
142158

143-
printf("leveldb_get key <%s> %s, vallen = %lu, errstr = %s, taken %.2fms\n", line, value ? "HIT" : "MISS", vallen, errstr ? errstr : "errstr is empty", tv_sub_msec_double(tv_now(), tv));
159+
log_info("leveldb_get key <%s> %s, vallen = %lu, errstr = %s, taken %.2fms", line, value ? "HIT" : "MISS", vallen, errstr ? errstr : "errstr is empty", tv_sub_msec_double(tv_now(), tv));
144160

145161
leveldb_free(errstr);
146162
leveldb_free(value);
@@ -161,9 +177,7 @@ static void process_ldb_get(leveldb_t *ldb, ldb_options_t *opt) {
161177
*enter = '\0';
162178
}
163179

164-
for (int i = 0; i < 1000; i++) {
165-
ldb_get(ldb, opt->db_name, line, ropt);
166-
}
180+
ldb_get(ldb, opt->db_name, line, ropt);
167181
}
168182

169183
leveldb_readoptions_destroy(ropt);
@@ -176,10 +190,10 @@ static void ldb_put(leveldb_t *ldb, const char *db_name, const char *line, level
176190
leveldb_put(ldb, wopt, line, strlen(line), line, strlen(line), &errstr);
177191

178192
if (errstr) {
179-
printf("leveldb_put key <%s> to db %s error: %s\n", line, db_name, errstr);
193+
log_info("leveldb_put key <%s> to db %s error: %s", line, db_name, errstr);
180194
leveldb_free(errstr);
181195
} else {
182-
printf("leveldb_put key <%s> to db %s taken %.2fms\n", line, db_name, tv_sub_msec_double(tv_now(), tv));
196+
// log_info("leveldb_put key <%s> to db %s taken %.2fms", line, db_name, tv_sub_msec_double(tv_now(), tv));
183197
}
184198
}
185199

@@ -218,7 +232,7 @@ static void process_ldb_keys(leveldb_t *ldb, ldb_options_t *opt) {
218232
tv = tv_end;
219233

220234
if (key) {
221-
printf("process key <%.*s> klen = %lu, taken %.2fms\n", (int)klen, key, klen, ms_taken);
235+
log_info("process key <%.*s> klen = %lu, taken %.2fms", (int)klen, key, klen, ms_taken);
222236
}
223237

224238
leveldb_iter_next(iter);
@@ -229,20 +243,20 @@ static void process_ldb_keys(leveldb_t *ldb, ldb_options_t *opt) {
229243
}
230244

231245
static void process_ldb_compact_range(leveldb_t *ldb, ldb_options_t *opt) {
232-
printf("start to compact_range start <%s> end <%s>\n", opt->range_start, opt->range_end);
246+
log_info("start to compact_range start <%s> end <%s>", opt->range_start, opt->range_end);
233247

234248
struct timeval tv_start = tv_now();
235249
leveldb_compact_range(ldb, opt->range_start, strlen(opt->range_start), opt->range_end, strlen(opt->range_end));
236-
printf("compact finished! taken %.2fms\n", tv_sub_msec_double(tv_now(), tv_start));
250+
log_info("compact finished! taken %.2fms", tv_sub_msec_double(tv_now(), tv_start));
237251
}
238252

239253
static void process_ldb_property(leveldb_t *ldb, ldb_options_t *opt) {
240254
char *value = leveldb_property_value(ldb, opt->propname);
241255

242256
if (value == NULL) {
243-
printf("get property <%s> but return NULL\n", opt->propname);
257+
log_info("get property <%s> but return NULL", opt->propname);
244258
} else {
245-
printf("%s\n", value);
259+
log_info("%s", value);
246260
leveldb_free(value);
247261
}
248262
}
@@ -253,7 +267,7 @@ static void process_ldb_repair(ldb_options_t *ldb_opt, leveldb_options_t *opt) {
253267
struct timeval tv_start = tv_now();
254268
leveldb_repair_db(opt, ldb_opt->db_name, &errstr);
255269

256-
printf("repair db <%s> %s! taken %.2fms", ldb_opt->db_name, errstr == NULL ? "successful!" : errstr, tv_sub_msec_double(tv_now(), tv_start));
270+
log_info("repair db <%s> %s! taken %.2fms", ldb_opt->db_name, errstr == NULL ? "successful!" : errstr, tv_sub_msec_double(tv_now(), tv_start));
257271
leveldb_free(errstr);
258272
}
259273

@@ -262,12 +276,12 @@ static void process_ldb(leveldb_t *ldb, const char *typ, const char *errstr, ldb
262276
if (errstr == NULL) {
263277
errstr = "no error str";
264278
}
265-
printf("open %s error: %s\n", opt->db_name, errstr);
279+
log_info("open %s error: %s", opt->db_name, errstr);
266280
return;
267281
}
268282

269283
if (typ == NULL) {
270-
printf("type is NULL, impossible!\n");
284+
log_info("type is NULL, impossible!");
271285
} else if (!strcasecmp(typ, "get")) {
272286
process_ldb_get(ldb, opt);
273287
} else if (!strcasecmp(typ, "put")) {
@@ -279,7 +293,7 @@ static void process_ldb(leveldb_t *ldb, const char *typ, const char *errstr, ldb
279293
} else if (!strcasecmp(typ, "property")) {
280294
process_ldb_property(ldb, opt);
281295
} else {
282-
printf("invalid type %s\n", typ);
296+
log_info("invalid type %s", typ);
283297
}
284298
}
285299

@@ -306,6 +320,9 @@ int main(int argc, const char *argv[]) {
306320
leveldb_options_t *opt = leveldb_options_create();
307321
leveldb_options_set_create_if_missing(opt, 1);
308322
leveldb_options_set_max_open_files(opt, ldb_opt->max_open_files);
323+
leveldb_options_set_write_buffer_size(opt, ldb_opt->write_buffer_size);
324+
// leveldb_options_set_max_file_size(opt, ldb_opt->max_file_size);
325+
log_info("write_buffer_size is %ld", ldb_opt->write_buffer_size);
309326
if (!strcasecmp(ldb_opt->compression, "snappy")) {
310327
leveldb_options_set_compression(opt, leveldb_snappy_compression);
311328
}
@@ -321,8 +338,6 @@ int main(int argc, const char *argv[]) {
321338
leveldb_options_set_cache(opt, cache);
322339
}
323340

324-
// leveldb_options_set_max_file_size(opt, 1024 * 1024 * 8);
325-
326341
if (!strcasecmp(type, "repair")) {
327342
process_ldb_repair(ldb_opt, opt);
328343
} else {

rdb.c

+18-12
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void ldb_get(rocksdb_t *ldb, const char *db_name, const char *line, rocks
140140

141141
char *value = rocksdb_get(ldb, ropt, line, strlen(line), &vallen, &errstr);
142142

143-
printf("rocksdb_get key <%s> %s, vallen = %lu, errstr = %s, taken %.2fms\n", line, value ? "HIT" : "MISS", vallen, errstr ? errstr : "errstr is empty", tv_sub_msec_double(tv_now(), tv));
143+
log_info("rocksdb_get key <%s> %s, vallen = %lu, errstr = %s, taken %.2fms", line, value ? "HIT" : "MISS", vallen, errstr ? errstr : "errstr is empty", tv_sub_msec_double(tv_now(), tv));
144144

145145
rocksdb_free(errstr);
146146
rocksdb_free(value);
@@ -172,14 +172,18 @@ static void process_ldb_get(rocksdb_t *ldb, ldb_options_t *opt) {
172172
static void ldb_put(rocksdb_t *ldb, const char *db_name, const char *line, rocksdb_writeoptions_t *wopt) {
173173
char *errstr = NULL;
174174
struct timeval tv = tv_now();
175+
static int i = 0;
175176

176177
rocksdb_put(ldb, wopt, line, strlen(line), line, strlen(line), &errstr);
177178

178179
if (errstr) {
179-
printf("rocksdb_put key <%s> to db %s error: %s\n", line, db_name, errstr);
180+
log_info("rocksdb_put key <%s> to db %s error: %s", line, db_name, errstr);
180181
rocksdb_free(errstr);
181182
} else {
182-
printf("rocksdb_put key <%s> to db %s taken %.2fms\n", line, db_name, tv_sub_msec_double(tv_now(), tv));
183+
i++;
184+
if (i % 10000 == 0) {
185+
log_info("rocksdb_put key <%s> to db %s taken %.2fms", line, db_name, tv_sub_msec_double(tv_now(), tv));
186+
}
183187
}
184188
}
185189

@@ -220,7 +224,7 @@ static void process_ldb_keys(rocksdb_t *ldb, ldb_options_t *opt) {
220224
tv = tv_end;
221225

222226
if (key) {
223-
printf("process key <%.*s> klen = %lu, value <%.*s> vlen = %lu, taken %.2fms\n", (int)klen, key, klen, (int)vlen, value, vlen, ms_taken);
227+
log_info("process key <%.*s> klen = %lu, value <%.*s> vlen = %lu, taken %.2fms", (int)klen, key, klen, (int)vlen, value, vlen, ms_taken);
224228
}
225229

226230
rocksdb_iter_next(iter);
@@ -231,20 +235,20 @@ static void process_ldb_keys(rocksdb_t *ldb, ldb_options_t *opt) {
231235
}
232236

233237
static void process_ldb_compact_range(rocksdb_t *ldb, ldb_options_t *opt) {
234-
printf("start to compact_range start <%s> end <%s>\n", opt->range_start, opt->range_end);
238+
log_info("start to compact_range start <%s> end <%s>", opt->range_start, opt->range_end);
235239

236240
struct timeval tv_start = tv_now();
237241
rocksdb_compact_range(ldb, opt->range_start, strlen(opt->range_start), opt->range_end, strlen(opt->range_end));
238-
printf("compact finished! taken %.2fms\n", tv_sub_msec_double(tv_now(), tv_start));
242+
log_info("compact finished! taken %.2fms", tv_sub_msec_double(tv_now(), tv_start));
239243
}
240244

241245
static void process_ldb_property(rocksdb_t *ldb, ldb_options_t *opt) {
242246
char *value = rocksdb_property_value(ldb, opt->propname);
243247

244248
if (value == NULL) {
245-
printf("get property <%s> but return NULL\n", opt->propname);
249+
log_info("get property <%s> but return NULL", opt->propname);
246250
} else {
247-
printf("%s\n", value);
251+
log_info("%s", value);
248252
rocksdb_free(value);
249253
}
250254
}
@@ -255,7 +259,7 @@ static void process_ldb_repair(ldb_options_t *ldb_opt, rocksdb_options_t *opt) {
255259
struct timeval tv_start = tv_now();
256260
rocksdb_repair_db(opt, ldb_opt->db_name, &errstr);
257261

258-
printf("repair db <%s> %s! taken %.2fms", ldb_opt->db_name, errstr == NULL ? "successful!" : errstr, tv_sub_msec_double(tv_now(), tv_start));
262+
log_info("repair db <%s> %s! taken %.2fms", ldb_opt->db_name, errstr == NULL ? "successful!" : errstr, tv_sub_msec_double(tv_now(), tv_start));
259263
rocksdb_free(errstr);
260264
}
261265

@@ -264,12 +268,12 @@ static void process_ldb(rocksdb_t *ldb, const char *typ, const char *errstr, ldb
264268
if (errstr == NULL) {
265269
errstr = "no error str";
266270
}
267-
printf("open %s error: %s\n", opt->db_name, errstr);
271+
log_info("open %s error: %s", opt->db_name, errstr);
268272
return;
269273
}
270274

271275
if (typ == NULL) {
272-
printf("type is NULL, impossible!\n");
276+
log_info("type is NULL, impossible!");
273277
} else if (!strcasecmp(typ, "get")) {
274278
process_ldb_get(ldb, opt);
275279
} else if (!strcasecmp(typ, "put")) {
@@ -281,7 +285,7 @@ static void process_ldb(rocksdb_t *ldb, const char *typ, const char *errstr, ldb
281285
} else if (!strcasecmp(typ, "property")) {
282286
process_ldb_property(ldb, opt);
283287
} else {
284-
printf("invalid type %s\n", typ);
288+
log_info("invalid type %s", typ);
285289
}
286290
}
287291

@@ -308,6 +312,8 @@ int main(int argc, const char *argv[]) {
308312
rocksdb_options_t *opt = rocksdb_options_create();
309313
rocksdb_options_set_create_if_missing(opt, 1);
310314
rocksdb_options_set_max_open_files(opt, ldb_opt->max_open_files);
315+
//rocksdb_options_set_target_file_size_base(opt, 32 * 1024 * 1024);
316+
//rocksdb_options_set_target_file_size_multiplier(opt, 2);
311317
if (!strcasecmp(ldb_opt->compression, "snappy")) {
312318
rocksdb_options_set_compression(opt, rocksdb_snappy_compression);
313319
}

string_printf.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,11 @@ int main(int argc, const char **argv) {
113113
test<v1>(n);
114114
test<v2>(n);
115115
}
116+
117+
/*
118+
* Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
119+
$ ./string_printf 100000
120+
test 2v1: loop 100000 times, taken 12539 msec, s.length = 19888890
121+
test 2v2: loop 100000 times, taken 25 msec, s.length = 19888890
122+
*
123+
*/

test_keepalive.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static config cfg;
1010

1111
static command_t cmds[] = {
1212
{
13-
"h",
13+
"",
1414
"host",
1515
cmd_set_str,
1616
offsetof(config, host),
@@ -25,7 +25,7 @@ static command_t cmds[] = {
2525
},
2626
{
2727
"s",
28-
"",
28+
"sleep_second",
2929
cmd_set_int,
3030
offsetof(config, sleep_second),
3131
""

0 commit comments

Comments
 (0)