-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ethcore-io retries failed work steal #9651
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -693,7 +693,6 @@ impl Engine<EthereumMachine> for Tendermint { | |
} | ||
|
||
fn stop(&self) { | ||
self.step_service.stop() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
fn is_proposal(&self, header: &Header) -> bool { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ use std::collections::HashMap; | |
use mio::*; | ||
use mio::timer::{Timeout}; | ||
use mio::deprecated::{EventLoop, Handler, Sender, EventLoopBuilder}; | ||
use crossbeam::sync::chase_lev; | ||
use deque; | ||
use slab::Slab; | ||
use {IoError, IoHandler}; | ||
use worker::{Worker, Work, WorkType}; | ||
|
@@ -184,7 +184,7 @@ pub struct IoManager<Message> where Message: Send + Sync { | |
timers: Arc<RwLock<HashMap<HandlerId, UserTimer>>>, | ||
handlers: Arc<RwLock<Slab<Arc<IoHandler<Message>>>>>, | ||
workers: Vec<Worker>, | ||
worker_channel: chase_lev::Worker<Work<Message>>, | ||
worker_channel: deque::Worker<Work<Message>>, | ||
work_ready: Arc<Condvar>, | ||
} | ||
|
||
|
@@ -194,7 +194,7 @@ impl<Message> IoManager<Message> where Message: Send + Sync + 'static { | |
event_loop: &mut EventLoop<IoManager<Message>>, | ||
handlers: Arc<RwLock<Slab<Arc<IoHandler<Message>>>>> | ||
) -> Result<(), IoError> { | ||
let (worker, stealer) = chase_lev::deque(); | ||
let (worker, stealer) = deque::fifo(); | ||
let num_workers = 4; | ||
let work_ready_mutex = Arc::new(Mutex::new(())); | ||
let work_ready = Arc::new(Condvar::new()); | ||
|
@@ -430,7 +430,7 @@ impl<Message> IoChannel<Message> where Message: Send + Sync + 'static { | |
/// General IO Service. Starts an event loop and dispatches IO requests. | ||
/// 'Message' is a notification message type | ||
pub struct IoService<Message> where Message: Send + Sync + 'static { | ||
thread: Mutex<Option<JoinHandle<()>>>, | ||
thread: Option<JoinHandle<()>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since |
||
host_channel: Mutex<Sender<IoMessage<Message>>>, | ||
handlers: Arc<RwLock<Slab<Arc<IoHandler<Message>>>>>, | ||
} | ||
|
@@ -448,19 +448,19 @@ impl<Message> IoService<Message> where Message: Send + Sync + 'static { | |
IoManager::<Message>::start(&mut event_loop, h).expect("Error starting IO service"); | ||
}); | ||
Ok(IoService { | ||
thread: Mutex::new(Some(thread)), | ||
thread: Some(thread), | ||
host_channel: Mutex::new(channel), | ||
handlers: handlers, | ||
}) | ||
} | ||
|
||
pub fn stop(&self) { | ||
pub fn stop(&mut self) { | ||
trace!(target: "shutdown", "[IoService] Closing..."); | ||
// Clear handlers so that shared pointers are not stuck on stack | ||
// in Channel::send_sync | ||
self.handlers.write().clear(); | ||
self.host_channel.lock().send(IoMessage::Shutdown).unwrap_or_else(|e| warn!("Error on IO service shutdown: {:?}", e)); | ||
if let Some(thread) = self.thread.lock().take() { | ||
if let Some(thread) = self.thread.take() { | ||
thread.join().unwrap_or_else(|e| { | ||
debug!(target: "shutdown", "Error joining IO service event loop thread: {:?}", e); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
use std::sync::Arc; | ||
use std::thread::{JoinHandle, self}; | ||
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}; | ||
use crossbeam::sync::chase_lev; | ||
use deque; | ||
use service_mio::{HandlerId, IoChannel, IoContext}; | ||
use IoHandler; | ||
use LOCAL_STACK_SIZE; | ||
|
@@ -53,7 +53,7 @@ pub struct Worker { | |
impl Worker { | ||
/// Creates a new worker instance. | ||
pub fn new<Message>(index: usize, | ||
stealer: chase_lev::Stealer<Work<Message>>, | ||
stealer: deque::Stealer<Work<Message>>, | ||
channel: IoChannel<Message>, | ||
wait: Arc<Condvar>, | ||
wait_mutex: Arc<Mutex<()>>, | ||
|
@@ -75,8 +75,9 @@ impl Worker { | |
worker | ||
} | ||
|
||
fn work_loop<Message>(stealer: chase_lev::Stealer<Work<Message>>, | ||
channel: IoChannel<Message>, wait: Arc<Condvar>, | ||
fn work_loop<Message>(stealer: deque::Stealer<Work<Message>>, | ||
channel: IoChannel<Message>, | ||
wait: Arc<Condvar>, | ||
wait_mutex: Arc<Mutex<()>>, | ||
deleting: Arc<AtomicBool>) | ||
where Message: Send + Sync + 'static { | ||
|
@@ -91,8 +92,9 @@ impl Worker { | |
|
||
while !deleting.load(AtomicOrdering::Acquire) { | ||
match stealer.steal() { | ||
chase_lev::Steal::Data(work) => Worker::do_work(work, channel.clone()), | ||
_ => break, | ||
deque::Steal::Data(work) => Worker::do_work(work, channel.clone()), | ||
deque::Steal::Retry => {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was a bug, if worker lost the race for stealing data, it was incorrectly killed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The break is from the inner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure it's going to increase CPU usage, but should also improve performance, cause previously if a thread lost the race it would go to sleep vs re-trying and get the work done. If it went to sleep other threads had to finish whatever they were doing and then pick up the new task. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a case when |
||
deque::Steal::Empty => break, | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this method altogether, there's a default empty implementation in the
Engine
trait.