优化 watchdog tfe worker thread 的实现逻辑
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <event2/buffer.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#include <proxy.h>
|
||||
#include <platform.h>
|
||||
@@ -202,37 +203,19 @@ retry:
|
||||
|
||||
void * watchdog_kni_thread(void * arg)
|
||||
{
|
||||
char thread_name[16];
|
||||
snprintf(thread_name, sizeof(thread_name), "watchdog:kni");
|
||||
prctl(PR_SET_NAME, (unsigned long long) thread_name, NULL, NULL, NULL);
|
||||
|
||||
struct watchdog_kni * __ctx = (struct watchdog_kni *)arg;
|
||||
while(event_base_dispatch(__ctx->ev_base) >= 0) {}
|
||||
DIE("watchdog thread is terminated.");
|
||||
}
|
||||
|
||||
static void health_check_for_thread_worker(evutil_socket_t fd, short what, void * arg)
|
||||
{
|
||||
struct tfe_proxy *proxy = (struct tfe_proxy *)arg;
|
||||
struct timespec now;
|
||||
time_t temp;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
for (unsigned int i = 0; i < proxy->nr_work_threads; i++)
|
||||
{
|
||||
temp = ATOMIC_READ(&(proxy->work_threads[i]->lastime));
|
||||
if (temp + 2 + 2 + 1 < now.tv_sec)
|
||||
{
|
||||
TFE_LOG_ERROR(g_default_logger, "Watchdog thread nowtime %ld, Worker thread %d lastime %ld, Worker thread no reply, Exit ! ! ! ", now.tv_sec, proxy->work_threads[i]->thread_id, temp);
|
||||
abort();
|
||||
}
|
||||
// TFE_LOG_DEBUG(g_default_logger, "Watchdog thread nowtime %ld, Worker thread %d lastime %lds ", now.tv_sec, proxy->work_threads[i]->thread_id, temp);
|
||||
}
|
||||
DIE("Watchdog KNI thread is terminated.");
|
||||
}
|
||||
|
||||
struct watchdog_kni * watchdog_kni_create(struct tfe_proxy * proxy, const char * profile, void * logger)
|
||||
{
|
||||
struct watchdog_kni * __ctx = ALLOC(struct watchdog_kni, 1);
|
||||
int ret = 0;
|
||||
struct event *ev = NULL;
|
||||
struct timeval timer_delay = {2, 0};
|
||||
|
||||
__ctx->proxy = proxy;
|
||||
__ctx->profile = profile;
|
||||
@@ -274,17 +257,6 @@ struct watchdog_kni * watchdog_kni_create(struct tfe_proxy * proxy, const char *
|
||||
errno = 0;
|
||||
goto __errout;
|
||||
}
|
||||
|
||||
ev = event_new(__ctx->ev_base, -1, EV_PERSIST, health_check_for_thread_worker, proxy);
|
||||
if (unlikely(ev == NULL))
|
||||
{
|
||||
TFE_LOG_ERROR(__ctx->logger, "Failed at creating health check event for worker thread");
|
||||
/* after log, reset errno */
|
||||
errno = 0;
|
||||
goto __errout;
|
||||
}
|
||||
evtimer_add(ev, &timer_delay);
|
||||
|
||||
watchdog_kni_reset(__ctx);
|
||||
watchdog_kni_try_connect(__ctx);
|
||||
|
||||
@@ -298,7 +270,7 @@ struct watchdog_kni * watchdog_kni_create(struct tfe_proxy * proxy, const char *
|
||||
goto __errout;
|
||||
}
|
||||
|
||||
TFE_LOG_INFO(__ctx->logger, "KNI watchdog module init successfully.");
|
||||
TFE_LOG_INFO(__ctx->logger, "Watchdog KNI module init successfully.");
|
||||
return __ctx;
|
||||
|
||||
__errout:
|
||||
|
||||
Reference in New Issue
Block a user