List Info

Thread: using eventmachine from rails




using eventmachine from rails
country flaguser name
Canada
2007-03-01 09:09:09
I've got a need to use eventmachine in two different ways
and use it from a rails app.

1. Use eventmachine to do a non-blocking POST to a website.
2. Use eventmachine as a server that manages some client
programs that connect to it.  Have the rails app provide an
interface to the client server.

I don't suppose I can just stick something like this in a
controller/model file?  (And similar for the POST)

EventMachine::run {
  EventMachine::start_server "127.0.0.1", 8081,
ClientServer
}

Any tips you can provide would be greatly helpful!  My
rubyfu is still weak so I'm drawing a blank here.

Thank you
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Re: using eventmachine from rails
country flaguser name
Canada
2007-03-01 10:07:48
I figured out an easy way to do a non-blocking post from
rails.

`curl -d "parameterstring" http://site &`

But I'm still very curious about the second part, running a
standalone eventmachine server yet interacting with it from
the rails app.

On Thu, 1 Mar 2007 08:09:09 -0700
James Robey <jrobeystripemobile.com> wrote:

> I've got a need to use eventmachine in two different
ways and use it from a rails app.
> 
> 1. Use eventmachine to do a non-blocking POST to a
website.
> 2. Use eventmachine as a server that manages some
client programs that connect to it.  Have the rails app
provide an interface to the client server.
> 
> I don't suppose I can just stick something like this in
a controller/model file?  (And similar for the POST)
> 
> EventMachine::run {
>   EventMachine::start_server "127.0.0.1",
8081, ClientServer
> }
> 
> Any tips you can provide would be greatly helpful!  My
rubyfu is still weak so I'm drawing a blank here.
> 
> Thank you
> _______________________________________________
> Eventmachine-talk mailing list
> Eventmachine-talkrubyforge.org
> http://rubyforge.org/mailman/listinfo/eventmachine-talk
> 
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Re: using eventmachine from rails
user name
2007-03-01 10:26:15
"Non-blocking" does not necessarily mean
"non-error checking" - unless
you really want to forego it (as your example below does).

Best regards,

--Michael

On 3/1/07, James Robey <jrobeystripemobile.com>
wrote:
> I figured out an easy way to do a non-blocking post
from rails.
>
> `curl -d "parameterstring" http://site &`
>
> But I'm still very curious about the second part,
running a standalone eventmachine server yet interacting
with it from the rails app.
>
> On Thu, 1 Mar 2007 08:09:09 -0700
> James Robey <jrobeystripemobile.com>
wrote:
>
> > I've got a need to use eventmachine in two
different ways and use it from a rails app.
> >
> > 1. Use eventmachine to do a non-blocking POST to a
website.
> > 2. Use eventmachine as a server that manages some
client programs that connect to it.  Have the rails app
provide an interface to the client server.
> >
> > I don't suppose I can just stick something like
this in a controller/model file?  (And similar for the
POST)
> >
> > EventMachine::run {
> >   EventMachine::start_server
"127.0.0.1", 8081, ClientServer
> > }
> >
> > Any tips you can provide would be greatly helpful!
 My rubyfu is still weak so I'm drawing a blank here.
> >
> > Thank you
> > _______________________________________________
> > Eventmachine-talk mailing list
> > Eventmachine-talkrubyforge.org
> > http://rubyforge.org/mailman/listinfo/eventmachine-talk
> >
> _______________________________________________
> Eventmachine-talk mailing list
> Eventmachine-talkrubyforge.org
> http://rubyforge.org/mailman/listinfo/eventmachine-talk
>
>
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Re: using eventmachine from rails
country flaguser name
Canada
2007-03-01 11:04:51
Yeah in this particular case, I'm not concerned about error
checking.

I've figured out a ruby way to do it:

Thread.new { WWW::Mechanize.new().post("http://site", paramsend)
}

On Thu, 1 Mar 2007 08:26:15 -0800
"Michael S. Fischer" <michaeldynamine.net> wrote:

