serving_build.sh 51.2 KB
Newer Older
G
guru4elephant 已提交
1
#!/usr/bin/env bash
M
fix ci  
MRXLT 已提交
2
set -x
3 4 5 6 7 8 9 10 11 12 13 14
function unsetproxy() {
    HTTP_PROXY_TEMP=$http_proxy
    HTTPS_PROXY_TEMP=$https_proxy
    unset http_proxy
    unset https_proxy
}

function setproxy() {
    export http_proxy=$HTTP_PROXY_TEMP
    export https_proxy=$HTTPS_PROXY_TEMP
}

G
guru4elephant 已提交
15 16 17 18 19
function init() {
    source /root/.bashrc
    set -v
    export PYTHONROOT=/usr
    cd Serving
B
barrierye 已提交
20
    export SERVING_WORKDIR=$PWD
D
dongdaxiang 已提交
21
    $PYTHONROOT/bin/python -m pip install -r python/requirements.txt
G
guru4elephant 已提交
22 23 24 25 26 27 28 29 30
}

function check_cmd() {
    eval $@
    if [ $? -ne 0 ]; then
        exit 1
    fi
}

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
function rerun() {
    if [ $# -ne 2 ]; then
        echo "usage: rerun command rerun-times"
        exit 1
    fi
    local command=$1
    local times=$2
    for((i=1;i<=${times};i++))
    do
        if [ ${i} != 1 ]; then
            echo "${i}-th run command: ${command}..."
        fi
        eval $command
        if [ $? -eq 0 ]; then
            return 0
        fi
        echo "${i}-th run(command: ${command}) failed."
    done
    exit 1
}

B
barrierye 已提交
52 53 54 55 56 57 58 59 60 61 62
function build_app() {
    local TYPE=$1
    local DIRNAME=build-app-$TYPE
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-app-$TYPE
    case $TYPE in
        CPU|GPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
                  -DAPP=ON ..
M
MRXLT 已提交
63
            rerun "make -j10 >/dev/null" 3 # due to some network reasons, compilation may fail
B
barrierye 已提交
64 65 66 67 68 69 70 71 72 73 74
            pip install -U python/dist/paddle_serving_app* >/dev/null
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build app $TYPE part finished as expected."
    cd .. # pwd: /Serving
}

G
guru4elephant 已提交
75
function build_client() {
76
    local TYPE=$1
G
guru4elephant 已提交
77
    local DIRNAME=build-client-$TYPE
78 79
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-client-$TYPE
G
guru4elephant 已提交
80 81 82 83 84
    case $TYPE in
        CPU|GPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
85
                  -DCLIENT=ON ..
M
MRXLT 已提交
86
            rerun "make -j10 >/dev/null" 3 # due to some network reasons, compilation may fail
Y
Your Name 已提交
87
            pip install -U python/dist/paddle_serving_client* >/dev/null
G
guru4elephant 已提交
88 89 90 91 92 93 94
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build client $TYPE part finished as expected."
Y
Your Name 已提交
95
    cd .. # pwd: /Serving
96
    # rm -rf $DIRNAME
G
guru4elephant 已提交
97 98 99
}

function build_server() {
100
    local TYPE=$1
G
guru4elephant 已提交
101
    local DIRNAME=build-server-$TYPE
102 103
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-server-$TYPE
G
guru4elephant 已提交
104 105 106 107 108
    case $TYPE in
        CPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
G
guru4elephant 已提交
109
                  -DSERVER=ON ..
M
MRXLT 已提交
110
            rerun "make -j10 >/dev/null" 3 # due to some network reasons, compilation may fail
111
            check_cmd "make install -j2 >/dev/null"
Y
Your Name 已提交
112
            pip install -U python/dist/paddle_serving_server* >/dev/null
G
guru4elephant 已提交
113 114 115 116 117
            ;;
        GPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
118
                  -DSERVER=ON \
G
guru4elephant 已提交
119
                  -DWITH_GPU=ON ..
M
MRXLT 已提交
120
            rerun "make -j10 >/dev/null" 3 # due to some network reasons, compilation may fail
121
            check_cmd "make install -j2 >/dev/null"
Y
Your Name 已提交
122
            pip install -U python/dist/paddle_serving_server* >/dev/null
G
guru4elephant 已提交
123 124 125 126 127 128 129
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build server $TYPE part finished as expected."
Y
Your Name 已提交
130
    cd .. # pwd: /Serving
Y
Your Name 已提交
131
    # rm -rf $DIRNAME    for export SERVING_BIN
G
guru4elephant 已提交
132 133
}

134
function kill_server_process() {
Y
Your Name 已提交
135
    ps -ef | grep "serving" | grep -v serving_build | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
136
    sleep 1
137 138
}

B
barrierye 已提交
139
function kill_process_by_port() {
B
barrierye 已提交
140
    if [ $# != 1 ]; then
B
barrierye 已提交
141
        echo "usage: kill_process_by_port <PID>"
B
barrierye 已提交
142 143 144 145 146 147
        exit 1
    fi
    local PID=$1
    lsof -i:$PID | awk 'NR == 1 {next} {print $2}' | xargs kill
}

G
guru4elephant 已提交
148
function python_test_fit_a_line() {
Y
Your Name 已提交
149 150
    # pwd: /Serving/python/examples
    cd fit_a_line # pwd: /Serving/python/examples/fit_a_line
G
guru4elephant 已提交
151 152
    sh get_data.sh
    local TYPE=$1
B
barrierye 已提交
153
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
G
guru4elephant 已提交
154 155 156
    case $TYPE in
        CPU)
            # test rpc
157 158
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9393 --thread 4 > /dev/null &"
            sleep 5 # wait for the server to start
G
guru4elephant 已提交
159
            check_cmd "python test_client.py uci_housing_client/serving_client_conf.prototxt > /dev/null"
160
            kill_server_process
B
barrierye 已提交
161

G
guru4elephant 已提交
162
            # test web
163
            unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
164 165
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --name uci --port 9393 --thread 4 --name uci > /dev/null &"
            sleep 5 # wait for the server to start
M
MRXLT 已提交
166
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
167
            # check http code
M
fix ci  
MRXLT 已提交
168
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
Y
Your Name 已提交
169 170 171 172
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
B
barrierye 已提交
173 174 175 176 177 178 179 180 181 182
            # test web batch
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
            # check http code
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
            setproxy # recover proxy state
            kill_server_process
G
guru4elephant 已提交
183 184
            ;;
        GPU)
B
fix bug  
barrierye 已提交
185
            export CUDA_VISIBLE_DEVICES=0
186 187 188 189 190
            # test rpc
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9393 --thread 4 --gpu_ids 0 > /dev/null &"
            sleep 5 # wait for the server to start
            check_cmd "python test_client.py uci_housing_client/serving_client_conf.prototxt > /dev/null"
            kill_server_process
M
MRXLT 已提交
191

192
            # test web
J
Jiawei Wang 已提交
193
            #unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
D
dyning 已提交
194 195 196
            #check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9393 --thread 2 --gpu_ids 0 --name uci > /dev/null &"
            #sleep 5 # wait for the server to start
            #check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
197
            # check http code
D
dyning 已提交
198 199 200 201 202
            #http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
            #if [ ${http_code} -ne 200 ]; then
            #    echo "HTTP status code -ne 200"
            #    exit 1
            #fi
B
barrierye 已提交
203
            # test web batch
D
dyning 已提交
204
            #check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
B
barrierye 已提交
205
            # check http code
D
dyning 已提交
206 207 208 209 210
            #http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
            #if [ ${http_code} -ne 200 ]; then
            #    echo "HTTP status code -ne 200"
            #    exit 1
            #fi
J
Jiawei Wang 已提交
211
            #setproxy # recover proxy state
D
dyning 已提交
212
            #kill_server_process
G
guru4elephant 已提交
213 214 215 216 217 218 219 220
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test fit_a_line $TYPE part finished as expected."
    rm -rf image kvdb log uci_housing* work*
B
barrierye 已提交
221
    unset SERVING_BIN
Y
Your Name 已提交
222
    cd .. # pwd: /Serving/python/examples
G
guru4elephant 已提交
223 224
}

