run_standalone.sh 2.6 KB
Newer Older
J
jingqinghe 已提交
1
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
J
jingqinghe 已提交
2
#
J
jingqinghe 已提交
3 4 5 6 7 8 9 10 11 12 13 14
# 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.

J
jingqinghe 已提交
15 16
#!/bin/bash
#
J
jingqinghe 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
# A tools to faciliate the parallel running of fluid_encrypted test scrips.
# A test script is EXPECTED to accepted arguments in the following format:
#
# SCRIPT_NAME $ROLE $SERVER $PORT
#   ROLE:    the role of the running party
#   SERVER:  the address of the party discovering service
#   PORT:    the port of the party discovering service
#
# This tool will try to fill the above three argument to the test script,
# so that totally three processes running the script will be started, to
# simulate run of three party in a standalone machine.
#
# Usage of this script:
#
# bash run_standalone.sh TEST_SCRIPT_NAME
#

# modify the following vars according to your environment
H
heya02 已提交
35 36 37 38 39
PYTHON=${PYTHON}
REDIS_HOME=${PATH_TO_REDIS_BIN}
SERVER=${LOCALHOST}
PORT=${REDIS_PORT}
echo "redis home in ${REDIS_HOME}, server is ${SERVER}, port is ${PORT}"
J
jingqinghe 已提交
40

H
bug_fix  
heya02 已提交
41
function usage(){
J
jingqinghe 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    echo 'run_standalone.sh SCRIPT_NAME [ARG...]'
    exit 0
}

if [ $# -lt 1 ]; then
    usage
fi

SCRIPT=$1
if [ ! -f $SCRIPT ]; then
    echo 'Could not find script of '$SCRIPT
    exit 1
fi

REDIS_BIN=$REDIS_HOME/redis-cli
if [ ! -f $REDIS_BIN ]; then
    echo 'Could not find redis cli in '$REDIS_HOME
    exit 1
fi

# clear the redis cache
$REDIS_BIN -h $SERVER -p $PORT flushall

J
jingqinghe 已提交
65 66 67
# remove temp data generated in last time
LOSS_FILE="/tmp/uci_loss.*"
PRED_FILE="/tmp/uci_prediction.*"
H
bug_fix  
heya02 已提交
68 69
ls ${LOSS_FILE}
if [ $? -eq 0 ]; then
J
jingqinghe 已提交
70 71
        rm -rf $LOSS_FILE
fi
J
jingqinghe 已提交
72

H
bug_fix  
heya02 已提交
73 74
ls ${PRED_FILE}
if [ $? -eq 0 ]; then
J
jingqinghe 已提交
75 76 77
        rm -rf $PRED_FILE
fi

H
heya02 已提交
78
TRAINING_FILE="/tmp/house_feature.part*"
H
bug_fix  
heya02 已提交
79 80
ls ${TRAINING_FILE}
if [ $? -ne 0 ]; then
H
heya02 已提交
81 82 83 84 85 86
    echo "There is no data in /tmp, please prepare data with "python prepare.py" firstly"
    exit 1
else
    echo "There are data for uci:"
    echo "`ls ${TRAINING_FILE}`"
fi
J
jingqinghe 已提交
87 88

# kick off script with roles of 1 and 2, and redirect output to /dev/null
J
jingqinghe 已提交
89 90 91 92 93 94
for role in {1..2}; do
    $PYTHON $SCRIPT $role $SERVER $PORT 2>&1 >/dev/null &
done

# for party of role 0, run in a foreground mode and show the output
$PYTHON $SCRIPT 0 $SERVER $PORT
J
jingqinghe 已提交
95