[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] responses delayed while using evhttp
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] responses delayed while using evhttp
- From: Julian Bui <julianbui@xxxxxxxxx>
- Date: Wed, 20 Jun 2012 09:09:47 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Wed, 20 Jun 2012 12:09:56 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=LnEJnDYB3qo8wwirg3HUq7bgMRT0FNsIGdsfIGCr3QY=; b=eu2C7+N1sTmySKVCBEHPg3R10ILs2ZwoYdNWJ1BBszI+3VpGHdIy8TjCRA38dRRJq8 xw4kb+cgkpLnTbdzuwu4C9ogCBvFRGxzKOQSRlQKqCsi17ZyI6DQAipsNegZssacO5HT +1Nykt41KoJ1mVEJjkuJGLCGUg/cZSVk/1RQp0MIf7h3IQFWArm54uEhJ6Nbr8kKYc9U DjxYW//8OBkAgdeqwWfh2VEdugtxeXwHhlOFLxxSAfw/FVw25K0bvQ2Lt5ypo5/9rOEe IoJlf/34CCsNv8/hxPY122nlvls+RmuI4iFz3k4Z48yui8hseUeX5JKYyhzreJGX1+Zj vzGw==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
Hi all,
I am having trouble sending HTTP replies/responses in a timely manner using evhttp.
PROBLEM:
If I call evhttp_send_reply in the gencb (callback that handles all requests), then my requests are sent out in a timely manner and everything is fine. However, I do some processing that will take a while so I don't want do the processing in this callback because it will hold up the dispatch loop and I think I won't be able to accept any connections while I'm doing this slow processing. Instead, when I get a request, I store the evhttp_request* off, and then hand it to a thread, and then return from the gencb. Later, when the processing is done, the original request's evhttp_request* is retrieved and used to send the response. However, the browser doesn't receive the response until exactly 10.0s later after the evhttp_send_reply was invoked, everytime...unless I call evhttp_send_reply from the gencb in the dispatch loop thread, in which case the browser gets the response immediately.
PSEUDOCODE:
*Dispatch loop thread*
::onGeneralRequest { 1. Store the evhttp_request, 2. Hand off the request to a worker thread, 3. return }
*Worker thread*
// do work that might take a few seconds
cout << "about to send reply" << endl;
evbuffer* resp_buf = evbuffer_new();
evbuffer_add_printf(resp_buf, "This is the body");
evhttp_send_reply(response.conn, 200, "bogus reason", resp_buf); // use the original evhttp_request* (response.conn), send a success message
cout << "sent reply" << endl; // at this point the browser still doesn't get the response, 10s in the future it will get it
QUESTIONS:
- Do I need to use evthread.h? I am using QThreads, part of the Qt library, so it looks like I need to implement and call three methods: 1) evthread_set_condition_callbacks, 2) evthread_set_id_callbacks, and 3) evthread_set_lock_callbacks. Do I just implement and call these methods and then everything will be fine? I don't need to tell the library to specifically use my custom threading library as long as I call these three methods? There's no other setup? After I set these methods all the threading/locking is transparent to me?
- Why does it seem like I can't send the reply from a different thread? The variables I'm using are local to the particular request and are not shared, so I don't see why there should be any problem. In other words, I don't expect that there would be any race conditions since the requests are isolated from each other (?)
- Any idea what this 10s delay is when I send the reply from a different thread?
Any feedback would be greatly appreciated.
Thanks,
-Julian