> "Non-blocking" does not necessarily mean
"non-error checking" - unless
> you really want to forego it (as your example below
does).
> 
> Best regards,
> 
> --Michael
> 
> On 3/1/07, James Robey <jrobeystripemobile.com>
wrote:
> > I figured out an easy way to do a non-blocking
post from rails.
> >
> > `curl -d "parameterstring" http://site &`
> >
> > But I'm still very curious about the second part,
running a standalone eventmachine server yet interacting
with it from the rails app.
> >
> > On Thu, 1 Mar 2007 08:09:09 -0700
> > James Robey <jrobeystripemobile.com>
wrote:
> >
> > > I've got a need to use eventmachine in two
different ways and use it from a rails app.
> > >
> > > 1. Use eventmachine to do a non-blocking POST
to a website.
> > > 2. Use eventmachine as a server that manages
some client programs that connect to it.  Have the rails app
provide an interface to the client server.
> > >
> > > I don't suppose I can just stick something
like this in a controller/model file?  (And similar for the
POST)
> > >
> > > EventMachine::run {
> > >   EventMachine::start_server
"127.0.0.1", 8081, ClientServer
> > > }
> > >
> > > Any tips you can provide would be greatly
helpful!  My rubyfu is still weak so I'm drawing a blank
here.
> > >
> > > Thank you
> > >
_______________________________________________
> > > Eventmachine-talk mailing list
> > > Eventmachine-talkrubyforge.org
> > > http://rubyforge.org/mailman/listinfo/eventmachine-talk
> > >
> > _______________________________________________
> > Eventmachine-talk mailing list
> > Eventmachine-talkrubyforge.org
> > http://rubyforge.org/mailman/listinfo/eventmachine-talk
> >
> >
> _______________________________________________
> Eventmachine-talk mailing list
> Eventmachine-talkrubyforge.org
> http://rubyforge.org/mailman/listinfo/eventmachine-talk
> 
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Re: using eventmachine from rails
user name
2007-03-02 11:01:13
On 3/1/07, James Robey < jrobeystripemobile.com">jrobeystripemobile.com> wrote:
Yeah in this particular case, I'm not concerned about error checking.

I've figured out a ruby way to do it:

Thread.new { WWW::Mechanize.new().post("http://site", paramsend) }


Sounds like you have solutions to your problems. For future reference, there is an EM HTTP client intended for use within servers (such as when a server needs to make a REST request somewhere else). It has some limitations which we're working on. (See the recent threads from Tony Arcieri on this list.)

The problem with Rails is always that it's not thread-safe. It's probably not the best idea to try to embed advanced systems into a Rails app. You can always do it outboard, though. I'd be hesitant to try to make Rails do things it's not good at.

Re: using eventmachine from rails
country flaguser name
Canada
2007-03-02 11:47:12
Actually I'm still trying to figure out how to have my rails
app manage several client programs that expect to be able to
connect to a port and communicate via that.  I was told EM
would be good for that, so I'm wondering how to integrate EM
into the rails app.

Would I be able to run EM from within rails somehow? Or
would I have to use something like backgroundrb? (apparently
it provides messaging capabilities)

 
On Fri, 2 Mar 2007 12:01:13 -0500
"Francis Cianfrocca" <garbagecat10gmail.com> wrote:

> On 3/1/07, James Robey <jrobeystripemobile.com>
wrote:
> >
> > Yeah in this particular case, I'm not concerned
about error checking.
> >
> > I've figured out a ruby way to do it:
> >
> > Thread.new { WWW::Mechanize.new().post("http://site", paramsend)
}
> 
> 
> 
> Sounds like you have solutions to your problems. For
future reference, there
> is an EM HTTP client intended for use within servers
(such as when a server
> needs to make a REST request somewhere else). It has
some limitations which
> we're working on. (See the recent threads from Tony
Arcieri on this list.)
> 
> The problem with Rails is always that it's not
thread-safe. It's probably
> not the best idea to try to embed advanced systems into
a Rails app. You can
> always do it outboard, though. I'd be hesitant to try
to make Rails do
> things it's not good at.
> 
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Re: using eventmachine from rails
user name
2007-03-02 13:17:08
Not really enough information to make a coherent suggestion. The thought that comes immediately to mind is to "manage the several client programs&quot; (whatever that means) from a standalone EM application that accepts connections from the Rails app.

