提交 69415612 编写于 作者: W wangguibao

CTR prediction profiling

上级 0f3bd087
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
#include "predictor/framework/kv_manager.h" #include "predictor/framework/kv_manager.h"
#include "predictor/framework/memory.h" #include "predictor/framework/memory.h"
// Flag where enable profiling mode
DECLARE_bool(enable_ctr_profiling);
namespace baidu { namespace baidu {
namespace paddle_serving { namespace paddle_serving {
namespace serving { namespace serving {
...@@ -46,6 +49,11 @@ const int CTR_PREDICTION_DENSE_SLOT_ID = 26; ...@@ -46,6 +49,11 @@ const int CTR_PREDICTION_DENSE_SLOT_ID = 26;
const int CTR_PREDICTION_DENSE_DIM = 13; const int CTR_PREDICTION_DENSE_DIM = 13;
const int CTR_PREDICTION_EMBEDDING_SIZE = 10; const int CTR_PREDICTION_EMBEDDING_SIZE = 10;
bthread::Mutex CTRPredictionOp::mutex_;
int64_t CTRPredictionOp::cube_time_us_ = 0;
int32_t CTRPredictionOp::cube_req_num_ = 0;
int32_t CTRPredictionOp::cube_req_key_num_ = 0;
void fill_response_with_message(Response *response, void fill_response_with_message(Response *response,
int err_code, int err_code,
std::string err_msg) { std::string err_msg) {
...@@ -135,7 +143,28 @@ int CTRPredictionOp::inference() { ...@@ -135,7 +143,28 @@ int CTRPredictionOp::inference() {
return 0; return 0;
} else if (kvinfo->sparse_param_service_type == } else if (kvinfo->sparse_param_service_type ==
configure::EngineDesc::REMOTE) { configure::EngineDesc::REMOTE) {
int ret = cube->seek(table_name, keys, &values); struct timeval start;
struct timeval end;
int ret;
if (FLAGS_enable_ctr_profiling) {
gettimeofday(&start, NULL);
ret = cube->seek(table_name, keys, &values);
gettimeofday(&end, NULL);
uint64_t usec =
end.tv_sec * 1e6 + end.tv_usec - start.tv_sec * 1e6 - start.tv_usec;
// Statistics
mutex_.lock();
cube_time_us_ += usec;
++cube_req_num_;
cube_req_key_num_ += keys.size();
mutex_.unlock();
} else {
ret = cube->seek(table_name, keys, &values);
}
if (ret != 0) { if (ret != 0) {
fill_response_with_message(res, -1, "Query cube for embeddings error"); fill_response_with_message(res, -1, "Query cube for embeddings error");
LOG(ERROR) << "Query cube for embeddings error"; LOG(ERROR) << "Query cube for embeddings error";
......
...@@ -55,6 +55,7 @@ static const char* CTR_PREDICTION_MODEL_NAME = "ctr_prediction"; ...@@ -55,6 +55,7 @@ static const char* CTR_PREDICTION_MODEL_NAME = "ctr_prediction";
* and modifications we made * and modifications we made
* *
*/ */
class CTRPredictionOp class CTRPredictionOp
: public baidu::paddle_serving::predictor::OpWithChannel< : public baidu::paddle_serving::predictor::OpWithChannel<
baidu::paddle_serving::predictor::ctr_prediction::Response> { baidu::paddle_serving::predictor::ctr_prediction::Response> {
...@@ -64,6 +65,12 @@ class CTRPredictionOp ...@@ -64,6 +65,12 @@ class CTRPredictionOp
DECLARE_OP(CTRPredictionOp); DECLARE_OP(CTRPredictionOp);
int inference(); int inference();
private:
static bthread::Mutex mutex_;
static int64_t cube_time_us_;
static int32_t cube_req_num_;
static int32_t cube_req_key_num_;
}; };
} // namespace serving } // namespace serving
......
...@@ -40,8 +40,6 @@ DECLARE_int32(reload_interval_s); ...@@ -40,8 +40,6 @@ DECLARE_int32(reload_interval_s);
DECLARE_bool(enable_model_toolkit); DECLARE_bool(enable_model_toolkit);
DECLARE_string(enable_protocol_list); DECLARE_string(enable_protocol_list);
DECLARE_bool(enable_cube); DECLARE_bool(enable_cube);
DECLARE_string(cube_config_path);
DECLARE_string(cube_config_file);
// STATIC Variables // STATIC Variables
extern const char* START_OP_NAME; extern const char* START_OP_NAME;
......
...@@ -69,6 +69,9 @@ static bvar::PassiveStatus<std::string> s_predictor_revision( ...@@ -69,6 +69,9 @@ static bvar::PassiveStatus<std::string> s_predictor_revision(
DEFINE_bool(V, false, "print version, bool"); DEFINE_bool(V, false, "print version, bool");
DEFINE_bool(g, false, "user defined gflag path"); DEFINE_bool(g, false, "user defined gflag path");
DEFINE_bool(enable_ctr_profiling,
false,
"Enable profiling in CTR prediction demo");
DECLARE_string(flagfile); DECLARE_string(flagfile);
namespace bthread { namespace bthread {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册