int main(int argc, char *argv[]) { printf("process: %s version: %s, compile date: %s %s\n", __process__, __version__, __DATE__, __TIME__); if (argc < 2) { printf("usage: %s config.json\n", argv[0]); exit(EXIT_FAILURE); } if (process_exist(__process__) != 0) { printf("process: %s exist\n", __process__); exit(EXIT_FAILURE); } int ret; ret = init_config(argv[1]); if (ret < 0) { error(EXIT_FAILURE, errno, "load config fail: %d", ret); } ret = init_process(); if (ret < 0) { error(EXIT_FAILURE, errno, "init process fail: %d", ret); } ret = init_log(); if (ret < 0) { error(EXIT_FAILURE, errno, "init log fail: %d", ret); } daemon(1, 1); process_keepalive(); ret = init_server(); if (ret < 0) { error(EXIT_FAILURE, errno, "init server fail: %d", ret); } nw_timer_set(&cron_timer, 0.5, true, on_cron_check, NULL); nw_timer_start(&cron_timer); log_vip("server start"); log_stderr("server start"); nw_loop_run(); log_vip("server stop"); return 0; }
static void reciver_looper(void) { if (shut_down_flag) { int i; for (i = 0; i < settings.hash_table_num; ++i) { flush_table(&settings.tables[i]); } log_vip("reciver, shut down..."); exit(0); } struct timeval now; gettimeofday(&now, NULL); dlog_check(NULL, &now); static time_t last_log_min; time_t curr_min = now.tv_sec / 60; if (curr_min != last_log_min) { if (last_log_min != 0) { log_info("reciver: recv pkg: %d, succ: %d, fail: %d", \ recv_pkg_count, process_pkg_succ_count, process_pkg_fail_count); recv_pkg_count = 0; process_pkg_succ_count = 0; process_pkg_fail_count = 0; } last_log_min = curr_min; } static struct timeval last_check; if (settings.cache_time_in_ms && ((timeval_diff(&last_check, &now) / 1000) > (uint64_t)settings.check_time_in_ms)) { int i; for (i = 0; i < settings.hash_table_num; ++i) { if (settings.tables[i].buf_use && (timeval_diff(&settings.tables[i].start, &now) / 1000) > (uint64_t)settings.cache_time_in_ms) { flush_table(&settings.tables[i]); } } last_check = now; } return; }
static void worker_looper(void) { if (shut_down_flag) { log_vip("worker id: %d, shut down...", settings.worker_id); exit(0); } struct timeval now; gettimeofday(&now, NULL); dlog_check(NULL, &now); static time_t last_check; if (settings.shift_table_type != TABLE_NO_SHIFT && now.tv_sec != last_check) { check_shift(now.tv_sec); last_check = now.tv_sec; } static time_t last_log_min; time_t curr_min = now.tv_sec / 60; if (curr_min != last_log_min) { if (last_log_min != 0) { log_info("worker %d: insert succ: %d, fail: %d, other succ: %d, fail: %d", \ settings.worker_id, insert_db_succ_count, insert_db_fail_count, \ exec_sql_succ_count, exec_sql_fail_count); insert_db_succ_count = 0; insert_db_fail_count = 0; exec_sql_succ_count = 0; exec_sql_fail_count = 0; } last_log_min = curr_min; } }