|
@ -0,0 +1,122 @@ |
|
|
|
|
|
#include "leveldb/db.h"
|
|
|
|
|
|
#include "leveldb/my_leveldb.h"
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
using namespace leveldb; |
|
|
|
|
|
|
|
|
|
|
|
// ÍÌÍÂÁ¿
|
|
|
|
|
|
void TestThroughput(int num_operations) { |
|
|
|
|
|
WriteOptions writeOptions; |
|
|
|
|
|
ReadOptions readOptions; |
|
|
|
|
|
Options options; |
|
|
|
|
|
options.create_if_missing = true; |
|
|
|
|
|
auto db1 = new MyLevelDB(options, "testThroughput"); |
|
|
|
|
|
std::string key = "k_"; |
|
|
|
|
|
FieldArray fields = {{"name", "Customer#000000001"}, |
|
|
|
|
|
{"address", "IVhzIApeRb"}, |
|
|
|
|
|
{"phone", "25-989-741-2988"}}; |
|
|
|
|
|
//д
|
|
|
|
|
|
auto start_time1 = std::chrono::steady_clock::now(); |
|
|
|
|
|
for (int i = 0; i < num_operations; ++i) { |
|
|
|
|
|
db1->PutWithFields(WriteOptions(), key + to_string(i), fields); |
|
|
|
|
|
} |
|
|
|
|
|
auto end_time1 = std::chrono::steady_clock::now(); |
|
|
|
|
|
auto duration1 = |
|
|
|
|
|
chrono::duration_cast<chrono::milliseconds>(end_time1 - start_time1) |
|
|
|
|
|
.count(); |
|
|
|
|
|
cout << "Put Op Throughput: " << num_operations * 1000 / duration1 << " OPS" << endl; |
|
|
|
|
|
//¶Á
|
|
|
|
|
|
string str; |
|
|
|
|
|
auto start_time2 = std::chrono::steady_clock::now(); |
|
|
|
|
|
for (int i = 0; i < num_operations*100; ++i) { |
|
|
|
|
|
db1->Get(ReadOptions(), key, &str); |
|
|
|
|
|
} |
|
|
|
|
|
auto end_time2 = std::chrono::steady_clock::now(); |
|
|
|
|
|
auto duration2 = |
|
|
|
|
|
chrono::duration_cast<chrono::milliseconds>(end_time2 - start_time2) |
|
|
|
|
|
.count(); |
|
|
|
|
|
//cout << duration2 << endl;
|
|
|
|
|
|
cout << "Get Op Throughput: " << num_operations*100 * 1000 / duration2 << " OPS" |
|
|
|
|
|
<< endl; |
|
|
|
|
|
|
|
|
|
|
|
//×ֶβéÕÒ
|
|
|
|
|
|
std::vector<std::string> keys; |
|
|
|
|
|
auto start_time3 = std::chrono::steady_clock::now(); |
|
|
|
|
|
for (int i = 0; i < num_operations; ++i) { |
|
|
|
|
|
db1->FindKeysByField(ReadOptions(), fields[0],&keys); |
|
|
|
|
|
} |
|
|
|
|
|
auto end_time3 = std::chrono::steady_clock::now(); |
|
|
|
|
|
auto duration3 = |
|
|
|
|
|
chrono::duration_cast<chrono::milliseconds>(end_time3 - start_time3) |
|
|
|
|
|
.count(); |
|
|
|
|
|
cout << "FindKeysByField Op Throughput: " << num_operations * 1000 / duration3 << " OPS" |
|
|
|
|
|
<< endl; |
|
|
|
|
|
} |
|
|
|
|
|
// ÑÓ³Ù
|
|
|
|
|
|
void TestLatency(int num_operations) { |
|
|
|
|
|
Options options; |
|
|
|
|
|
options.create_if_missing = true; |
|
|
|
|
|
auto db = new MyLevelDB(options, "testLatency"); |
|
|
|
|
|
std::string key = "k_"; |
|
|
|
|
|
FieldArray fields = {{"name", "Customer#000000001"}, |
|
|
|
|
|
{"address", "IVhzIApeRb"}, |
|
|
|
|
|
{"phone", "25-989-741-2988"}}; |
|
|
|
|
|
//Put
|
|
|
|
|
|
int64_t latency1 = 0; |
|
|
|
|
|
int64_t tollatency = 0; |
|
|
|
|
|
auto end_time1 = std::chrono::steady_clock::now(); |
|
|
|
|
|
auto last_time1 = end_time1; |
|
|
|
|
|
for (int i = 0; i < num_operations*100; ++i) { |
|
|
|
|
|
// Operations
|
|
|
|
|
|
db->PutWithFields(WriteOptions(), key + to_string(i), fields); |
|
|
|
|
|
end_time1 = std::chrono::steady_clock::now(); |
|
|
|
|
|
latency1 = std::chrono::duration_cast<std::chrono::milliseconds>(end_time1 - |
|
|
|
|
|
last_time1) |
|
|
|
|
|
.count(); |
|
|
|
|
|
last_time1 = end_time1; |
|
|
|
|
|
tollatency += latency1; |
|
|
|
|
|
} |
|
|
|
|
|
std::cout << num_operations*100<<" put op averange latency:" << (double)tollatency / num_operations<< std::endl; |
|
|
|
|
|
//Get
|
|
|
|
|
|
int64_t latency2 = 0; |
|
|
|
|
|
tollatency = 0; |
|
|
|
|
|
auto end_time2 = std::chrono::steady_clock::now(); |
|
|
|
|
|
auto last_time2 = end_time2; |
|
|
|
|
|
std::string str; |
|
|
|
|
|
for (int i = 0; i < num_operations*100; ++i) { |
|
|
|
|
|
// Operations
|
|
|
|
|
|
db->Get(ReadOptions(), key + to_string(i),&str ); |
|
|
|
|
|
end_time2 = std::chrono::steady_clock::now(); |
|
|
|
|
|
latency2 = std::chrono::duration_cast<std::chrono::milliseconds>(end_time2 - |
|
|
|
|
|
last_time2) |
|
|
|
|
|
.count(); |
|
|
|
|
|
last_time2 = end_time2; |
|
|
|
|
|
tollatency += latency2; |
|
|
|
|
|
} |
|
|
|
|
|
std::cout << num_operations*100 |
|
|
|
|
|
<< " Get operation averange latency:" << (double)tollatency / num_operations |
|
|
|
|
|
<< std::endl; |
|
|
|
|
|
//FindKeysByField
|
|
|
|
|
|
int64_t latency3 = 0; |
|
|
|
|
|
tollatency = 0; |
|
|
|
|
|
auto end_time3 = std::chrono::steady_clock::now(); |
|
|
|
|
|
auto last_time3 = end_time3; |
|
|
|
|
|
std::vector<std::string> keys; |
|
|
|
|
|
for (int i = 0; i < 50; ++i) { |
|
|
|
|
|
// Operations
|
|
|
|
|
|
db->FindKeysByField(ReadOptions(), fields[0], &keys); |
|
|
|
|
|
end_time3 = std::chrono::steady_clock::now(); |
|
|
|
|
|
latency3 = std::chrono::duration_cast<std::chrono::milliseconds>(end_time3 - |
|
|
|
|
|
last_time3) |
|
|
|
|
|
.count(); |
|
|
|
|
|
last_time3 = end_time3; |
|
|
|
|
|
tollatency += latency3; |
|
|
|
|
|
} |
|
|
|
|
|
std::cout << 50 << " FindKeysByField operation averange latency:" |
|
|
|
|
|
<< (double)tollatency / num_operations << "ms" |
|
|
|
|
|
<< std::endl; |
|
|
|
|
|
} |
|
|
|
|
|
int main() { |
|
|
|
|
|
TestThroughput(100); |
|
|
|
|
|
TestLatency(1000); |
|
|
|
|
|
} |