Comment #1 on issue 164 by
wuzuy...@gmail.com: leveldb writes blocks
occassionarily
http://code.google.com/p/leveldb/issues/detail?id=164
The attachment may be mission, repost.
{{{
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <string>
#include "leveldb/db.h"
#include "leveldb/options.h"
#include "leveldb/slice.h"
static inline double microtime(){
struct timeval now;
gettimeofday(&now, NULL);
double ret = now.tv_sec + now.tv_usec/1000.0/1000.0;
return ret;
}
int main(int argc, char **argv){
int nums = 1000;
if(argc > 1){
nums = atoi(argv[1]);
}
printf("nums: %d\n", nums);
leveldb::DB* db;
leveldb::Options options;
leveldb::Status status;
options.create_if_missing = true;
status = leveldb::DB::Open(options, "a", &db);
if(!status.ok()){
printf("open leveldb: %s error!\n", "a");
return 0;
}
char buf[1024];
srand ( time(NULL) );
for(int i=0; i<nums; i++){
snprintf(buf, sizeof(buf), "%d%d", rand(), rand());
std::string k(buf);
std::string v(rand()%(100*1024), 'a');
double stime = microtime();
status = db->Put(leveldb::WriteOptions(), k, v);
double ts = 1000 * (microtime() - stime);
if(ts > 100){
printf("%5d: slow log: %8.3f\n", i, ts);
}
if(!status.ok()){
printf("put leveldb error!\n");
break;
}
}
delete db;
return 0;
}
}}}
Attachments:
test.cpp 1.2 KB