This is mainly for jruby. I''m trying to think of a way to spawn a thread that runs EM which handles a bunch of async http requests to another server. I''d like the main thread to be able to hand off data to be sent, and the EM thread pushes results onto an array that the main thread can read from. So far I can''t think of a way to make this work without calling EM.run for every http request. Any ideas? Chris
On 10/30/07, snacktime <snacktime at gmail.com> wrote:> > This is mainly for jruby. I''m trying to think of a way to spawn a > thread that runs EM which handles a bunch of async http requests to > another server. I''d like the main thread to be able to hand off data > to be sent, and the EM thread pushes results onto an array that the > main thread can read from. > > So far I can''t think of a way to make this work without calling EM.run > for every http request. Any ideas?Sounds like the problem is how to feed the data from the main thread to the EM thread. Why not open up a localhost TCP server in the EM thread and have the main thread send data to it? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20071030/c9911a09/attachment.html
> > > Sounds like the problem is how to feed the data from the main thread to the > EM thread. Why not open up a localhost TCP server in the EM thread and have > the main thread send data to it?So that''s what I ended up doing and it works well. We basically created an activerecord clone that can make async requests to backend services to retrieve data. Rails spins up a single thread that opens a localhost connection and goes into a select() loop waiting for results, and the controllers fire off the requests. Chris
On 11/2/07, snacktime <snacktime at gmail.com> wrote:> > > > > > Sounds like the problem is how to feed the data from the main thread to the > > EM thread. Why not open up a localhost TCP server in the EM thread and have > > the main thread send data to it? > > So that''s what I ended up doing and it works well. We basically > created an activerecord clone that can make async requests to backend > services to retrieve data. Rails spins up a single thread that opens > a localhost connection and goes into a select() loop waiting for > results, and the controllers fire off the requests. >How is the performance Chris? Sounds like a nice idea for couple of projects of my own. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org
> > How is the performance Chris? Sounds like a nice idea for couple of > projects of my own.Performance is great on the networking side. Right now 10 simultaneous requests take around 60ms. 1 request takes 4-5 ms. Most of the cumulative delay has nothing to do with the networking code though from what I can tell, it''s in other areas such as parsing/validation. Chris
Actually the performance issues were on the backend server I was hitting. 10 queries comes in around 5-7 ms. Chris On 11/2/07, snacktime <snacktime at gmail.com> wrote:> > > > How is the performance Chris? Sounds like a nice idea for couple of > > projects of my own. > > Performance is great on the networking side. Right now 10 > simultaneous requests take around 60ms. 1 request takes 4-5 ms. > Most of the cumulative delay has nothing to do with the networking > code though from what I can tell, it''s in other areas such as > parsing/validation. > > Chris >