Loading...
Searching...
No Matches
kv_server_performance.cpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#include <glog/logging.h>
21
28#include "proto/kv/kv.pb.h"
29
30using namespace resdb;
31using namespace resdb::storage;
32
33void ShowUsage() {
34 printf("<config> <private_key> <cert_file> [logging_dir]\n");
35}
36
37std::string GetRandomKey() {
38 int num1 = rand() % 10;
39 int num2 = rand() % 10;
40 return std::to_string(num1) + std::to_string(num2);
41}
42
43int main(int argc, char** argv) {
44 if (argc < 3) {
45 ShowUsage();
46 exit(0);
47 }
48
49 // google::InitGoogleLogging(argv[0]);
50 // FLAGS_minloglevel = google::GLOG_WARNING;
51
52 char* config_file = argv[1];
53 char* private_key_file = argv[2];
54 char* cert_file = argv[3];
55
56 if (argc >= 5) {
57 auto monitor_port = Stats::GetGlobalStats(5);
58 monitor_port->SetPrometheus(argv[4]);
59 }
60
61 std::unique_ptr<ResDBConfig> config =
62 GenerateResDBConfig(config_file, private_key_file, cert_file);
63
64 config->RunningPerformance(true);
65
66 auto performance_consens = std::make_unique<ConsensusManagerPBFT>(
67 *config, std::make_unique<KVExecutor>(std::make_unique<MemoryDB>()));
68 performance_consens->SetupPerformanceDataFunc([]() {
69 KVRequest request;
70 request.set_cmd(KVRequest::SET);
71 request.set_key(GetRandomKey());
72 request.set_value("helloworld");
73 std::string request_data;
74 request.SerializeToString(&request_data);
75 return request_data;
76 });
77
78 auto server =
79 std::make_unique<ServiceNetwork>(*config, std::move(performance_consens));
80 server->Run();
81}
static Stats * GetGlobalStats(int sleep_seconds=5)
Definition stats.cpp:29
std::string GetRandomKey()
int main(int argc, char **argv)
void ShowUsage()
std::unique_ptr< ResDBConfig > GenerateResDBConfig(const std::string &config_file, const std::string &private_key_file, const std::string &cert_file, std::optional< ReplicaInfo > self_info, std::optional< ConfigGenFunc > gen_func)