You can easily run an EM event loop from a Rails handler but I don't see what good it does you. Rails is always single threaded so you have to start and stop the EM loop before you can feed a result back into Rails.

Unless you're thinking that *each* individual Rails request needs to access a bunch of different client programs and aggregate the results. EM might be a very good fit for that.

On 3/2/07, James Robey < jrobeystripemobile.com">jrobeystripemobile.com> wrote:
Actually I'm still trying to figure out how to have my rails app manage several client programs that expect to be able to connect to a port and communicate via that. ; I was told EM would be good for that, so I'm wondering how to integrate EM into the rails app.

Would I be able to run EM from within rails somehow? Or would I have to use something like backgroundrb? (apparently it provides messaging capabilities)


On Fri, 2 Mar 2007 12:01:13 -0500
&quot;Francis Cianfrocca" < garbagecat10gmail.com">garbagecat10gmail.com> wrote:

&gt; On 3/1/07, James Robey < jrobeystripemobile.com">jrobeystripemobile.com> wrote:
>; >
> > Yeah in this particular case, I'm not concerned about error checking.
> >
> > I've figured out a ruby way to do it:
> >
> > Thread.new { WWW::Mechanize.new().post("http://site", paramsend) }
>
>;
>
&gt; Sounds like you have solutions to your problems. For future reference, there
> is an EM HTTP client intended for use within servers (such as when a server
>; needs to make a REST request somewhere else). It has some limitations which
&gt; we're working on. (See the recent threads from Tony Arcieri on this list.)
>;
> The problem with Rails is always that it's not thread-safe. It's probably
&gt; not the best idea to try to embed advanced systems into a Rails app. You can
> always do it outboard, though. I'd be hesitant to try to make Rails do
> things it's not good at.
>
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org"> Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Re: using eventmachine from rails
user name
2007-03-02 16:37:24
I started out with exactly the same problem (EM does ---
let's just
say --- LDAP for me, and handles demand-queries from Rails
actions).

I have two solutions, neither optimal:

1. BackgrounDrb, with EM queuing up Marshalled Ruby objects
and then
doing its own dispatch.

2. Just serializing objects in Rails myself, blitting them
out to a
localhost socket EM listens on, and having the EM server
dump results
into ActiveRecord.

What sucks about 1 is Drb, which is a synchronous API; I had
to go
into the guts of its marshalling code to figure out how to
fake out
the server stubs from EM.

What sucks about 2 is that it's not really safe to have EM
dump
results to a database, SQLite or otherwise, because on most
systems
(1) the filesystem IO is blocking and can stall the event
loop and (2)
the SQL interface is blocking, etc etc.

The "best" answer to this question is probably
"use YAML to do
lightweight messaging over HTTP POST to EM, and have EM POST
back the
results to another Rails action".

I am amused by, and share, Francis' opinion of Rails as
primitive, at
least in scalability/concurrency terms. On the other hand,
Twisted is
extremely advanced and its API is a debacle.

I would love to see some kind of agreement about what the
"Right" way
is to interface an EM loop to Rails is, and then a shared
effort to
come up with one extensible implementation of that way.