W
wangjiawei04 已提交
225
function python_run_criteo_ctr_with_cube() {
Y
merge  
Your Name 已提交
226
    # pwd: /Serving/python/examples
W
wangjiawei04 已提交
227
    local TYPE=$1
228
    yum install -y bc >/dev/null
Y
merge  
Your Name 已提交
229
    cd criteo_ctr_with_cube # pwd: /Serving/python/examples/criteo_ctr_with_cube
M
MRXLT 已提交
230
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
B
barrierye 已提交
231 232 233 234 235 236 237 238
    case $TYPE in
        CPU)
            check_cmd "wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz"
            check_cmd "tar xf ctr_cube_unittest.tar.gz"
            check_cmd "mv models/ctr_client_conf ./"
            check_cmd "mv models/ctr_serving_model_kv ./"
            check_cmd "mv models/data ./cube/"
            check_cmd "mv models/ut_data ./"
M
MRXLT 已提交
239
            cp ../../../build-server-$TYPE/output/bin/cube* ./cube/
B
barrierye 已提交
240 241
            sh cube_prepare.sh &
            python test_server.py ctr_serving_model_kv &
M
MRXLT 已提交
242
            sleep 5
B
barrierye 已提交
243
            check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score"
W
wangjiawei04 已提交
244
            tail -n 2 score | awk 'NR==1'
B
barrierye 已提交
245
            AUC=$(tail -n 2  score | awk 'NR==1')
246
            VAR2="0.67" #TODO: temporarily relax the threshold to 0.67
B
barrierye 已提交
247 248
            RES=$( echo "$AUC>$VAR2" | bc )
            if [[ $RES -eq 0 ]]; then
J
Jiawei Wang 已提交
249
                echo "error with criteo_ctr_with_cube inference auc test, auc should > 0.67"
B
barrierye 已提交
250 251 252
                exit 1
            fi
            echo "criteo_ctr_with_cube inference auc test success"
B
barrierye 已提交
253
            kill_server_process
B
barrierye 已提交
254
            ps -ef | grep "cube" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
255
            sleep 1
B
barrierye 已提交
256 257
            ;;
        GPU)
W
wangjiawei04 已提交
258 259 260 261 262 263 264 265 266
            check_cmd "wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz"
            check_cmd "tar xf ctr_cube_unittest.tar.gz"
            check_cmd "mv models/ctr_client_conf ./"
            check_cmd "mv models/ctr_serving_model_kv ./"
            check_cmd "mv models/data ./cube/"
            check_cmd "mv models/ut_data ./"
            cp ../../../build-server-$TYPE/output/bin/cube* ./cube/
            sh cube_prepare.sh &
            python test_server_gpu.py ctr_serving_model_kv &
M
MRXLT 已提交
267
            sleep 5
B
barrierye 已提交
268
            # for warm up
B
barrierye 已提交
269
            python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data > /dev/null || true
W
wangjiawei04 已提交
270 271 272
            check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score"
            tail -n 2 score | awk 'NR==1'
            AUC=$(tail -n 2  score | awk 'NR==1')
J
Jiawei Wang 已提交
273
            VAR2="0.67" #TODO: temporarily relax the threshold to 0.67
