Comments (4)
I don't think this is in the http server. A simple qotd server is growing about 500 bytes per request. Source: https://github.com/kamalmarhubi/futures-rs/blob/qotd/mio/examples/qotd.rs
from futures-rs.
After @jvns showed me ltrace last night, we tracked down some leaking allocations and found that in fact the very first accept(listener)
allocation is never freed.
In both cases, the heap growth is from holding on to the initial accept(listener)
future, which is await
'ed. This future never completes: instead a chain of futures is created via join
, which grows with each request received. Using join
ensures we listen for the next request, but at the cost of making the current request's future not complete until the next request has. And so on.
It's easiest to see in the qotd example:
fn main() {
// ...
l.await(accept(listener)).unwrap();
}
fn accept(listener: TcpListener) -> Box<IoFuture<()>> {
listener.accept().and_then(move |(stream, _addr)| {
send_quote(stream)
.join(accept(listener)) // this is problematic!!
.map(|_| ())
.boxed()
}).boxed()
}
fn send_quote(stream: TcpStream) -> Box<IoFuture<()>> {
let quote = b"If I knew any quotes, I'd've put one here.".to_vec();
stream.write(0, quote).map(|_| ()).map_err(From::from).boxed()
}
I think the pub fn accept(&self) -> Box<IoFuture<(TcpStream, SocketAddr)>>
API is what is "wrong" here: wrapping this up in a future is conceptually nice but has issues. I'm experimenting with a replacement listening API like this:
impl Loop {
pub fn start_server<F>(&mut self, addr: &SocketAddr, cb: F)
-> io::Result<()>
where F: Fn(TcpStream, SocketAddr) -> Box<IoFuture<()>> + 'static
}
This works for the qotd server, keeping memory usage steady over at least sequential requests. (This wasn't true previously!) For the HTTP server, sequential requests have memory usage steady, but concurrent requests just don't work right now. I think I messed something up in socket registration.
from futures-rs.
All this is to say: the leak is not in the core futures lib!
from futures-rs.
Nice investigation! That definitely makes sense to me. Definitely a not-so-good design :)
I'll close this for now as it shouldn't affect the core futures lib and just the toy stuff I've been doing should probably change...
from futures-rs.
Related Issues (20)
- FuturesUnordered produces invalid reads and writes under Valgrind HOT 2
- Infinite loop caused by invalid UTF-8 bytes
- Potential unsoundness in FuturesUnordered HOT 2
- Peekable::try_peek HOT 1
- `futures_task::waker_ref()` is unsound
- `TryFlattenUnordered` doesn't impl `TryStream` HOT 1
- Provide `Deref{Mut}` implementation for `AllowStdIO`. HOT 1
- Document what features are required for feature-gated items HOT 1
- Warn when PR is opened for 0.3/0.1 branch HOT 4
- Feature request: impl std::iter::Extend<Fut> for FuturesUnordered HOT 1
- Analogue of .last() method
- parse error in `select!`/`select_biased!` macro HOT 2
- Error on OSX by futures-executir HOT 1
- Consider removing ArcWake, re-export std::task::Wake HOT 3
- Fine-tune the Ordering for num_senders
- Feature Request: make FuturesUnordered splitable.
- `FuturesUnordered` guaranties
- Unbounded memory use of `futures::channel::mpsc` with `SinkExt::feed`
- Question: futures-rs::channels implement Send trait HOT 1
- Non-send future produced by chaining `Stream` combinators HOT 1
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 futures-rs.