On 3/2/07, James Robey <jrobeystripemobile.com>
wrote:
> Actually I'm still trying to figure out how to have my
rails app manage several client programs that expect to be
able to connect to a port and communicate via that.  I was
told EM would be good for that, so I'm wondering how to
integrate EM into the rails app.
>
> Would I be able to run EM from within rails somehow? Or
would I have to use something like backgroundrb? (apparently
it provides messaging capabilities)
>
>
> On Fri, 2 Mar 2007 12:01:13 -0500
> "Francis Cianfrocca" <garbagecat10gmail.com> wrote:
>
> > On 3/1/07, James Robey <jrobeystripemobile.com> wrote:
> > >
> > > Yeah in this particular case, I'm not
concerned about error checking.
> > >
> > > I've figured out a ruby way to do it:
> > >
> > > Thread.new {
WWW::Mechanize.new().post("http://site", paramsend)
}
> >
> >
> >
> > Sounds like you have solutions to your problems.
For future reference, there
> > is an EM HTTP client intended for use within
servers (such as when a server
> > needs to make a REST request somewhere else). It
has some limitations which
> > we're working on. (See the recent threads from
Tony Arcieri on this list.)
> >
> > The problem with Rails is always that it's not
thread-safe. It's probably
> > not the best idea to try to embed advanced systems
into a Rails app. You can
> > always do it outboard, though. I'd be hesitant to
try to make Rails do
> > things it's not good at.
> >
> _______________________________________________
> Eventmachine-talk mailing list
> Eventmachine-talkrubyforge.org
> http://rubyforge.org/mailman/listinfo/eventmachine-talk
>
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

Re: using eventmachine from rails
user name
2007-03-02 17:22:18
On 3/2/07, Thomas Ptacek < tqbfmatasano.com">tqbfmatasano.com> wrote:
I started out with exactly the same problem (EM does --- let's just
say --- LDAP for me, and handles demand-queries from Rails actions).

I have two solutions, neither optimal:

1. BackgrounDrb, with EM queuing up Marshalled Ruby objects and then
doing its own dispatch.

2. Just serializing objects in Rails myself, blitting them out to a
localhost socket EM listens on, and having the EM server dump results
into ActiveRecord.

What sucks about 1 is Drb, which is a synchronous API; I had to go
into the guts of its marshalling code to figure out how to fake out
the server stubs from EM.

What sucks about 2 is that it's not really safe to have EM dump
results to a database, SQLite or otherwise, because on most systems
(1) the filesystem IO is blocking and can stall the event loop and (2)
the SQL interface is blocking, etc etc.

The "best" answer to this question is probably "use YAML to do
lightweight messaging over HTTP POST to EM, and have EM POST back the
results to another Rails action&quot;.

I am amused by, and share, Francis9; opinion of Rails as primitive, at
least in scalability/concurrency terms. On the other hand, Twisted is
extremely advanced and its API is a debacle.

I would love to see some kind of agreement about what the "Right" way
is to interface an EM loop to Rails is, and then a shared effort to
come up with one extensible implementation of that way.

On 3/2/07, James Robey < jrobeystripemobile.com">jrobeystripemobile.com> wrote:
>; Actually I'm still trying to figure out how to have my rails app manage several client programs that expect to be able to connect to a port and communicate via that. ; I was told EM would be good for that, so I'm wondering how to integrate EM into the rails app.


I'm starting to get interested again in the idea of  doing an event-driven implementation of the DBMS protocols. We know that postgres has been done in pure Ruby so maybe this isn't as hubristic as it sounds.

How about running Rails *inside* an EM event loop? You're always stuck with Rails being single-threaded, meaning in this case that if you kick off some high-latency operation (like a DB call or a REST call to some external server), and then try to dispatch another Rails request while waiting for the first one to complete, Rails will probably become very angry. Although I don't know that for sure! EM's Deferrable (identical conceptually to Twisted9;s Deferred) can easily handle this kind of thing without threads, and it would be worth seeing if Rails can tolerate it.

Kirk may have the ultimate answer: use EM to build a clustering proxy and run it in front of multiple single-threaded Rails processes, all of which will block while handling each request.

Re: using eventmachine from rails
user name
2007-03-02 17:26:32
On 3/2/07, Francis Cianfrocca <garbagecat10gmail.com> wrote:

> Kirk may have the ultimate answer: use EM to build a
clustering proxy and
> run it in front of multiple single-threaded Rails
processes, all of which
> will block while handling each request.

See also HAProxy <http://haproxy.1wt.eu> if you don't need to reinvent
the wheel.

--Michael
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-talkrubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk

[1-10] [11-20] [21-30] [31-40] [41-50] [51-59]

about | contact  Other archives ( Real Estate discussion Medical topics )