W
wangjiawei04 已提交
274 275
            RES=$( echo "$AUC>$VAR2" | bc )
            if [[ $RES -eq 0 ]]; then
J
Jiawei Wang 已提交
276
                echo "error with criteo_ctr_with_cube inference auc test, auc should > 0.67"
W
wangjiawei04 已提交
277 278 279
                exit 1
            fi
            echo "criteo_ctr_with_cube inference auc test success"
B
barrierye 已提交
280
            kill_server_process
W
wangjiawei04 已提交
281
            ps -ef | grep "cube" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
282
            sleep 1
B
barrierye 已提交
283 284 285 286 287 288
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
M
MRXLT 已提交
289
    unset SERVING_BIN
B
barrierye 已提交
290
    echo "test criteo_ctr_with_cube $TYPE part finished as expected."
Y
merge  
Your Name 已提交
291
    cd .. # pwd: /Serving/python/examples
W
wangjiawei04 已提交
292 293
}

W
wangjiawei04 已提交
294 295 296
function python_test_bert() {
    # pwd: /Serving/python/examples
    local TYPE=$1
297
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
W
wangjiawei04 已提交
298 299 300 301
    cd bert # pwd: /Serving/python/examples/bert
    case $TYPE in
        CPU)
            pip install paddlehub
302 303 304 305
            # Because download from paddlehub may timeout,
            # download the model from bos(max_seq_len=128).
            wget https://paddle-serving.bj.bcebos.com/paddle_hub_models/text/SemanticModel/bert_chinese_L-12_H-768_A-12.tar.gz
            tar -xzf bert_chinese_L-12_H-768_A-12.tar.gz
W
wangjiawei04 已提交
306
            sh get_data.sh
307
            check_cmd "python -m paddle_serving_server.serve --model bert_chinese_L-12_H-768_A-12_model --port 9292 &"
308
            sleep 5
W
wangjiawei04 已提交
309
            pip install paddle_serving_app
310
            check_cmd "head -n 10 data-c.txt | python bert_client.py --model bert_chinese_L-12_H-768_A-12_client/serving_client_conf.prototxt"
J
Jiawei Wang 已提交
311
            kill_server_process
M
MRXLT 已提交
312
            echo "bert RPC inference pass"
W
wangjiawei04 已提交
313 314
            ;;
        GPU)
B
fix bug  
barrierye 已提交
315
            export CUDA_VISIBLE_DEVICES=0
W
wangjiawei04 已提交
316
            pip install paddlehub
317 318 319 320
            # Because download from paddlehub may timeout,
            # download the model from bos(max_seq_len=128).
            wget https://paddle-serving.bj.bcebos.com/paddle_hub_models/text/SemanticModel/bert_chinese_L-12_H-768_A-12.tar.gz
            tar -xzf bert_chinese_L-12_H-768_A-12.tar.gz
W
wangjiawei04 已提交
321
            sh get_data.sh
322
            check_cmd "python -m paddle_serving_server_gpu.serve --model bert_chinese_L-12_H-768_A-12_model --port 9292 --gpu_ids 0 &"
323
            sleep 5
W
wangjiawei04 已提交
324
            pip install paddle_serving_app
325
            check_cmd "head -n 10 data-c.txt | python bert_client.py --model bert_chinese_L-12_H-768_A-12_client/serving_client_conf.prototxt"
J
Jiawei Wang 已提交
326
            kill_server_process
W
wangjiawei04 已提交
327 328 329
            echo "bert RPC inference pass"
            ;;
        *)
B
barrierye 已提交
330 331 332
            echo "error type"
            exit 1
            ;;
W
wangjiawei04 已提交
333 334
    esac
    echo "test bert $TYPE finished as expected."
335
    unset SERVING_BIN
W
wangjiawei04 已提交
336 337 338
    cd ..
}

M
MRXLT 已提交
339
function python_test_multi_fetch() {
M
MRXLT 已提交
340 341 342 343 344 345 346 347 348
    # pwd: /Serving/python/examples
    local TYPT=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd bert # pwd: /Serving/python/examples/bert
    case $TYPE in
        CPU)
            #download model (max_seq_len=32)
            wget https://paddle-serving.bj.bcebos.com/bert_example/bert_multi_fetch.tar.gz
            tar -xzvf bert_multi_fetch.tar.gz
M
fix ci  
MRXLT 已提交
349
            check_cmd "python -m paddle_serving_server.serve --model bert_seq32_model --port 9292 &"
M
MRXLT 已提交
350
            sleep 5
M
MRXLT 已提交
351
            check_cmd "head -n 8 data-c.txt | python test_multi_fetch_client.py"
M
MRXLT 已提交
352 353 354 355 356 357 358
            kill_server_process
            echo "bert mutli fetch RPC inference pass"
            ;;
        GPU)
            #download model (max_seq_len=32)
            wget https://paddle-serving.bj.bcebos.com/bert_example/bert_multi_fetch.tar.gz
            tar -xzvf bert_multi_fetch.tar.gz
M
fix ci  
MRXLT 已提交
359
            check_cmd "python -m paddle_serving_server_gpu.serve --model bert_seq32_model --port 9292 --gpu_ids 0 &"
M
MRXLT 已提交
360
            sleep 5
M
MRXLT 已提交
361
            check_cmd "head -n 8 data-c.txt | python test_multi_fetch_client.py"
M
MRXLT 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375
            kill_server_process
            echo "bert mutli fetch RPC inference pass"
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test multi fetch $TYPE finished as expected."
    unset SERVING_BIN
    cd ..
}

