-
Notifications
You must be signed in to change notification settings - Fork 177
Huge GC pressure when serving files with Cohttp_lwt_unix.Server.respond_file
#207
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
Comments
We should probably just be using |
I'm not especially knowledgeable on this, but for sure serving files is what sendfile(2) was made for. It would only help for plain (non-SSL) connections, which is an important limitation. There are a few complications though:
Regarding (2), after a quick look (this is the first time I look at cohttp's code, so take it with a grain This sounds quite involved, so for the time being simply allocating a string buffer and reusing it |
Another alternative would be to use |
We don't even need cstruct if we adopt core_kernel for every backend since |
Yeah. Anything that wraps We use |
I'd really prefer |
I second the preference for cstruct over core_kernel. |
@dbuenzli, @hcarty: The ecosystem could really use a common bigarray wrapper with zero-copy slicing and a few handy fixed-size extractor funs, that everybody agrees on. Like |
Cstruct now only optionally depends on camlp4 since 1.5.0, and has an adapter to Async. |
On Wed, Nov 26, 2014 at 09:54:52AM -0800, David Kaloper wrote:
I agree that cstructs (or even plain old 1-dimensional bigarrays, maybe with They are not a panacea however. For instance, non-mmapped bigarrays simply use Going back to the present issue, if Mauricio Fernández |
Cstructs are a minimal wrapping of bigarrays with offset/length! As for Re: imprecise deallocation and fragmentation.. I have no idea how it would play out. I think those questions are best answered by measurements. |
On Wed, Nov 26, 2014 at 11:55:11AM -0800, David Kaloper wrote:
I'm not very lucid today, what I meant was really non-opaque wrapping, for
We want to avoid allocation in This is why, when serving a file with Refer also to ocsigen/lwt#98 (as you can see I went
Allocating lots of bigarrays and hoping the GC will release them is just Mauricio Fernández |
It looks like a first move would be to request Lwt to have “allocation free” |
BTW, while we are at it, |
I've opened up #207 to track the IO.read comment -- it's helpful to keep these bug reports separate where possible. |
I'm thinking of implementing a trivial buffer pool to prevent allocation of large buffers (both This is the API I have in mind (as you can see in the Initially, I was going to just add the buffer pool to conduit, and then reuse it in cohttp and ocsigenserver (at some point, the API could be enriched and generalized, and split off to a separate package). One doubt I have is if it'd be acceptable to expose conduit's buffer pool (I mean the pool "value" itself, not the implementation) so that cohttp and ocsigenserver can reuse it, or if it'd be deemed better to have each one use its own internally (and without exposing it), while reusing the implementation, of course. In preliminary benchmarks of the ocsigenserver cohttp(_rebased) branch, I've seen it's between ~50% (for very small responses) and about as fast (slowdown going down as size increases, about ~ 5% for 16KB files) as stock ocsigenserver 2.6 (without any of the allocation prevention work mentioned earlier). I think the higher per-connection overhead can easily be explained by cohttp using 16KB buffers (vs. 4 KB in stock ocsigenserver). Also, regarding the precise problem that motivated this issue, it's similar to this one relative to ocsigenserver, so I'd expect about the same speed increase (>2X faster serving of large files) once addressed. This would build on the buffer pool work for extra effectiveness. |
respond_file
reads the file in 16 KB chunks usingLwt_io.read
. This allocates lots of 16 KB strings that go directly to the major heap and become garbage right away, and is bound to trigger major collection fests. See ocsigen/ocsigenserver#49 for an example of what can happen in a similar case...The text was updated successfully, but these errors were encountered: