From 8d60b2ca52691732aba6372e4da673864125f236 Mon Sep 17 00:00:00 2001 From: MRXLT Date: Tue, 7 Jul 2020 19:31:56 +0800 Subject: [PATCH] add cube benchmark script --- core/cube/cube-api/src/cube_cli.cpp | 8 +++-- .../criteo_ctr_with_cube/benchmark_cube.sh | 31 +++++++++++++++++++ .../examples/criteo_ctr_with_cube/gen_key.py | 20 ++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 python/examples/criteo_ctr_with_cube/benchmark_cube.sh create mode 100644 python/examples/criteo_ctr_with_cube/gen_key.py diff --git a/core/cube/cube-api/src/cube_cli.cpp b/core/cube/cube-api/src/cube_cli.cpp index eee4b0c3..19e77c90 100644 --- a/core/cube/cube-api/src/cube_cli.cpp +++ b/core/cube/cube-api/src/cube_cli.cpp @@ -188,6 +188,7 @@ int run_m(int argc, char** argv) { request_list.resize(thread_num); time_list.resize(thread_num); std::vector thread_pool; + TIME_FLAG(main_start); for (int i = 0; i < thread_num; i++) { thread_pool.push_back(new std::thread(run, argc, argv, i)); } @@ -195,6 +196,7 @@ int run_m(int argc, char** argv) { thread_pool[i]->join(); delete thread_pool[i]; } + TIME_FLAG(main_end); uint64_t sum_time = 0; uint64_t max_time = 0; uint64_t min_time = 1000000; @@ -210,12 +212,14 @@ int run_m(int argc, char** argv) { request_num += request_list[i]; } uint64_t mean_time = sum_time / thread_num; + uint64_t main_time = time_diff(main_start, main_end); LOG(INFO) << thread_num << " thread seek cost" << " avg = " << std::to_string(mean_time) << " max = " << std::to_string(max_time) << " min = " << std::to_string(min_time); - LOG(INFO) << " total_request = " << std::to_string(request_num) << " speed = " - << std::to_string(1000000 * thread_num / mean_time) // mean_time us + LOG(INFO) << " total_request = " << std::to_string(request_num) + << " speed = " << std::to_string(request_num * 1000000 / + main_time) // mean_time us << " query per second"; return 0; } diff --git a/python/examples/criteo_ctr_with_cube/benchmark_cube.sh b/python/examples/criteo_ctr_with_cube/benchmark_cube.sh new file mode 100755 index 00000000..aaf1dcce --- /dev/null +++ b/python/examples/criteo_ctr_with_cube/benchmark_cube.sh @@ -0,0 +1,31 @@ +rm profile_log + +#wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz --no-check-certificate +tar xf ctr_cube_unittest.tar.gz +mv models/ctr_client_conf ./ +mv models/ctr_serving_model_kv ./ +mv models/data ./cube/ + +#wget https://paddle-serving.bj.bcebos.com/others/cube_app.tar.gz --no-check-certificate +tar xf cube_app.tar.gz +mv cube_app/cube* ./cube/ +sh cube_prepare.sh & + +cp ../../../build_server/core/cube/cube-api/cube-cli . +python gen_key.py + +for thread_num in 1 +do +for batch_size in 1 +do + ./cube-cli -config_file ./cube/conf/cube.conf -keys key -dict test_dict -thread_num $thread_num --batch $batch_size > profile 2>&1 + echo "batch size : $batch_size" + echo "thread num : $thread_num" + echo "========================================" + echo "batch size : $batch_size" >> profile_log + echo "thread num : $thread_num" >> profile_log + tail -n 2 profile >> profile_log +done +done + +ps -ef|grep 'cube'|grep -v grep|cut -c 9-15 | xargs kill -9 diff --git a/python/examples/criteo_ctr_with_cube/gen_key.py b/python/examples/criteo_ctr_with_cube/gen_key.py new file mode 100644 index 00000000..115d8170 --- /dev/null +++ b/python/examples/criteo_ctr_with_cube/gen_key.py @@ -0,0 +1,20 @@ +# Copyright (c) 2020 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. + +import sys +import random + +with open("key", "w") as f: + for i in range(1000000): + f.write("{}\n".format(random.randint(0, 999999))) -- GitLab