Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: reduce scheduler msgs #3583

Merged
merged 2 commits into from Sep 14, 2018
Merged

storage: reduce scheduler msgs #3583

merged 2 commits into from Sep 14, 2018

Conversation

overvenus
Copy link
Member

What have you changed? (mandatory)

This PR reduces scheduler msgs, also offloads some functions from scheduler to workers.

What are the type of the changes? (mandatory)

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested? (mandatory)

Unit tests and integration tests.

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

No.

Does this PR affect tidb-ansible update? (mandatory)

No.

Refer to a related PR or issue link (optional)

#3581 , #3551 and #3582

Benchmark result if necessary (optional)

Combining these changes #3581, #3551 and #3582, QPS is improved from 40672.1 to 49144.5, and avg latnecy is reduced from 100.6ms to 83.5ms.

Msg::WriteFinished { cid, .. } => write!(f, "WriteFinished [cid={}]", cid),
Msg::ReadFinished { ref task, .. } => write!(f, "ReadFinished [cid={}]", task.cid),
Msg::WriteFinished { ref task, .. } => write!(f, "WriteFinished [cid={}]", task.cid),
Msg::FinishedWithErr { cid, .. } => write!(f, "WriteFinished [cid={}]", cid),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong format message

@overvenus overvenus changed the title storage: reduce scheduler msgs [DNM]storage: reduce scheduler msgs Sep 11, 2018
false
}
Err(e) => {
panic!("schedule WriteFinished msg failed, err:{:?}", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong message

@@ -619,6 +684,31 @@ impl ThreadContext for SchedContext {
}
}

pub struct Channels<E: Engine> {
scheduler: Option<worker::Scheduler<Msg>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should add some comments

result,
},
);
if success {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems that it can be combined into previous one

@@ -619,6 +684,31 @@ impl ThreadContext for SchedContext {
}
}

pub struct Channels<E: Engine> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Executor is a better name?


Ok(())
fn handle_schedule(scheduler: worker::Scheduler<Msg>, msg: Msg) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe send_msg_to_scheduler is a better name. Does this function can be a member of Channels?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or notify_scheduler?


impl<E: Engine> Scheduler<E> {
// Start the task.
pub fn start(&mut self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/start/pre_start

@overvenus
Copy link
Member Author

/run-all-tests

let tag = cmd.tag();
let pool = channels.take_pool();
if readcmd {
let pool = executor.take_pool();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more better to move following codes into Executor::exec, so the Executor is more like a executor.

}
}
}

/// Delivers a command to a worker thread for processing.
pub fn process_by_worker(&mut self, cid: u64, cb_ctx: CbContext, snapshot: E::Snap) {
fn process_by_worker<E: Engine>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe process_by_executor is more better.

let scheduler = self.scheduler.clone();
if readcmd {
worker_pool.execute(move |ctx: &mut SchedContext| {
let pool = executor.take_pool();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to wrap following codes into Executor.

let task = Task::new(cid, cmd);

// TODO: enqueue_task should return an reference of the entity.
self.enqueue_task(task, entity);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is weird that enqueue_task has a entity arg.

}

/// Scheduler which schedules the execution of `storage::Command`s.
pub struct Scheduler<E: Engine> {
engine: E,

// cid -> Task
pub cmd_ctxs: HashMap<u64, Task>,
pending_task: HashMap<u64, Task>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending_task -> pending_tasks

if ok {
ctx.latch_timer.take();
ctx.slow_timer = Some(SlowTimer::new());
entity.on_schedule();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call on_schedule in acquire_lock instead of schedule?

} else {
execute_callback(cb, pr);
execute_callback(entity.cb, pr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call the callback inside thread pool?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How?

);
}
// TODO: Moves SchedEntity to Task once we adopt futures in the Engine trait.
struct SchedEntity {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entity doesn't seem to be a good name, it makes more sense that task itself is an entity as it contains the actual task data. How about naming it as TaskTracker just like RequestTracker in endpoint.rs?

}

fn dequeue_schedule_entity(&mut self, cid: u64) -> SchedEntity {
let entity = self.schedule_entities.remove(&cid).unwrap();
fn find_task_context(&mut self, cid: u64) -> TaskContext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/find_task_context/take_task_context

zhangjinpeng87
zhangjinpeng87 previously approved these changes Sep 14, 2018
Copy link
Member

@zhangjinpeng87 zhangjinpeng87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Connor1996
Connor1996 previously approved these changes Sep 14, 2018
Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@overvenus overvenus changed the base branch from scheduler/process to master September 14, 2018 06:35
Signed-off-by: Neil Shen <overvenus@gmail.com>
@overvenus overvenus removed the S: DNM label Sep 14, 2018
@overvenus overvenus changed the title [DNM]storage: reduce scheduler msgs storage: reduce scheduler msgs Sep 14, 2018
Copy link
Member

@zhangjinpeng87 zhangjinpeng87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@overvenus
Copy link
Member Author

/run-all-tests

@zhangjinpeng87
Copy link
Member

/run-all-tests

Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@overvenus overvenus merged commit 597b89c into master Sep 14, 2018
@overvenus overvenus deleted the scheduler/reduce-msg branch September 14, 2018 12:04
sticnarf pushed a commit to sticnarf/tikv that referenced this pull request Oct 27, 2019
Signed-off-by: Neil Shen <overvenus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/performance Component: Performance component/storage Component: Storage, Scheduler, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants