Comments (2)
Why not use async? (It should already have the proper mechanisms to handle such cases.)
if e.kind() == std::io::ErrorKind::WouldBlock { dbg!("zzz"); backoff.snooze();
It does not seem desirable to do an unbounded spin loop if OS returns WouldBlock.
from crossbeam.
That's what we have been using, but we have realised that async in our code-base was a mistake, and we are migrating away from it.
What we ended up doing, for now, is this:
pub struct BootstrapTcpListener {
poll: Poll,
events: Events,
server: TcpListener,
// HACK : create variable to move ownership of mio_server to the thread
// if mio_server is not moved, poll does not receive any event from listener
_mio_server: MioTcpListener,
}
pub enum PollEvent {
NewConnection((TcpStream, SocketAddr)),
Stop,
}
impl BSEventPoller for BootstrapTcpListener {
fn poll(&mut self) -> Result<PollEvent, BootstrapError> {
self.poll.poll(&mut self.events, None).unwrap();
// Confirm that we are not being signalled to shut down
if self.events.iter().any(|ev| ev.token() == STOP_LISTENER) {
return Ok(PollEvent::Stop);
}
// Ther could be more than one connection ready, but we want to re-check for the stop
// signal after processing each connection.
return Ok(PollEvent::NewConnection(
self.server.accept().map_err(BootstrapError::from)?,
));
}
}
impl BootstrapListenerStopHandle {
/// Stop the bootstrap listener.
pub fn stop(self) -> Result<(), BootstrapError> {
self.0.wake().map_err(BootstrapError::from)
}
}
...and in the main event loop of the server, instead of using std::net::TcpListener::accept(...)?
, we use our poll and match on the return enum.
Previously we would have a dedicated listener thread, and two crossbeam channels, one for a connection, one for a stop-signal broadcast:
loop {
let conn = select! {
recv(stopper_rx) -> _ => return Ok(()),
recv(conn_rx) -> conn => conn,
};
// ...validate connection before dispatching to a system-thread to handle
}
What the change meant is that we no longer have a need for a dedicated listener thread, or a buffer of connections.
I see that my "MVP" is probably a bad label, and probably a distraction.
from crossbeam.
Related Issues (20)
- Can we avoid to call `try_advance` in some senarios? [crossbeam-epoch] HOT 2
- Epoch memory reclamation algorithm HOT 2
- consider adding `is_disconnected` method to Receiver type HOT 1
- Scaling receiver counter up/down based on demand
- `select!` macro and auto-complete HOT 1
- [crossbeam-epoch] false sharing issue for "epoch: AtomicEpoch" field in "Local" struct
- crossbeam-skiplist bug HOT 3
- epoch `fetch_update` not working as expected HOT 2
- Crossbeam channel slower than Go channels with input data delay HOT 5
- Questions about "crossbeam_epoch" HOT 10
- crossbeam channel is very slow if restricted to a single core HOT 4
- crossbeam-deque has no blocking pop: how do you use it?
- Semantic one-shot channel HOT 3
- Publish new `crossbeam-epoch` with updated `memoffset` HOT 2
- crossbeam_channel::tick delivery_time can support different flavor HOT 4
- what shuld used for AtomicCell or ShardedLock HOT 1
- Cirrus CI no longer supports 32-bit mode on ARM Linux runners
- Always use load(Acquire) for load_consume on Miri/TSan
- Question (epoch): How to avoid Miri to report data race on an `Atomic` pointer? HOT 6
- crossbeam::channel::Receiver::try_recv can block forever if sending thread is blocked HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crossbeam.