function python_test_multi_process(){
M
MRXLT 已提交
376 377 378
    # pwd: /Serving/python/examples
    local TYPT=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
M
fix ci  
MRXLT 已提交
379
    cd fit_a_line # pwd: /Serving/python/examples/fit_a_line
M
fix bug  
MRXLT 已提交
380
    sh get_data.sh
M
MRXLT 已提交
381 382
    case $TYPE in
        CPU)
B
barrierye 已提交
383 384
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9292 --workdir test9292 &"
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9293 --workdir test9293 &"
M
MRXLT 已提交
385 386 387 388 389 390
            sleep 5
            check_cmd "python test_multi_process_client.py"
            kill_server_process
            echo "bert mutli rpc RPC inference pass"
            ;;
        GPU)
B
barrierye 已提交
391
            rm -rf ./image #TODO: The following code tried to create this folder, but no corresponding code was found
B
barrierye 已提交
392 393
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9292 --workdir test9292 --gpu_ids 0 &"
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9293 --workdir test9293 --gpu_ids 0 &"
M
MRXLT 已提交
394 395 396 397 398 399 400 401 402 403 404 405 406
            sleep 5
            check_cmd "python test_multi_process_client.py"
            kill_server_process
            echo "bert mutli process RPC inference pass"
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test multi process $TYPE finished as expected."
    unset SERVING_BIN
    cd ..
M
MRXLT 已提交
407 408
}

W
wangjiawei04 已提交
409 410 411
function python_test_imdb() {
    # pwd: /Serving/python/examples
    local TYPE=$1
412 413
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd imdb # pwd: /Serving/python/examples/imdb
W
wangjiawei04 已提交
414 415 416
    case $TYPE in
        CPU)
            sh get_data.sh
J
Jiawei Wang 已提交
417
            check_cmd "python -m paddle_serving_server.serve --model imdb_cnn_model/ --port 9292 &"
B
barrierye 已提交
418
            sleep 5
W
wangjiawei04 已提交
419
            check_cmd "head test_data/part-0 | python test_client.py imdb_cnn_client_conf/serving_client_conf.prototxt imdb.vocab"
B
barrierye 已提交
420
            # test batch predict
M
MRXLT 已提交
421
            check_cmd "python benchmark.py --thread 4 --batch_size 8 --model imdb_bow_client_conf/serving_client_conf.prototxt --request rpc --endpoint 127.0.0.1:9292"
W
wangjiawei04 已提交
422
            echo "imdb CPU RPC inference pass"
B
barrierye 已提交
423
            kill_server_process
J
Jiawei Wang 已提交
424 425
            rm -rf work_dir1
            sleep 5
W
wangjiawei04 已提交
426

B
barrierye 已提交
427 428
            unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
            check_cmd "python text_classify_service.py imdb_cnn_model/ workdir/ 9292 imdb.vocab &"
429
            sleep 5
