Skip to content

Commit

Permalink
python transport sdk support initLog
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Nov 18, 2024
1 parent ee04393 commit e8eb9d8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 13 deletions.
4 changes: 1 addition & 3 deletions cpp/wedpr-computing/ppc-pir/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ set(TEST_BINARY_NAME test-ppc-pir)

add_executable(${TEST_BINARY_NAME} ${SOURCES})
target_include_directories(${TEST_BINARY_NAME} PRIVATE .)
# target_link_libraries(${PIR_TARGET} PUBLIC ${IO_TARGET} ${FRONT_TARGET} ${BCOS_UTILITIES_TARGET} ${TARS_PROTOCOL_TARGET} TBB::tbb TCMalloc)

# target_link_libraries(${TEST_BINARY_NAME} ${PIR_TARGET} ${RPC_TARGET} ${CRYPTO_TARGET} ${BOOST_UNIT_TEST})
target_link_libraries(${TEST_BINARY_NAME} PUBLIC ${IO_TARGET} ${FRONT_TARGET} ${BCOS_UTILITIES_TARGET} ${TARS_PROTOCOL_TARGET} ${PIR_TARGET} ${RPC_TARGET} ${CRYPTO_TARGET} ${PROTOCOL_TARGET} ${BOOST_UNIT_TEST})
target_link_libraries(${TEST_BINARY_NAME} PUBLIC ${CRYPTO_TARGET} ${BCOS_UTILITIES_TARGET} ${TARS_PROTOCOL_TARGET} ${PIR_TARGET} ${PROTOCOL_TARGET} ${BOOST_UNIT_TEST})
add_test(NAME test-pir WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME})
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,16 @@ bool CalculatorCache::tryToFinalize()
{
continue;
}
if (it.second.plainDataIndex >= 0)
if (it.second.plainDataIndex > 0)
{
m_intersectionResult.emplace_back(getPlainDataByIndex(it.second.plainDataIndex));
}
// means the header field, swap with the first element
if (it.second.plainDataIndex == 0)
{
m_intersectionResult.emplace_back(m_intersectionResult[0]);
m_intersectionResult[0] = getPlainDataByIndex(it.second.plainDataIndex);
}
}
m_cacheState = CacheState::Finalized;
ECDH_MULTI_LOG(INFO) << LOG_DESC("* tryToFinalize: compute intersection success")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __repr__(self):

class TransportLoader:
transport_builder = TransportBuilder()
transport_builder.initLog("conf/wedpr_sdk_log_config.ini")

@staticmethod
def load(transport_config: TransportConfig) -> Transport:
Expand Down
4 changes: 2 additions & 2 deletions python/ppc_model/conf/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ keys=root,wsgi

[logger_root]
level=INFO
handlers=consoleHandler,fileHandler
handlers=fileHandler

[logger_wsgi]
level = INFO
Expand All @@ -12,7 +12,7 @@ qualname = wsgi
propagate = 0

[handlers]
keys=fileHandler,consoleHandler,accessHandler
keys=fileHandler,accessHandler

[handler_accessHandler]
class=handlers.TimedRotatingFileHandler
Expand Down
17 changes: 17 additions & 0 deletions python/ppc_model/conf/wedpr_sdk_log_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[log]
enable = true
log_path = ./log
; info debug trace
level = info
; MB
max_log_file_size = 200
; LineID, TimeStamp, ProcessID, ThreadName, ThreadID and Message
;format = %Severity%|ppcs-gateway|system-id|%TimeStamp%|%ThreadName%-%ThreadID%|%Message%
format = %Severity%|%TimeStamp%|%Message%
enable_rotate_by_hour = true
; if archive_path is empty, the archive function will be disabled
; archive_path = ./log/
;compress_archive_file = true
; ; 0 = no limit, in MB
; max_archive_size = 0
; min_free_space = 0
2 changes: 1 addition & 1 deletion python/ppc_model/ppc_model_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def register_task_handler():
TransLogger(app, setup_console_handler=False), numthreads=2)

protocol = 'http'
message = f"Starting ppc model server at {protocol}://{app.config['HOST']}:{app.config['HTTP_PORT']} successfully"
message = f"* Starting ppc model server at {protocol}://{app.config['HOST']}:{app.config['HTTP_PORT']} successfully"
print(message)
components.logger().info(message)
server.start()
Expand Down
8 changes: 4 additions & 4 deletions python/ppc_model/task/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ def _terminate_timeout_tasks(self):
with self._rw_lock.gen_rlock():
for task_id, value in self._tasks.items():
alive_time = (datetime.datetime.now() -
value[1]).total_seconds()
if alive_time >= self._task_timeout_s and value[0] == TaskStatus.RUNNING.value:
value.start_time).total_seconds()
if alive_time >= self._task_timeout_s and value.task_status == TaskStatus.RUNNING.value:
tasks_to_kill.append(task_id)

for task_id in tasks_to_kill:
Expand All @@ -257,9 +257,9 @@ def _cleanup_finished_tasks(self):
with self._rw_lock.gen_rlock():
for task_id, value in self._tasks.items():
alive_time = (datetime.datetime.now() -
value[1]).total_seconds()
value.start_time).total_seconds()
if alive_time >= self._task_timeout_s + 3600:
tasks_to_cleanup.append((task_id, value[3]))
tasks_to_cleanup.append((task_id, value.job_id))
with self._rw_lock.gen_wlock():
for task_id, job_id in tasks_to_cleanup:
if task_id in self._tasks:
Expand Down
9 changes: 7 additions & 2 deletions python/ppc_model/tools/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ LOG_INFO() {
}
binary_path=${SHELL_FOLDER}/ppc_model_app.py
cd ${SHELL_FOLDER}
log_dir=logs
if [ ! -f ${log_dir} ];then
mkdir -p logs
fi
node=$(basename ${SHELL_FOLDER})
node_pid=$(ps aux|grep ${binary_path}|grep -v grep|awk '{print $2}')

if [ ! -z ${node_pid} ];then
echo " ${node} is running, pid is $node_pid."
exit 0
else
nohup python ${binary_path} > start.out 2>&1 &
# -u means Force the stdout and stderr streams to be unbuffered
nohup python -u ${binary_path} > start.out 2>&1 &
sleep 1.5
fi
try_times=4
Expand All @@ -34,4 +39,4 @@ do
sleep 0.5
((i=i+1))
done
echo -e "\033[31m Exceed waiting time. Please try again to start ${node} \033[0m"
echo -e "\033[31m Exceed waiting time. Please try again to start ${node} \033[0m"

0 comments on commit e8eb9d8

Please sign in to comment.