提交 d370b2f3 编写于 作者: W wangjiawei04

May 25 manually merge with coupling kv db

Change-Id: I7eb2d4d3905697aac3a6c55398a213967dcc3809
上级 3a754592
......@@ -26,6 +26,7 @@ message(STATUS "CXX compiler: ${CMAKE_CXX_COMPILER}, version: "
message(STATUS "C compiler: ${CMAKE_C_COMPILER}, version: "
"${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}")
find_package(Git REQUIRED)
find_package(Threads REQUIRED)
find_package(CUDA QUIET)
......@@ -46,7 +47,7 @@ set(THIRD_PARTY_BUILD_TYPE Release)
option(WITH_AVX "Compile Paddle Serving with AVX intrinsics" ${AVX_FOUND})
option(WITH_MKL "Compile Paddle Serving with MKL support." ${AVX_FOUND})
option(WITH_GPU "Compile Paddle Serving with NVIDIA GPU" ${CUDA_FOUND})
#option(WITH_GPU "Compile Paddle Serving with NVIDIA GPU" ${CUDA_FOUND})
option(CLIENT_ONLY "Compile client libraries and demos only" FALSE)
set(WITH_MKLML ${WITH_MKL})
......@@ -60,6 +61,7 @@ if (NOT DEFINED WITH_MKLDNN)
endif()
include(external/leveldb)
include(external/rocksdb)
include(external/zlib)
include(external/boost)
include(external/protobuf)
......@@ -67,6 +69,7 @@ include(external/brpc)
include(external/gflags)
include(external/glog)
include(external/snappy)
#include(external/redis++)
include(generic)
include(flags)
......@@ -81,6 +84,8 @@ include_directories(${PADDLE_SERVING_BINARY_DIR})
set(EXTERNAL_LIBS
gflags
rocksdb
# redis++
glog
protobuf
paddlepaddle
......@@ -105,6 +110,7 @@ add_subdirectory(configure)
add_subdirectory(pdcodegen)
add_subdirectory(sdk-cpp)
add_subdirectory(demo-client)
add_subdirectory(kvdb)
if (NOT CLIENT_ONLY)
add_subdirectory(predictor)
......
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
INCLUDE(ExternalProject)
SET(REDISCLIENT_SOURCES_DIR ${THIRD_PARTY_PATH}/redis++)
SET(REDISCLIENT_INSTALL_DIR ${THIRD_PARTY_PATH}/install/redis++)
SET(REDISCLIENT_INCLUDE_DIR "${REDISCLIENT_INSTALL_DIR}/include" CACHE PATH "redis++ include directory." FORCE)
SET(REDISCLIENT_LIBRARIES "${REDISCLIENT_INSTALL_DIR}/lib/libredis++.a" CACHE FILEPATH "redis++ library." FORCE)
INCLUDE_DIRECTORIES(${REDISCLIENT_INCLUDE_DIR})
ExternalProject_Add(
extern_redis++
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${REDISCLIENT_SOURCES_DIR}
GIT_REPOSITORY "https://github.com/sewenew/redis-plus-plus"
GIT_TAG master
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND cmake . && CXXFLAGS=-fPIC make -j ${NUM_OF_PROCESSOR} static
INSTALL_COMMAND mkdir -p ${REDISCLIENT_INSTALL_DIR}/lib/
&& cp ${REDISCLIENT_SOURCES_DIR}/src/extern_redis++/lib/libredis++.a ${REDISCLIENT_LIBRARIES}
&& cp -r ${REDISCLIENT_SOURCES_DIR}/src/extern_redis++/src/sw/redis++/ ${REDISCLIENT_INSTALL_DIR}/include/redis++/
BUILD_IN_SOURCE 1
)
ADD_DEPENDENCIES(extern_redis++ snappy)
ADD_LIBRARY(redis++ STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET redis++ PROPERTY IMPORTED_LOCATION ${ROCKSDB_LIBRARIES})
ADD_DEPENDENCIES(redis++ extern_redis++)
LIST(APPEND external_project_dependencies redis++)
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
INCLUDE(ExternalProject)
SET(ROCKSDB_SOURCES_DIR ${THIRD_PARTY_PATH}/rocksdb)
SET(ROCKSDB_INSTALL_DIR ${THIRD_PARTY_PATH}/install/rocksdb)
SET(ROCKSDB_INCLUDE_DIR "${ROCKSDB_INSTALL_DIR}/include" CACHE PATH "rocksdb include directory." FORCE)
SET(ROCKSDB_LIBRARIES "${ROCKSDB_INSTALL_DIR}/lib/librocksdb.a" CACHE FILEPATH "rocksdb library." FORCE)
INCLUDE_DIRECTORIES(${ROCKSDB_INCLUDE_DIR})
ExternalProject_Add(
extern_rocksdb
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${ROCKSDB_SOURCES_DIR}
GIT_REPOSITORY "https://github.com/facebook/rocksdb"
GIT_TAG 6.1.fb
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND CXXFLAGS=-fPIC make -j ${NUM_OF_PROCESSOR} static_lib
INSTALL_COMMAND mkdir -p ${ROCKSDB_INSTALL_DIR}/lib/
&& cp ${ROCKSDB_SOURCES_DIR}/src/extern_rocksdb/librocksdb.a ${ROCKSDB_LIBRARIES}
&& cp -r ${ROCKSDB_SOURCES_DIR}/src/extern_rocksdb/include ${ROCKSDB_INSTALL_DIR}/
BUILD_IN_SOURCE 1
)
ADD_DEPENDENCIES(extern_rocksdb snappy)
ADD_LIBRARY(rocksdb STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET rocksdb PROPERTY IMPORTED_LOCATION ${ROCKSDB_LIBRARIES})
ADD_DEPENDENCIES(rocksdb extern_rocksdb)
LIST(APPEND external_project_dependencies rocksdb)
......@@ -30,6 +30,11 @@ target_link_libraries(echo -Wl,--whole-archive sdk-cpp -Wl,--no-whole-archive
-lpthread -lcrypto -lm -lrt -lssl -ldl
-lz)
add_executable(echo_kvdb ${CMAKE_CURRENT_LIST_DIR}/src/echo_kvdb.cpp)
target_link_libraries(echo_kvdb -Wl,--whole-archive sdk-cpp -Wl,--no-whole-archive
-lpthread -lcrypto -lm -lrt -lssl -ldl
-lz)
add_executable(dense_format ${CMAKE_CURRENT_LIST_DIR}/src/dense_format.cpp)
target_link_libraries(dense_format -Wl,--whole-archive sdk-cpp -Wl,--no-whole-archive -lpthread -lcrypto -lm -lrt -lssl -ldl
-lz)
......@@ -69,6 +74,11 @@ install(TARGETS echo
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/conf DESTINATION
${PADDLE_SERVING_INSTALL_DIR}/demo/client/echo/)
install(TARGETS echo_kvdb
RUNTIME DESTINATION ${PADDLE_SERVING_INSTALL_DIR}/demo/client/echo_kvdb/bin)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/conf DESTINATION
${PADDLE_SERVING_INSTALL_DIR}/demo/client/echo_kvdb/)
install(TARGETS dense_format
RUNTIME DESTINATION
${PADDLE_SERVING_INSTALL_DIR}/demo/client/dense_format/bin)
......
......@@ -109,3 +109,18 @@ predictors {
}
}
}
predictors {
name: "echo_kvdb_service"
service_name: "baidu.paddle_serving.predictor.echo_kvdb_service.EchoKVDBService"
endpoint_router: "WeightedRandomRender"
weighted_random_render_conf {
variant_weight_list: "50"
}
variants {
tag: "var1"
naming_conf {
cluster: "list://127.0.0.1:8010"
}
}
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include "sdk-cpp/builtin_format.pb.h"
#include "sdk-cpp/echo_kvdb_service.pb.h"
#include "sdk-cpp/include/common.h"
#include "sdk-cpp/include/predictor_sdk.h"
#include <algorithm>
using baidu::paddle_serving::sdk_cpp::Predictor;
using baidu::paddle_serving::sdk_cpp::PredictorApi;
using baidu::paddle_serving::predictor::echo_kvdb_service::Request;
using baidu::paddle_serving::predictor::echo_kvdb_service::Response;
using baidu::paddle_serving::predictor::format::KVDBReq;
using baidu::paddle_serving::predictor::format::KVDBRes;
int global_key = 0;
int create_req(Request& req) { // NOLINT
KVDBReq* key = req.mutable_reqs()->Add();
key->set_op("SET");
key->set_key(std::to_string(global_key));
key->set_value(std::to_string(global_key * 1));
key = req.mutable_reqs()->Add();
key->set_op("GET");
key->set_key(std::to_string(global_key));
global_key ++;
return 0;
}
void print_res(const Request& req,
const Response& res,
std::string route_tag,
uint64_t elapse_ms) {
LOG(INFO) << "Receive Response size: " << res.ress_size();
for(size_t i = 0; i < res.ress_size(); i++) {
KVDBRes val = res.ress(i);
LOG(INFO) << "Receive value from demo-server: " << val.value();
}
LOG(INFO) << "Succ call predictor[echo_kvdb_service], the tag is: " << route_tag
<< ", elapse_ms: " << elapse_ms;
}
int main(int argc, char** argv) {
PredictorApi api;
// initialize logger instance
#ifdef BCLOUD
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_FILE;
std::string filename(argv[0]);
filename = filename.substr(filename.find_last_of('/') + 1);
settings.log_file = (std::string("./log/") + filename + ".log").c_str();
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
logging::InitLogging(settings);
logging::ComlogSinkOptions cso;
cso.process_name = filename;
cso.enable_wf_device = true;
logging::ComlogSink::GetInstance()->Setup(&cso);
#else
struct stat st_buf;
int ret = 0;
if ((ret = stat("./log", &st_buf)) != 0) {
mkdir("./log", 0777);
ret = stat("./log", &st_buf);
if (ret != 0) {
LOG(WARNING) << "Log path ./log not exist, and create fail";
return -1;
}
}
FLAGS_log_dir = "./log";
google::InitGoogleLogging(strdup(argv[0]));
#endif
if (api.create("./conf", "predictors.prototxt") != 0) {
LOG(ERROR) << "Failed create predictors api!";
return -1;
}
Request req;
Response res;
api.thrd_initialize();
while (true) {
if(global_key > 10000)
break;
timeval start;
gettimeofday(&start, NULL);
api.thrd_clear();
Predictor* predictor = api.fetch_predictor("echo_kvdb_service");
if (!predictor) {
LOG(ERROR) << "Failed fetch predictor: echo_kvdb_service";
return -1;
}
req.Clear();
res.Clear();
if (create_req(req) != 0) {
return -1;
}
butil::IOBufBuilder debug_os;
if (predictor->debug(&req, &res, &debug_os) != 0) {
LOG(ERROR) << "failed call predictor with req:" << req.ShortDebugString();
return -1;
}
butil::IOBuf debug_buf;
debug_os.move_to(debug_buf);
LOG(INFO) << "Debug string: " << debug_buf;
timeval end;
gettimeofday(&end, NULL);
uint64_t elapse_ms = (end.tv_sec * 1000 + end.tv_usec / 1000) -
(start.tv_sec * 1000 + start.tv_usec / 1000);
print_res(req, res, predictor->tag(), elapse_ms);
res.Clear();
usleep(50);
} // while (true)
api.thrd_finalize();
api.destroy();
#ifndef BCLOUD
google::ShutdownGoogleLogging();
#endif
return 0;
}
/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */
......@@ -12,6 +12,7 @@ if (NOT EXISTS
)
endif()
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../kvdb/include)
find_library(MKLML_LIBS NAMES libmklml_intel.so libiomp5.so)
include(op/CMakeLists.txt)
include(proto/CMakeLists.txt)
......@@ -31,8 +32,8 @@ if(WITH_GPU)
endif()
target_link_libraries(serving opencv_imgcodecs
${opencv_depend_libs} -Wl,--whole-archive fluid_cpu_engine
-Wl,--no-whole-archive pdserving paddle_fluid ${paddle_depend_libs}
${MKLML_LIB} ${MKLML_IOMP_LIB} -lpthread -lcrypto -lm -lrt -lssl -ldl -lz)
-Wl,--no-whole-archive pdserving paddle_fluid ${paddle_depend_libs} rocksdb_impl rocksdb
${MKLML_LIB} ${MKLML_IOMP_LIB} -lpthread -lcrypto -lm -lrt -lssl -ldl -lz -lbz2)
install(TARGETS serving
RUNTIME DESTINATION
......
......@@ -27,3 +27,7 @@ services {
workflows: "workflow6"
}
services {
name: "EchoKVDBService"
workflows: "workflow7"
}
......@@ -67,4 +67,11 @@ workflows {
type: "TextClassificationOp"
}
}
workflows {
name: "workflow7"
workflow_type: "Sequence"
nodes {
name: "echo_kvdb_service_op"
type: "KVDBEchoOp"
}
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "demo-serving/op/kvdb_echo_op.h"
namespace baidu {
namespace paddle_serving {
namespace predictor {
using baidu::paddle_serving::predictor::format::KVDBReq;
using baidu::paddle_serving::predictor::format::KVDBRes;
using baidu::paddle_serving::predictor::echo_kvdb_service::Request;
using baidu::paddle_serving::predictor::echo_kvdb_service::Response;
std::shared_ptr<RocksDBWrapper> KVDBEchoOp::db;
int KVDBEchoOp::inference() {
debug();
}
int KVDBEchoOp::debug() {
//TODO: implement DEBUG mode
this->DBInit();
const Request* req = dynamic_cast<const Request*>(get_request_message());
Response* res = mutable_data<Response>();
LOG(INFO) << "Receive request in KVDB echo service: " << req->ShortDebugString();
for(size_t i = 0; i < req->reqs_size(); i++) {
auto kvdbreq = req->reqs(i);
std::string op = kvdbreq.op();
std::string key = kvdbreq.key();
std::string val = kvdbreq.value();
if(op == "SET") {
db->Put(key, val);
KVDBRes* kvdb_value_res = res->mutable_ress()->Add();
kvdb_value_res -> set_value("OK");
} else if(op == "GET") {
std::string getvalue = db->Get(key);
KVDBRes* kvdb_value_res = res->mutable_ress()->Add();
kvdb_value_res -> set_value(getvalue);
}
}
return 0;
}
void KVDBEchoOp::DBInit() {
if(db.get() == nullptr) {
db = RocksDBWrapper::RocksDBWrapperFactory("kvdb");
}
}
DEFINE_OP(KVDBEchoOp);
}
}
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "demo-serving/echo_kvdb_service.pb.h"
#include "predictor/common/inner_common.h"
#include "predictor/framework/channel.h"
#include "predictor/framework/op_repository.h"
#include "predictor/op/op.h"
#include "kvdb/paddle_rocksdb.h"
namespace baidu {
namespace paddle_serving {
namespace predictor {
class KVDBEchoOp: public OpWithChannel<baidu::paddle_serving::predictor::echo_kvdb_service::Response> {
public:
DECLARE_OP(KVDBEchoOp);
int inference();
int debug();
protected:
static std::shared_ptr<RocksDBWrapper> db;
void DBInit();
};
} // namespace predictor
} // namespace paddle_serving
} // namespace baidu
......@@ -3,6 +3,7 @@ LIST(APPEND protofiles
${CMAKE_CURRENT_LIST_DIR}/dense_service.proto
${CMAKE_CURRENT_LIST_DIR}/sparse_service.proto
${CMAKE_CURRENT_LIST_DIR}/echo_service.proto
${CMAKE_CURRENT_LIST_DIR}/echo_kvdb_service.proto
${CMAKE_CURRENT_LIST_DIR}/int64tensor_service.proto
${CMAKE_CURRENT_LIST_DIR}/text_classification.proto
)
......
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto2";
import "pds_option.proto";
import "builtin_format.proto";
package baidu.paddle_serving.predictor.echo_kvdb_service;
option cc_generic_services = true;
message Request {
repeated baidu.paddle_serving.predictor.format.KVDBReq reqs = 1;
};
message Response {
repeated baidu.paddle_serving.predictor.format.KVDBRes ress = 1;
};
service EchoKVDBService {
rpc inference(Request) returns (Response);
rpc debug(Request) returns (Response);
option (pds.options).generate_impl = true;
};
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/gtest-1.7.0/fused-src
${CMAKE_CURRENT_LIST_DIR}/include)
add_subdirectory(./gtest-1.7.0/fused-src/gtest)
set(SRC_LIST ${CMAKE_CURRENT_LIST_DIR}/src/test_rocksdb.cpp
${CMAKE_CURRENT_LIST_DIR}/src/rockskvdb_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/param_dict_mgr_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/mock_param_dict_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/paddle_rocksdb.cpp
${CMAKE_CURRENT_LIST_DIR}/src/gtest_kvdb.cpp)
add_library(rocksdb_impl ${SRC_LIST})
install(TARGETS rocksdb_impl ARCHIVE DESTINATION ${PADDLE_SERVING_INSTALL_DIR}/lib/)
add_executable(kvdb_test ${SRC_LIST})
add_dependencies(kvdb_test rocksdb)
target_link_libraries(kvdb_test rocksdb bz2 snappy zlib gtest)
#target_include_directories(kvdb_test PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/kvdb)
set(SRC_LIST2 ${CMAKE_CURRENT_LIST_DIR}/src/gtest_db_thread.cpp
${CMAKE_CURRENT_LIST_DIR}/src/rockskvdb_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/param_dict_mgr_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/mock_param_dict_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/paddle_rocksdb.cpp)
add_executable(db_thread ${SRC_LIST2})
add_dependencies(db_thread rocksdb)
target_link_libraries(db_thread rocksdb bz2 snappy zlib gtest)
#target_include_directories(db_thread PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/kvdb)
set(SRC_LIST3 ${CMAKE_CURRENT_LIST_DIR}/src/gtest_db_func.cpp
${CMAKE_CURRENT_LIST_DIR}/src/rockskvdb_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/param_dict_mgr_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/mock_param_dict_impl.cpp
${CMAKE_CURRENT_LIST_DIR}/src/paddle_rocksdb.cpp)
add_executable(db_func ${SRC_LIST3})
add_dependencies(db_func rocksdb)
target_link_libraries(db_func rocksdb bz2 snappy zlib gtest)
#target_include_directories(db_func PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/kvdb)
install(TARGETS kvdb_test
RUNTIME DESTINATION ${PADDLE_SERVING_INSTALL_DIR}/demo/kvdb_test)
install(TARGETS db_thread
RUNTIME DESTINATION ${PADDLE_SERVING_INSTALL_DIR}/demo/db_thread)
install(TARGETS db_func
RUNTIME DESTINATION ${PADDLE_SERVING_INSTALL_DIR}/demo/db_func)
file(GLOB kvdb_headers "${CMAKE_CURRENT_LIST_DIR}/include/kvdb/*.h")
install(FILES ${kvdb_headers} DESTINATION
${PADDLE_SERVING_INSTALL_DIR}/include/kvdb/)
此差异已折叠。
third-party/gtest-1.7.0/fused-src/gtest/gtest-all.cc.d \
third-party/gtest-1.7.0/fused-src/gtest/gtest-all.o: \
third-party/gtest-1.7.0/fused-src/gtest/gtest-all.cc
此差异已折叠。
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <vector>
#include <unordered_map>
#include <memory>
#include <chrono>
class AbstractKVDB;
class AbstractDictReader;
class AbstractParamDict;
typedef std::shared_ptr<AbstractKVDB> AbsKVDBPtr;
typedef std::shared_ptr<AbstractDictReader> AbsDictReaderPtr;
typedef std::shared_ptr<AbstractParamDict> AbsParamDictPtr;
class AbstractKVDB {
public:
virtual void CreateDB() = 0;
virtual void SetDBName(std::string) = 0;
virtual void Set(std::string key, std::string value) = 0;
virtual std::string Get(std::string key) = 0;
virtual ~AbstractKVDB() = 0;
};
// TODO: Implement RedisKVDB
//class RedisKVDB;
class AbstractDictReader {
public:
virtual std::string GetFileName() = 0;
virtual void SetFileName(std::string) = 0;
virtual std::string GetMD5() = 0;
virtual bool CheckDiff() = 0;
virtual std::chrono::system_clock::time_point GetTimeStamp() = 0;
virtual void Read(std::vector<std::string>&) = 0;
virtual ~AbstractDictReader() = 0;
protected:
std::string filename_;
std::string last_md5_val_;
std::chrono::system_clock::time_point time_stamp_;
};
class AbstractParamDict {
public:
virtual std::vector<AbsDictReaderPtr> GetDictReaderLst() = 0;
virtual void SetDictReaderLst(std::vector<AbsDictReaderPtr>) = 0;
virtual std::vector<float> GetSparseValue(int64_t, int64_t) = 0;
virtual std::vector<float> GetSparseValue(std::string, std::string) = 0;
virtual bool InsertSparseValue(int64_t, int64_t, const std::vector<float>&) = 0;
virtual bool InsertSparseValue(std::string, std::string, const std::vector<float>&) = 0;
virtual void UpdateBaseModel() = 0;
virtual void UpdateDeltaModel() = 0;
virtual std::pair<AbsKVDBPtr, AbsKVDBPtr> GetKVDB() = 0;
virtual void SetKVDB(std::pair<AbsKVDBPtr, AbsKVDBPtr>) = 0;
virtual void CreateKVDB() = 0;
virtual ~AbstractParamDict() = 0;
protected:
std::vector<AbsDictReaderPtr> dict_reader_lst_;
AbsKVDBPtr front_db, back_db;
};
class ParamDictMgr {
public:
void UpdateAll();
void InsertParamDict(std::string, AbsParamDictPtr);
protected:
std::unordered_map<std::string, AbsParamDictPtr> ParamDictMap;
};
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb_impl.h"
#include "paddle_rocksdb.h"
class RocksKVDB: public AbstractKVDB {
public:
void CreateDB();
void SetDBName(std::string);
void Set(std::string key, std::string value);
std::string Get(std::string key);
~RocksKVDB();
protected:
std::shared_ptr<RocksDBWrapper> db_;
public:
static int db_count;
};
class MockDictReader : public AbstractDictReader{
public:
std::string GetFileName();
void SetFileName(std::string);
std::string GetMD5();
bool CheckDiff();
std::chrono::system_clock::time_point GetTimeStamp();
void Read(std::vector<std::string>&);
~MockDictReader();
};
class MockParamDict : public AbstractParamDict{
public:
std::vector<AbsDictReaderPtr> GetDictReaderLst();
void SetDictReaderLst(std::vector<AbsDictReaderPtr>);
std::vector<float> GetSparseValue(int64_t, int64_t);
std::vector<float> GetSparseValue(std::string, std::string);
bool InsertSparseValue(int64_t, int64_t, const std::vector<float>&);
bool InsertSparseValue(std::string, std::string, const std::vector<float>&);
void UpdateBaseModel();
void UpdateDeltaModel();
std::pair<AbsKVDBPtr, AbsKVDBPtr> GetKVDB();
void SetKVDB(std::pair<AbsKVDBPtr, AbsKVDBPtr>);
void CreateKVDB();
~MockParamDict();
};
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <memory>
#include <string>
#include "rocksdb/db.h"
#include "rocksdb/options.h"
#include "rocksdb/slice.h"
#include "rocksdb/sst_file_writer.h"
#include "rocksdb/table.h"
#include "rocksdb/compaction_filter.h"
#include "rocksdb/filter_policy.h"
class RocksDBWrapper {
public:
RocksDBWrapper(std::string db_name);
std::string Get(std::string key);
bool Put(std::string key, std::string value);
void SetDBName(std::string db_name);
static std::shared_ptr<RocksDBWrapper> RocksDBWrapperFactory(std::string db_name = "SparseMatrix");
protected:
rocksdb::DB *db_;
std::string db_name_;
};
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/mock_kvdb_impl.h"
#include "kvdb/kvdb_impl.h"
#include "kvdb/paddle_rocksdb.h"
#include <gtest/gtest.h>
#include <string>
#include <fstream>
#include <sstream>
#include <chrono>
#include <thread>
class KVDBTest : public ::testing::Test {
protected:
void SetUp() override{
}
static void SetUpTestCase() {
}
};
int my_argc;
char** my_argv;
std::vector<std::string> StringSplit(std::string str, char split) {
std::vector<std::string> strs;
std::istringstream f(str);
std:: string s;
while(getline(f, s, split)) {
strs.push_back(s);
}
return strs;
}
TEST_F(KVDBTest, AbstractKVDB_Func_Test) {
AbsKVDBPtr kvdb = std::make_shared<RocksKVDB>();
kvdb->CreateDB();
std::string set_list = "setlist.txt";
std::string get_list = "getlist.txt";
std::ifstream set_file(set_list);
std::ifstream get_file(get_list);
for( std::string line; getline(set_file, line ); )
{
std::vector<std::string> strs = StringSplit (line, ' ');
kvdb->Set(strs[0], strs[1]);
}
for( std::string line; getline(set_file, line ); ) {
std::vector<std::string> strs = StringSplit(line, ' ');
std::string val = kvdb->Get(strs[0]);
ASSERT_EQ(val, strs[1]);
}
}
int main(int argc, char** argv) {
my_argc = argc;
my_argv = argv;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/mock_kvdb_impl.h"
#include "kvdb/kvdb_impl.h"
#include "kvdb/paddle_rocksdb.h"
#include <gtest/gtest.h>
#include <string>
#include <fstream>
#include <chrono>
#include <thread>
class KVDBTest : public ::testing::Test {
protected:
void SetUp() override{
}
static void SetUpTestCase() {
}
};
int my_argc;
char** my_argv;
void db_thread_test(AbsKVDBPtr kvdb, int size) {
for(int i = 0; i < size; i++) {
kvdb->Set(std::to_string(i), std::to_string(i));
kvdb->Get(std::to_string(i));
}
}
TEST_F(KVDBTest, AbstractKVDB_Thread_Test) {
if(my_argc != 3) {
std::cerr << "illegal input! should be db_thread ${num_of_thread} ${num_of_ops_each_thread}" << std::endl;
return;
}
int num_of_thread = atoi(my_argv[1]);
int nums_of_ops_each_thread = atoi(my_argv[2]);
std::vector<AbsKVDBPtr> kvdbptrs;
for(int i= 0; i < num_of_thread; i++) {
kvdbptrs.push_back(std::make_shared<RocksKVDB>());
kvdbptrs[i]->CreateDB();
}
std::vector<std::thread> tarr;
for(int i = 0; i< num_of_thread; i++) {
tarr.push_back(std::thread(db_thread_test, kvdbptrs[i], nums_of_ops_each_thread));
}
for(int i = 0; i< num_of_thread; i++) {
tarr[i].join();
}
return;
}
int main(int argc, char** argv) {
my_argc = argc;
my_argv = argv;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/mock_kvdb_impl.h"
#include "kvdb/kvdb_impl.h"
#include "kvdb/paddle_rocksdb.h"
#include <gtest/gtest.h>
#include <string>
#include <fstream>
#include <chrono>
#include <thread>
class KVDBTest : public ::testing::Test {
protected:
void SetUp() override{
}
static void SetUpTestCase() {
kvdb = std::make_shared<RocksKVDB>();
dict_reader = std::make_shared<MockDictReader>();
param_dict = std::make_shared<MockParamDict>();
}
static AbsKVDBPtr kvdb;
static AbsDictReaderPtr dict_reader;
static AbsParamDictPtr param_dict;
static ParamDictMgr dict_mgr;
};
AbsKVDBPtr KVDBTest::kvdb;
AbsDictReaderPtr KVDBTest::dict_reader;
AbsParamDictPtr KVDBTest::param_dict;
ParamDictMgr KVDBTest::dict_mgr;
void GenerateTestIn(std::string);
void UpdateTestIn(std::string);
TEST_F(KVDBTest, AbstractKVDB_Unit_Test) {
kvdb->CreateDB();
kvdb->SetDBName("test_kvdb");
for(int i = 0; i < 100; i++) {
kvdb->Set(std::to_string(i), std::to_string(i * 2));
}
for(int i = 0; i < 100; i++) {
std::string val = kvdb->Get(std::to_string(i));
ASSERT_EQ(val, std::to_string(i * 2));
}
}
TEST_F(KVDBTest, AbstractDictReader_Unit_Test) {
std::string test_in_filename = "abs_dict_reader_test_in.txt";
GenerateTestIn(test_in_filename);
dict_reader->SetFileName(test_in_filename);
std::string md5_1 = dict_reader->GetMD5();
std::chrono::system_clock::time_point timestamp_1 = dict_reader->GetTimeStamp();
std::string md5_2 = dict_reader->GetMD5();
std::chrono::system_clock::time_point timestamp_2 = dict_reader->GetTimeStamp();
ASSERT_EQ(md5_1, md5_2);
ASSERT_EQ(timestamp_1, timestamp_2);
UpdateTestIn(test_in_filename);
std::string md5_3 = dict_reader->GetMD5();
std::chrono::system_clock::time_point timestamp_3 = dict_reader->GetTimeStamp();
ASSERT_NE(md5_2, md5_3);
ASSERT_NE(timestamp_2, timestamp_3);
}
#include <cmath>
TEST_F(KVDBTest, MockParamDict_Unit_Test) {
std::string test_in_filename = "abs_dict_reader_test_in.txt";
param_dict->SetDictReaderLst({dict_reader});
param_dict->CreateKVDB();
GenerateTestIn(test_in_filename);
param_dict->UpdateBaseModel();
std::this_thread::sleep_for(std::chrono::seconds(2));
std::vector<float> test_vec = param_dict->GetSparseValue(1, 1);
ASSERT_LT(fabs(test_vec[0] - 1.0), 1e-2);
UpdateTestIn(test_in_filename);
param_dict->UpdateDeltaModel();
}
void GenerateTestIn(std::string filename) {
std::ifstream in_file(filename);
if(in_file.good()) {
in_file.close();
std::string cmd = "rm -rf "+ filename;
system(cmd.c_str());
}
std::ofstream out_file(filename);
for(size_t i = 0; i < 100000; i++) {
out_file << i << " " << i << " ";
for(size_t j = 0; j < 3; j++) {
out_file << i << " ";
}
out_file << std::endl;
}
out_file.close();
}
void UpdateTestIn(std::string filename) {
std::ifstream in_file(filename);
if(in_file.good()) {
in_file.close();
std::string cmd = "rm -rf " + filename;
system(cmd.c_str());
}
std::ofstream out_file(filename);
for(size_t i = 0; i < 10000; i++) {
out_file << i << " " << i << " ";
for(size_t j = 0; j < 3; j++) {
out_file << i + 1 << " ";
}
out_file << std::endl;
}
out_file.close();
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/mock_kvdb_impl.h"
#include <thread>
#include <iterator>
#include <fstream>
#include <sstream>
std::string MockDictReader::GetFileName() {
return this->filename_;
}
void MockDictReader::SetFileName(std::string filename) {
this->filename_ = filename;
this->last_md5_val_ = this->GetMD5();
this->time_stamp_ = std::chrono::system_clock::now();
}
std::string MockDictReader::GetMD5() {
auto getCmdOut = [] (std::string cmd) {
std::string data;
FILE *stream;
const int max_buffer = 256;
char buffer[max_buffer];
cmd.append(" 2>&1");
stream = popen(cmd.c_str(), "r");
if(stream) {
if(fgets(buffer, max_buffer, stream) != NULL) {
data.append(buffer);
}
}
return data;
};
std::string cmd = "md5sum " + this->filename_;
//TODO: throw exception if error occurs during execution of shell command
std::string md5val = getCmdOut(cmd);
this->time_stamp_ = md5val == this->last_md5_val_? this->time_stamp_: std::chrono::system_clock::now();
this->last_md5_val_ = md5val;
return md5val;
}
bool MockDictReader::CheckDiff() {
return this->GetMD5() == this->last_md5_val_;
}
std::chrono::system_clock::time_point MockDictReader::GetTimeStamp() {
//TODO: Implement Get Time Stamp of dict file
return this->time_stamp_;
}
void MockDictReader::Read(std::vector<std::string>& res) {
std::string line;
std::ifstream infile(this->filename_);
if(infile.is_open()) {
while(getline(infile, line)) {
res.push_back(line);
}
}
infile.close();
}
MockDictReader::~MockDictReader() {
//TODO: I imageine nothing to do here
}
std::vector<AbsDictReaderPtr> MockParamDict::GetDictReaderLst() {
return this->dict_reader_lst_;
}
void MockParamDict::SetDictReaderLst(std::vector<AbsDictReaderPtr> lst) {
this->dict_reader_lst_ = lst;
}
std::vector<float> MockParamDict::GetSparseValue(std::string feasign, std::string slot) {
auto BytesToFloat = [](uint8_t* byteArray){
return *((float*)byteArray);
};
//TODO: the concatation of feasign and slot is TBD.
std::string result = front_db->Get(feasign + slot);
std::vector<float> value;
if(result == "NOT_FOUND")
return value;
uint8_t* raw_values_ptr = reinterpret_cast<uint8_t *>(&result[0]);
for(size_t i = 0; i < result.size(); i += 4) {
float temp = BytesToFloat(raw_values_ptr + i);
value.push_back(temp);
}
return value;
}
std::vector<float> MockParamDict::GetSparseValue(int64_t feasign, int64_t slot) {
return this->GetSparseValue(std::to_string(feasign), std::to_string(slot));
}
bool MockParamDict::InsertSparseValue(int64_t feasign, int64_t slot, const std::vector<float>& values) {
return this->InsertSparseValue(std::to_string(feasign), std::to_string(slot), values);
}
bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, const std::vector<float>& values) {
auto FloatToBytes = [](float fvalue, uint8_t *arr){
unsigned char *pf;
unsigned char *px;
unsigned char i;
pf =(unsigned char *)&fvalue;
px = arr;
for(i=0;i<4;i++)
{
*(px+i)=*(pf+i);
}
};
std::string key = feasign + slot;
uint8_t* values_ptr = new uint8_t[values.size() * 4];
std::string value;
for(size_t i = 0; i < values.size(); i++) {
FloatToBytes(values[i], values_ptr + 4 * i);
}
char* raw_values_ptr = reinterpret_cast<char*>(values_ptr);
for(size_t i = 0; i < values.size()*4 ; i++) {
value.push_back(raw_values_ptr[i]);
}
back_db->Set(key, value);
//TODO: change stateless to stateful
return true;
}
void MockParamDict::UpdateBaseModel() {
std::thread t([&] () {
for(AbsDictReaderPtr dict_reader: this->dict_reader_lst_) {
if(dict_reader->CheckDiff()) {
std::vector<std::string> strs;
dict_reader->Read(strs);
for(const std::string& str: strs) {
std::vector<std::string> arr;
std::istringstream in(str);
copy(std::istream_iterator<std::string>(in), std::istream_iterator<std::string>(), back_inserter(arr));
std::vector<float> nums;
for(size_t i = 2; i < arr.size(); i++) {
nums.push_back(std::stof(arr[i]));
}
this->InsertSparseValue(arr[0], arr[1], nums);
}
}
}
AbsKVDBPtr temp = front_db;
front_db = back_db;
back_db = temp;
});
t.detach();
}
void MockParamDict::UpdateDeltaModel() {
UpdateBaseModel();
}
std::pair<AbsKVDBPtr, AbsKVDBPtr> MockParamDict::GetKVDB() {
return {front_db, back_db};
}
void MockParamDict::SetKVDB(std::pair<AbsKVDBPtr, AbsKVDBPtr> kvdbs) {
this->front_db = kvdbs.first;
this->back_db = kvdbs.second;
}
void MockParamDict::CreateKVDB() {
this->front_db = std::make_shared<RocksKVDB>();
this->back_db = std::make_shared<RocksKVDB>();
this->front_db->CreateDB();
this->back_db->CreateDB();
}
MockParamDict::~MockParamDict() {
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/paddle_rocksdb.h"
RocksDBWrapper::RocksDBWrapper(std::string db_name) {
rocksdb::Options options;
options.create_if_missing = true;
db_name_ = db_name;
db_ = nullptr;
rocksdb::Status s = rocksdb::DB::Open(options, db_name, &db_);
return;
}
std::string RocksDBWrapper::Get(std::string key) {
rocksdb::ReadOptions options;
options.verify_checksums = true;
std::string result;
rocksdb::Status s = db_->Get(options, key, &result);
if(s.IsNotFound()) {
result = "NOT_FOUND";
}
return result;
}
bool RocksDBWrapper::Put(std::string key, std::string value) {
rocksdb::WriteOptions options;
rocksdb::Status s = db_->Put(options, key, value);
if(s.ok()) {
return true;
} else {
return false;
}
}
void RocksDBWrapper::SetDBName(std::string db_name) {
this->db_name_ = db_name;
}
std::shared_ptr<RocksDBWrapper> RocksDBWrapper::RocksDBWrapperFactory(std::string db_name) {
return std::make_shared<RocksDBWrapper>(db_name);
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/kvdb_impl.h"
void ParamDictMgr::UpdateAll() {
for(auto it = this->ParamDictMap.begin(); it!= this->ParamDictMap.end(); ++it) {
it->second->UpdateBaseModel();
}
}
void ParamDictMgr::InsertParamDict(std::string key, AbsParamDictPtr value) {
this->ParamDictMap.insert(std::make_pair(key, value));
}
AbstractKVDB::~AbstractKVDB() {}
AbstractDictReader::~AbstractDictReader() {}
AbstractParamDict::~AbstractParamDict() {}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/mock_kvdb_impl.h"
int RocksKVDB::db_count;
void RocksKVDB::CreateDB() {
this->db_ = RocksDBWrapper::RocksDBWrapperFactory("RocksDB_" + std::to_string(RocksKVDB::db_count));
RocksKVDB::db_count ++;
return;
}
void RocksKVDB::SetDBName(std::string db_name) {
this->db_->SetDBName(db_name);
return;
}
void RocksKVDB::Set(std::string key, std::string value) {
this->db_->Put(key, value);
return;
}
std::string RocksKVDB::Get(std::string key) {
return this->db_->Get(key);
}
RocksKVDB::~RocksKVDB() {
}
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "kvdb/mock_kvdb_impl.h"
#include "kvdb/paddle_rocksdb.h"
#include <iostream>
void test_rockskvdb() {
RocksKVDB db;
db.CreateDB();
db.SetDBName("Sparse Matrix");
db.Set("1", "One");
std::cout << db.Get("1") << std::endl;
return ;
}
void test_rocksdbwrapper() {
std::shared_ptr<RocksDBWrapper> db = RocksDBWrapper::RocksDBWrapperFactory("TEST");
for(size_t i = 0; i < 1000; i++) {
db->Put(std::to_string(i), std::to_string(i * 2));
}
for(size_t i = 0; i < 1000; i++) {
std::string res = db->Get(std::to_string(i));
std::cout << res << " ";
}
std::cout << std::endl;
}
#ifdef RAW_TEST
int main() {
test_rockskvdb();
test_rocksdbwrapper();
}
#endif
workflow_type: Sequence
[@Node]
name: echo_kvdb_op
type: KVDBEchoOp
......@@ -15,6 +15,19 @@
syntax = "proto2";
package baidu.paddle_serving.predictor.format;
// echo kvdb formant
message KVDBReq {
required string op = 1;
required string key = 2;
optional string value = 3;
};
message KVDBRes{
required string value = 2;
};
// dense format
message DenseInstance { repeated float features = 1; };
......
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto2";
import "pds_option.proto";
import "builtin_format.proto";
package baidu.paddle_serving.predictor.echo_kvdb_service;
option cc_generic_services = true;
message Request {
repeated baidu.paddle_serving.predictor.format.KVDBReq reqs = 1;
};
message Response {
repeated baidu.paddle_serving.predictor.format.KVDBRes ress = 1;
};
service EchoKVDBService {
rpc inference(Request) returns (Response);
rpc debug(Request) returns (Response);
option (pds.options).generate_stub = true;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册