M
MRXLT 已提交
430
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"words\": \"i am very sad | 0\"}], \"fetch\":[\"prediction\"]}' http://127.0.0.1:9292/imdb/prediction"
B
barrierye 已提交
431
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"words": "i am very sad | 0"}], "fetch":["prediction"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9292/imdb/prediction`
B
barrierye 已提交
432 433 434 435
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
B
barrierye 已提交
436
            # test batch predict
M
MRXLT 已提交
437
            check_cmd "python benchmark.py --thread 4 --batch_size 8 --model imdb_bow_client_conf/serving_client_conf.prototxt --request http --endpoint 127.0.0.1:9292"
B
barrierye 已提交
438 439 440
            setproxy # recover proxy state
            kill_server_process
            ps -ef | grep "text_classify_service.py" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
441
            echo "imdb CPU HTTP inference pass"
W
wangjiawei04 已提交
442 443 444 445 446
            ;;
        GPU)
            echo "imdb ignore GPU test"
            ;;
        *)
B
barrierye 已提交
447 448 449
            echo "error type"
            exit 1
            ;;
W
wangjiawei04 已提交
450 451
    esac
    echo "test imdb $TYPE finished as expected."
452 453 454 455 456 457 458 459 460 461 462
    unset SERVING_BIN
    cd ..
}

function python_test_lac() {
    # pwd: /Serving/python/examples
    local TYPE=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd lac # pwd: /Serving/python/examples/lac
    case $TYPE in
        CPU)
M
fix ci  
MRXLT 已提交
463 464 465
            python -m paddle_serving_app.package --get_model lac
            tar -xzvf lac.tar.gz
            check_cmd "python -m paddle_serving_server.serve --model lac_model/ --port 9292 &"
466
            sleep 5
M
fix ci  
MRXLT 已提交
467
            check_cmd "echo \"我爱北京天安门\" | python lac_client.py lac_client/serving_client_conf.prototxt "
468
            echo "lac CPU RPC inference pass"
B
barrierye 已提交
469
            kill_server_process
470

B
barrierye 已提交
471
            unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
M
fix ci  
MRXLT 已提交
472
            check_cmd "python lac_web_service.py lac_model/ lac_workdir 9292 &"
473
            sleep 5
B
barrierye 已提交
474 475
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"words\": \"我爱北京天安门\"}], \"fetch\":[\"word_seg\"]}' http://127.0.0.1:9292/lac/prediction"
            # check http code
B
barrierye 已提交
476
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"words": "我爱北京天安门"}], "fetch":["word_seg"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9292/lac/prediction`
B
barrierye 已提交
477 478 479 480 481 482 483
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
            # http batch
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"words\": \"我爱北京天安门\"}, {\"words\": \"我爱北京天安门\"}], \"fetch\":[\"word_seg\"]}' http://127.0.0.1:9292/lac/prediction"
            # check http code
B
barrierye 已提交
484
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"words": "我爱北京天安门"}, {"words": "我爱北京天安门"}], "fetch":["word_seg"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9292/lac/prediction`
B
barrierye 已提交
485 486 487 488
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
B
barrierye 已提交
489
            setproxy # recover proxy state
B
barrierye 已提交
490
            kill_server_process
491
            ps -ef | grep "lac_web_service" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
492
            sleep 1
493 494 495 496 497 498
            echo "lac CPU HTTP inference pass"
            ;;
        GPU)
            echo "lac ignore GPU test"
            ;;
        *)
B
barrierye 已提交
499 500 501
            echo "error type"
            exit 1
            ;;
502 503 504
    esac
    echo "test lac $TYPE finished as expected."
    unset SERVING_BIN
W
wangjiawei04 已提交
505 506 507
    cd ..
}

B
barrierye 已提交
508 509 510 511 512 513 514
function java_run_test() {
    # pwd: /Serving
    local TYPE=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    unsetproxy
    case $TYPE in
        CPU)
B
barrierye 已提交
515 516 517 518 519 520 521 522 523
            # compile java sdk
            cd java # pwd: /Serving/java
            mvn compile > /dev/null
            mvn install > /dev/null
            # compile java sdk example
            cd examples # pwd: /Serving/java/examples
            mvn compile > /dev/null
            mvn install > /dev/null
            
B
barrierye 已提交
524 525 526 527 528 529 530 531 532 533 534 535 536
            # fit_a_line (general, asyn_predict, batch_predict)
            cd ../../python/examples/grpc_impl_example/fit_a_line # pwd: /Serving/python/examples/grpc_impl_example/fit_a_line
            sh get_data.sh
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9393 --thread 4 --use_multilang > /dev/null &"
            sleep 5 # wait for the server to start
            cd ../../../java/examples # /Serving/java/examples
            java -cp target/paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PaddleServingClientExample fit_a_line
            java -cp target/paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PaddleServingClientExample asyn_predict
            java -cp target/paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PaddleServingClientExample batch_predict
            kill_server_process

            # imdb (model_ensemble)
            cd ../../python/examples/grpc_impl_example/imdb # pwd: /Serving/python/examples/grpc_impl_example/imdb
B
barrierye 已提交
537
            sh get_data.sh > /dev/null
B
barrierye 已提交
538 539 540 541 542 543 544 545
            check_cmd "python test_multilang_ensemble_server.py > /dev/null &"
            sleep 5 # wait for the server to start
            cd ../../../java/examples # /Serving/java/examples
            java -cp target/paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PaddleServingClientExample model_ensemble
            kill_server_process

            # yolov4 (int32)
            cd ../../python/examples/grpc_impl_example/yolov4 # pwd: /Serving/python/examples/grpc_impl_example/yolov4
B
barrierye 已提交
546 547
            python -m paddle_serving_app.package --get_model yolov4 > /dev/null
            tar -xzf yolov4.tar.gz > /dev/null
B
barrierye 已提交
548
            check_cmd "python -m paddle_serving_server.serve --model yolov4_model --port 9393 --use_multilang --mem_optim > /dev/null &"
B
barrierye 已提交
549 550 551
            cd ../../../java/examples # /Serving/java/examples
            java -cp target/paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PaddleServingClientExample yolov4 src/main/resources/000000570688.jpg
            kill_server_process
B
barrierye 已提交
552
            cd ../../ # pwd: /Serving
B
barrierye 已提交
553 554 555 556 557 558 559 560 561 562 563 564 565
            ;;
        GPU)
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "java-sdk $TYPE part finished as expected."
    setproxy
    unset SERVING_BIN
}

B
barrierye 已提交
566 567 568 569 570
function python_test_grpc_impl() {
    # pwd: /Serving/python/examples
    cd grpc_impl_example # pwd: /Serving/python/examples/grpc_impl_example
    local TYPE=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
B
barrierye 已提交
571
    unsetproxy
B
barrierye 已提交
572 573 574 575 576 577 578 579 580 581 582 583
    case $TYPE in
        CPU)
            # test general case
            cd fit_a_line # pwd: /Serving/python/examples/grpc_impl_example/fit_a_line
            sh get_data.sh

            # one line command start
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9393 --thread 4 --use_multilang > /dev/null &"
            sleep 5 # wait for the server to start
            check_cmd "python test_sync_client.py > /dev/null"
            check_cmd "python test_asyn_client.py > /dev/null"
            check_cmd "python test_general_pb_client.py > /dev/null"
B
barrierye 已提交
584
            check_cmd "python test_numpy_input_client.py > /dev/null"
B
barrierye 已提交
585
            check_cmd "python test_batch_client.py > /dev/null"
B
barrierye 已提交
586
            check_cmd "python test_timeout_client.py > /dev/null"
B
barrierye 已提交
587
            kill_server_process
B
barrierye 已提交
588
            kill_process_by_port 9393
B
barrierye 已提交
589

B
barrierye 已提交
590
            check_cmd "python test_server.py uci_housing_model > /dev/null &"
B
barrierye 已提交
591 592 593 594
            sleep 5 # wait for the server to start
            check_cmd "python test_sync_client.py > /dev/null"
            check_cmd "python test_asyn_client.py > /dev/null"
            check_cmd "python test_general_pb_client.py > /dev/null"
B
barrierye 已提交
595
            check_cmd "python test_numpy_input_client.py > /dev/null"
B
barrierye 已提交
596
            check_cmd "python test_batch_client.py > /dev/null"
B
barrierye 已提交
597
            check_cmd "python test_timeout_client.py > /dev/null"
B
barrierye 已提交
598
            kill_server_process
B
barrierye 已提交
599
            kill_process_by_port 9393
B
barrierye 已提交
600

B
barrierye 已提交
601 602 603 604 605
            cd .. # pwd: /Serving/python/examples/grpc_impl_example

            # test load server config and client config in Server side
            cd criteo_ctr_with_cube # pwd: /Serving/python/examples/grpc_impl_example/criteo_ctr_with_cube

B
barrierye 已提交
606
            check_cmd "wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz > /dev/null"
B
barrierye 已提交
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
            check_cmd "tar xf ctr_cube_unittest.tar.gz"
            check_cmd "mv models/ctr_client_conf ./"
            check_cmd "mv models/ctr_serving_model_kv ./"
            check_cmd "mv models/data ./cube/"
            check_cmd "mv models/ut_data ./"
            cp ../../../../build-server-$TYPE/output/bin/cube* ./cube/
            sh cube_prepare.sh &
            check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/"
            python test_server.py ctr_serving_model_kv ctr_client_conf/serving_client_conf.prototxt &
            sleep 5
            check_cmd "python test_client.py ./ut_data >score"
            tail -n 2 score | awk 'NR==1'
            AUC=$(tail -n 2  score | awk 'NR==1')
            VAR2="0.67" #TODO: temporarily relax the threshold to 0.67
            RES=$( echo "$AUC>$VAR2" | bc )
            if [[ $RES -eq 0 ]]; then
                echo "error with criteo_ctr_with_cube inference auc test, auc should > 0.67"
                exit 1
            fi
            echo "grpc impl test success"
            kill_server_process
            ps -ef | grep "cube" | grep -v grep | awk '{print $2}' | xargs kill

            cd .. # pwd: /Serving/python/examples/grpc_impl_example
B
barrierye 已提交
631 632 633 634 635 636 637 638 639 640 641 642 643
            ;;
        GPU)
            export CUDA_VISIBLE_DEVICES=0
            # test general case
            cd fit_a_line # pwd: /Serving/python/examples/grpc_impl_example/fit_a_line
            sh get_data.sh

            # one line command start
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9393 --thread 4 --gpu_ids 0 --use_multilang > /dev/null &"
            sleep 5 # wait for the server to start
            check_cmd "python test_sync_client.py > /dev/null"
            check_cmd "python test_asyn_client.py > /dev/null"
            check_cmd "python test_general_pb_client.py > /dev/null"
B
barrierye 已提交
644
            check_cmd "python test_numpy_input_client.py > /dev/null"
B
barrierye 已提交
645
            check_cmd "python test_batch_client.py > /dev/null"
B
barrierye 已提交
646
            check_cmd "python test_timeout_client.py > /dev/null"
B
barrierye 已提交
647
            kill_server_process
B
barrierye 已提交
648
            kill_process_by_port 9393
B
barrierye 已提交
649

B
barrierye 已提交
650
            check_cmd "python test_server_gpu.py uci_housing_model > /dev/null &"
B
barrierye 已提交
651 652 653 654
            sleep 5 # wait for the server to start
            check_cmd "python test_sync_client.py > /dev/null"
            check_cmd "python test_asyn_client.py > /dev/null"
            check_cmd "python test_general_pb_client.py > /dev/null"
B
barrierye 已提交
655
            check_cmd "python test_numpy_input_client.py > /dev/null"
B
barrierye 已提交
656
            check_cmd "python test_batch_client.py > /dev/null"
B
barrierye 已提交
657
            check_cmd "python test_timeout_client.py > /dev/null"
B
barrierye 已提交
658
            kill_server_process
B
barrierye 已提交
659
            kill_process_by_port 9393
B
barrierye 已提交
660
            #ps -ef | grep "test_server_gpu" | grep -v serving_build | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
661

B
barrierye 已提交
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
            cd .. # pwd: /Serving/python/examples/grpc_impl_example

            # test load server config and client config in Server side
            cd criteo_ctr_with_cube # pwd: /Serving/python/examples/grpc_impl_example/criteo_ctr_with_cube

            check_cmd "wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz"
            check_cmd "tar xf ctr_cube_unittest.tar.gz"
            check_cmd "mv models/ctr_client_conf ./"
            check_cmd "mv models/ctr_serving_model_kv ./"
            check_cmd "mv models/data ./cube/"
            check_cmd "mv models/ut_data ./"
            cp ../../../../build-server-$TYPE/output/bin/cube* ./cube/
            sh cube_prepare.sh &
            check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/"
            python test_server_gpu.py ctr_serving_model_kv ctr_client_conf/serving_client_conf.prototxt &
            sleep 5
B
barrierye 已提交
678 679
            # for warm up
            python test_client.py ./ut_data &> /dev/null || true
B
barrierye 已提交
680 681 682 683 684 685 686 687 688 689 690
            check_cmd "python test_client.py ./ut_data >score"
            tail -n 2 score | awk 'NR==1'
            AUC=$(tail -n 2  score | awk 'NR==1')
            VAR2="0.67" #TODO: temporarily relax the threshold to 0.67
            RES=$( echo "$AUC>$VAR2" | bc )
            if [[ $RES -eq 0 ]]; then
                echo "error with criteo_ctr_with_cube inference auc test, auc should > 0.67"
                exit 1
            fi
            echo "grpc impl test success"
            kill_server_process
B
barrierye 已提交
691
            ps -ef | grep "test_server_gpu" | grep -v serving_build | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
692 693
            ps -ef | grep "cube" | grep -v grep | awk '{print $2}' | xargs kill
            cd .. # pwd: /Serving/python/examples/grpc_impl_example
B
barrierye 已提交
694 695 696 697 698 699
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
B
barrierye 已提交
700
    echo "test grpc impl $TYPE part finished as expected."
B
barrierye 已提交
701
    setproxy
B
barrierye 已提交
702 703 704 705
    unset SERVING_BIN
    cd .. # pwd: /Serving/python/examples
}

B
barrierye 已提交
706

M
MRXLT 已提交
707 708 709 710 711 712 713
function python_test_yolov4(){
    #pwd:/ Serving/python/examples
    local TYPE=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd yolov4
    case $TYPE in
        CPU)
M
MRXLT 已提交
714
            echo "no implement for cpu type"
M
MRXLT 已提交
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
            ;;
        GPU)
            python -m paddle_serving_app.package --get_model yolov4
            tar -xzvf yolov4.tar.gz
            check_cmd "python -m paddle_serving_server_gpu.serve --model yolov4_model/ --port 9393 --gpu_ids 0 &"
            sleep 5
            check_cmd "python test_client.py 000000570688.jpg"
            echo "yolov4 GPU RPC inference pass"
            kill_server_process
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test yolov4 $TYPE finished as expected."
    unset SERVING_BIN
    cd ..
}

M
MRXLT 已提交
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
function python_test_resnet50(){
    #pwd:/ Serving/python/examples
    local TYPE=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd imagenet
    case $TYPE in
        CPU)
            echo "no implement for cpu type"
            ;;
        GPU)
            sh get_model.sh
            check_cmd"python -m paddle_serving_server_gpu.serve --model ResNet50_vd_model --port 9696 --gpu_ids 0"
            sleep 5
            check_cmd"python resnet50_rpc_client.py ResNet50_vd_client_config/serving_client_conf.prototxt"
            echo "resnet50 GPU RPC inference pass"
            kill_server_process
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test resnet $TYPE finished as expected"
    unset SERVING_BIN
    cd ..
}

B
barrierye 已提交
762 763 764 765 766 767 768 769 770 771
function python_test_pipeline(){
    # pwd:/ Serving/python/examples
    local TYPE=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    unsetproxy
    cd pipeline/imdb_model_ensemble
    case $TYPE in
        CPU)
            # start paddle serving service (brpc)
            sh get_data.sh
B
barrierye 已提交
772 773
            python -m paddle_serving_server.serve --model imdb_cnn_model --port 9292 --workdir test9292 &> cnn.log &
            python -m paddle_serving_server.serve --model imdb_bow_model --port 9393 --workdir test9393 &> bow.log &
B
barrierye 已提交
774 775 776
            sleep 5
            
            # test: thread servicer & thread op
B
barrierye 已提交
777
            cat << EOF > config.yml
B
barrierye 已提交
778
port: 18080
B
bug fix  
barriery 已提交
779
worker_num: 4
B
barrierye 已提交
780 781 782 783 784 785 786
build_dag_each_worker: false
dag:
    is_thread_op: true
    client_type: brpc
    retry: 1
    use_profile: false
EOF
B
barrierye 已提交
787
            python test_pipeline_server.py > /dev/null &
B
barrierye 已提交
788 789 790
            sleep 5
            check_cmd "python test_pipeline_client.py"
            ps -ef | grep "pipeline_server" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
791
            kill_process_by_port 18080
B
barrierye 已提交
792 793

            # test: thread servicer & process op
B
barrierye 已提交
794
            cat << EOF > config.yml
B
barrierye 已提交
795
port: 18080
B
bug fix  
barriery 已提交
796
worker_num: 4
B
barrierye 已提交
797 798 799 800 801 802 803
build_dag_each_worker: false
dag:
    is_thread_op: false
    client_type: brpc
    retry: 1
    use_profile: false
EOF
B
barrierye 已提交
804
            python test_pipeline_server.py > /dev/null &
B
barrierye 已提交
805 806 807
            sleep 5
            check_cmd "python test_pipeline_client.py"
            ps -ef | grep "pipeline_server" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
808
            kill_process_by_port 18080
B
barrierye 已提交
809

B
bug fix  
barriery 已提交
810
            # test: process servicer & process op
B
barrierye 已提交
811
            cat << EOF > config.yml
B
barrierye 已提交
812
port: 18080
B
bug fix  
barriery 已提交
813 814
worker_num: 4
build_dag_each_worker: false
B
barrierye 已提交
815
dag:
B
bug fix  
barriery 已提交
816
    is_thread_op: false
B
barrierye 已提交
817 818 819 820
    client_type: brpc
    retry: 1
    use_profile: false
EOF
B
barrierye 已提交
821
            python test_pipeline_server.py > /dev/null &
B
barrierye 已提交
822 823 824
            sleep 5
            check_cmd "python test_pipeline_client.py"
            ps -ef | grep "pipeline_server" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
825
            kill_process_by_port 18080
B
bug fix  
barriery 已提交
826 827
            
            # test: process servicer & thread op
B
fix ci  
barriery 已提交
828
            pip uninstall grpcio -y
B
bug fix  
barriery 已提交
829
            pip install grpcio --no-binary=grpcio
B
barrierye 已提交
830
            cat << EOF > config.yml
B
barrierye 已提交
831
port: 18080
B
bug fix  
barriery 已提交
832 833
worker_num: 4
build_dag_each_worker: true
B
barrierye 已提交
834
dag:
B
bug fix  
barriery 已提交
835
    is_thread_op: false
B
barrierye 已提交
836 837 838 839
    client_type: brpc
    retry: 1
    use_profile: false
EOF
B
barrierye 已提交
840
            python test_pipeline_server.py > /dev/null &
B
barrierye 已提交
841 842 843
            sleep 5
            check_cmd "python test_pipeline_client.py"
            ps -ef | grep "pipeline_server" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
844
            kill_process_by_port 18080
B
barrierye 已提交
845

B
barriery 已提交
846 847 848 849
            kill_server_process
            kill_process_by_port 9292
            kill_process_by_port 9393

B
barrierye 已提交
850
            # start paddle serving service (grpc)
B
barrierye 已提交
851 852
            python -m paddle_serving_server.serve --model imdb_cnn_model --port 9292 --use_multilang --workdir test9292 &> cnn.log &
            python -m paddle_serving_server.serve --model imdb_bow_model --port 9393 --use_multilang --workdir test9393 &> bow.log &
B
barrierye 已提交
853
            sleep 5
B
barrierye 已提交
854 855
            cat << EOF > config.yml
port: 18080
B
bug fix  
barriery 已提交
856
worker_num: 4
B
barrierye 已提交
857 858 859 860 861 862 863
build_dag_each_worker: false
dag:
    is_thread_op: false
    client_type: grpc
    retry: 1
    use_profile: false
EOF
B
barrierye 已提交
864
            python test_pipeline_server.py > /dev/null &
B
barrierye 已提交
865 866 867
            sleep 5
            check_cmd "python test_pipeline_client.py"
            ps -ef | grep "pipeline_server" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
868
            kill_process_by_port 18080
B
barrierye 已提交
869
            kill_server_process
B
barrierye 已提交
870 871
            kill_process_by_port 9292
            kill_process_by_port 9393
B
barrierye 已提交
872 873 874 875 876 877 878 879 880 881 882 883 884 885
            ;;
        GPU)
            echo "pipeline ignore GPU test"
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    cd ../../
    setproxy
    unset SERVING_BIN
}

M
MRXLT 已提交
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
function python_app_api_test(){
    #pwd:/ Serving/python/examples
    #test image reader
    local TYPE=$1
    cd imagenet
    case $TYPE in
        CPU)
            check_cmd "python test_image_reader.py"
            ;;
        GPU)
            echo "no implement for cpu type"
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test app api finised as expected"
    cd ..
}
M
MRXLT 已提交
906

G
guru4elephant 已提交
907
function python_run_test() {
908
    # Using the compiled binary
Y
Your Name 已提交
909 910 911
    local TYPE=$1 # pwd: /Serving
    cd python/examples # pwd: /Serving/python/examples
    python_test_fit_a_line $TYPE # pwd: /Serving/python/examples
Y
merge  
Your Name 已提交
912
    python_run_criteo_ctr_with_cube $TYPE # pwd: /Serving/python/examples
W
wangjiawei04 已提交
913
    python_test_bert $TYPE # pwd: /Serving/python/examples
M
MRXLT 已提交
914
    python_test_imdb $TYPE # pwd: /Serving/python/examples
M
MRXLT 已提交
915 916 917
    python_test_lac $TYPE # pwd: /Serving/python/examples
    python_test_multi_process $TYPE # pwd: /Serving/python/examples
    python_test_multi_fetch $TYPE # pwd: /Serving/python/examples
M
MRXLT 已提交
918
    python_test_yolov4 $TYPE # pwd: /Serving/python/examples
B
barrierye 已提交
919
    python_test_grpc_impl $TYPE # pwd: /Serving/python/examples
M
MRXLT 已提交
920
    python_test_resnet50 $TYPE # pwd: /Serving/python/examples
B
barrierye 已提交
921
    python_test_pipeline $TYPE # pwd: /Serving/python/examples
G
guru4elephant 已提交
922
    echo "test python $TYPE part finished as expected."
Y
Your Name 已提交
923
    cd ../.. # pwd: /Serving
G
guru4elephant 已提交
924 925
}

B
barrierye 已提交
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
function monitor_test() {
    local TYPE=$1 # pwd: /Serving
    mkdir _monitor_test && cd _monitor_test # pwd: /Serving/_monitor_test
    case $TYPE in
        CPU):
            pip install pyftpdlib
            mkdir remote_path
            mkdir local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            check_cmd "python -m pyftpdlib -p 8000 &>/dev/null &"
            cd .. # pwd: /Serving/_monitor_test

            # type: ftp
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: ftp
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            ps -ef | grep "pyftpdlib" | grep -v grep | awk '{print $2}' | xargs kill
            ;;
        GPU):
B
barrierye 已提交
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
            pip install pyftpdlib
            mkdir remote_path
            mkdir local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            check_cmd "python -m pyftpdlib -p 8000 &>/dev/null &"
            cd .. # pwd: /Serving/_monitor_test

            # type: ftp
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: ftp
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            ps -ef | grep "pyftpdlib" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
1157 1158
            ;;
        *)
B
barrierye 已提交
1159 1160 1161
            echo "error type"
            exit 1
            ;;
B
barrierye 已提交
1162 1163 1164 1165 1166 1167
    esac
    cd .. # pwd: /Serving
    rm -rf _monitor_test
    echo "test monitor $TYPE finished as expected."
}

G
guru4elephant 已提交
1168
function main() {
Y
Your Name 已提交
1169 1170 1171 1172
    local TYPE=$1 # pwd: /
    init # pwd: /Serving
    build_client $TYPE # pwd: /Serving
    build_server $TYPE # pwd: /Serving
B
barrierye 已提交
1173
    build_app $TYPE # pwd: /Serving
B
barrierye 已提交
1174
    java_run_test $TYPE # pwd: /Serving
Y
Your Name 已提交
1175
    python_run_test $TYPE # pwd: /Serving
B
barrierye 已提交
1176
    monitor_test $TYPE # pwd: /Serving
G
guru4elephant 已提交
1177 1178 1179 1180
    echo "serving $TYPE part finished as expected."
}

main $@
B
barrierye 已提交
1181
exit 0