[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] Zero-copy http client?



Hi there,

I have a feature request for the http client facility, or at least a request for advice if there's already a way to do what I want.

Profiling my application which uses libevent's http client piece to make a large number of GET requests for fairly large amounts of data I see the majority of the process's time is spent in memcpy.

Right now libevent is conveniently taking care of the reading and buffering of data from the remote host. After the request callback is invoked I copy out of the buffer into my internal storage. I would like to avoid that extra copy by having libevent allocate and read directly into my internal storage.  This should be possible once the headers and Content-Length has been parsed.

I don't see a way to do this with the API as it is right now. evhttp_read_body uses the request's bufferevent's input buffer to do the work,  this is doing its own allocations, and once it's complete and the done callback is invoked, one can copy out of the evbuffer.

Perhaps one way to accomplish this would be to have a way to assign allocate/done callbacks to an existing bufferevent. The 'allocate' callback could get passed a requested size and a user-assignable argument, and return a pointer to a region of memory. Then after the initial request has been created, I could go in and set these callbacks for the specific storage my request needs to go into. When the http request is finished reading, it could similarly call a 'done' callback.

Thoughts?

Ryan