提交 570fde52 编写于 作者: O obdev 提交者: ob-robot

Optimize cpu consumption for arb server.

上级 e5bfe02e
#define TIME_WHEEL_SLOT_NUM (1<<16) #define TIME_WHEEL_SLOT_NUM (1<<16)
#define TIME_WHEEL_SLOT_INTERVAL 1024 #define TIME_WHEEL_SLOT_INTERVAL 8192
typedef struct time_wheel_t time_wheel_t; typedef struct time_wheel_t time_wheel_t;
typedef void (timer_cb_t)(time_wheel_t* tw, dlink_t* l); typedef void (timer_cb_t)(time_wheel_t* tw, dlink_t* l);
typedef struct time_wheel_t { typedef struct time_wheel_t {
......
...@@ -93,7 +93,8 @@ const int64_t PALF_LEADER_RECONFIRM_SYNC_TIMEOUT_US = 10 * 1000 * 1000L; // ...@@ -93,7 +93,8 @@ const int64_t PALF_LEADER_RECONFIRM_SYNC_TIMEOUT_US = 10 * 1000 * 1000L; //
const int64_t PREPARE_LOG_BUFFER_SIZE = 2048; const int64_t PREPARE_LOG_BUFFER_SIZE = 2048;
const int64_t PALF_LEADER_ACTIVE_SYNC_TIMEOUT_US = 10 * 1000 * 1000L; // 10s const int64_t PALF_LEADER_ACTIVE_SYNC_TIMEOUT_US = 10 * 1000 * 1000L; // 10s
const int32_t PALF_MAX_REPLAY_TIMEOUT = 500 * 1000; const int32_t PALF_MAX_REPLAY_TIMEOUT = 500 * 1000;
const int32_t PALF_LOG_LOOP_INTERVAL_US = 1 * 1000; // 1ms const int32_t DEFAULT_PALF_LOG_LOOP_INTERVAL_US = 1 * 1000; // 1ms
const int32_t PALF_LOG_LOOP_INTERVAL_US_UPPER_BOUND = 100 * 1000; // 100ms
const int64_t PALF_SLIDING_WINDOW_SIZE = 1 << 11; // must be 2^n(n>0), default 2^11 = 2048 const int64_t PALF_SLIDING_WINDOW_SIZE = 1 << 11; // must be 2^n(n>0), default 2^11 = 2048
const int64_t PALF_MAX_LEADER_SUBMIT_LOG_COUNT = PALF_SLIDING_WINDOW_SIZE / 2; // max number of concurrent submitting group log in leader const int64_t PALF_MAX_LEADER_SUBMIT_LOG_COUNT = PALF_SLIDING_WINDOW_SIZE / 2; // max number of concurrent submitting group log in leader
const int64_t PALF_RESEND_MSLOG_INTERVAL_US = 500 * 1000L; // 500 ms const int64_t PALF_RESEND_MSLOG_INTERVAL_US = 500 * 1000L; // 500 ms
......
...@@ -105,7 +105,6 @@ void LogIOTaskCbThreadPool::destroy() ...@@ -105,7 +105,6 @@ void LogIOTaskCbThreadPool::destroy()
wait(); wait();
is_inited_ = false; is_inited_ = false;
if (-1 != tg_id_) { if (-1 != tg_id_) {
MTL_UNREGISTER_THREAD_DYNAMIC(tg_id_);
TG_DESTROY(tg_id_); TG_DESTROY(tg_id_);
} }
tg_id_ = -1; tg_id_ = -1;
......
...@@ -22,6 +22,7 @@ namespace palf ...@@ -22,6 +22,7 @@ namespace palf
{ {
LogLoopThread::LogLoopThread() LogLoopThread::LogLoopThread()
: palf_env_impl_(NULL), : palf_env_impl_(NULL),
run_interval_(DEFAULT_PALF_LOG_LOOP_INTERVAL_US),
is_inited_(false) is_inited_(false)
{ {
} }
...@@ -31,7 +32,7 @@ LogLoopThread::~LogLoopThread() ...@@ -31,7 +32,7 @@ LogLoopThread::~LogLoopThread()
destroy(); destroy();
} }
int LogLoopThread::init(IPalfEnvImpl *palf_env_impl) int LogLoopThread::init(const bool is_normal_mode, IPalfEnvImpl *palf_env_impl)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
if (OB_UNLIKELY(is_inited_)) { if (OB_UNLIKELY(is_inited_)) {
...@@ -43,6 +44,9 @@ int LogLoopThread::init(IPalfEnvImpl *palf_env_impl) ...@@ -43,6 +44,9 @@ int LogLoopThread::init(IPalfEnvImpl *palf_env_impl)
} else { } else {
palf_env_impl_ = palf_env_impl; palf_env_impl_ = palf_env_impl;
share::ObThreadPool::set_run_wrapper(MTL_CTX()); share::ObThreadPool::set_run_wrapper(MTL_CTX());
if (false == is_normal_mode) {
run_interval_ = PALF_LOG_LOOP_INTERVAL_US_UPPER_BOUND;
}
is_inited_ = true; is_inited_ = true;
} }
...@@ -108,13 +112,13 @@ void LogLoopThread::log_loop_() ...@@ -108,13 +112,13 @@ void LogLoopThread::log_loop_()
} }
const int64_t round_cost_time = ObTimeUtility::current_time() - start_ts; const int64_t round_cost_time = ObTimeUtility::current_time() - start_ts;
int32_t sleep_ts = PALF_LOG_LOOP_INTERVAL_US - static_cast<const int32_t>(round_cost_time); int32_t sleep_ts = run_interval_ - static_cast<const int32_t>(round_cost_time);
if (sleep_ts < 0) { if (sleep_ts < 0) {
sleep_ts = 0; sleep_ts = 0;
} }
ob_usleep(sleep_ts); ob_usleep(sleep_ts);
if (REACH_TIME_INTERVAL(5 * 1000 * 1000)) { if (REACH_TENANT_TIME_INTERVAL(5 * 1000 * 1000)) {
PALF_LOG(INFO, "LogLoopThread round_cost_time", K(round_cost_time)); PALF_LOG(INFO, "LogLoopThread round_cost_time", K(round_cost_time));
} }
} }
......
...@@ -27,13 +27,14 @@ public: ...@@ -27,13 +27,14 @@ public:
LogLoopThread(); LogLoopThread();
virtual ~LogLoopThread(); virtual ~LogLoopThread();
public: public:
int init(IPalfEnvImpl *palf_env_impl); int init(const bool is_normal_mode, IPalfEnvImpl *palf_env_impl);
void destroy(); void destroy();
void run1(); void run1();
private: private:
void log_loop_(); void log_loop_();
private: private:
IPalfEnvImpl *palf_env_impl_; IPalfEnvImpl *palf_env_impl_;
int64_t run_interval_;
bool is_inited_; bool is_inited_;
private: private:
DISALLOW_COPY_AND_ASSIGN(LogLoopThread); DISALLOW_COPY_AND_ASSIGN(LogLoopThread);
......
...@@ -207,7 +207,7 @@ int PalfEnvImpl::init( ...@@ -207,7 +207,7 @@ int PalfEnvImpl::init(
PALF_LOG(ERROR, "construct log path failed", K(ret), K(pret)); PALF_LOG(ERROR, "construct log path failed", K(ret), K(pret));
} else if (OB_FAIL(palf_handle_impl_map_.init("LOG_HASH_MAP", tenant_id))) { } else if (OB_FAIL(palf_handle_impl_map_.init("LOG_HASH_MAP", tenant_id))) {
PALF_LOG(ERROR, "palf_handle_impl_map_ init failed", K(ret)); PALF_LOG(ERROR, "palf_handle_impl_map_ init failed", K(ret));
} else if (OB_FAIL(log_loop_thread_.init(this))) { } else if (OB_FAIL(log_loop_thread_.init(true, this))) {
PALF_LOG(ERROR, "log_loop_thread_ init failed", K(ret)); PALF_LOG(ERROR, "log_loop_thread_ init failed", K(ret));
} else if (OB_FAIL( } else if (OB_FAIL(
election_timer_.init_and_start(1, 1_ms, "ElectTimer"))) { // just one worker thread election_timer_.init_and_start(1, 1_ms, "ElectTimer"))) { // just one worker thread
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册