ruote, Sinatra and Thin

9 views
Skip to first unread message

gmcinnes

unread,
Jul 22, 2009, 3:25:44 PM7/22/09
to Ruote (OpenWFEru) users
Hmm, so I just wanted to alert people that I've been having major
speed issues with this combination, embedding a OpenWfe engine inside
a small sinatra app, using Thin as the web container.

There seems to be a pause of more than 30 seconds after the calling
the Sinatra #halt method (which should immediately render the response
to the client).

My code looks something like this:

configure do
# Do some configuration
set :engine, engine # <- This is a standard OpenWfe engine
instantiated by
# OpenWFE::Engine.new
(application_context) earlier in the initialization process

end

post '/patients/:patient_login/evaluations' do
workitem = OpenWFE::LaunchItem.new(PatientEvaluation)
# .....
# more things are added to the workitem
#
options.engine.launch(workitem)
halt 201, "Evaluation created"

# skipping exception handling
end

So, if I understand correctly, the engine should go off and do its
thing asynchronously and Sinatra should return
the 201 to the client immediately. This is the expected behaviour,
and indeed, what I see when using Mongrel or WEBrick as the webserver.

When using Thin, although the engine returns immediately, the halt
statement seems to be involved in a timeout before it returns - it
takes at least 30 seconds. If I add a :wait_for => true to the engine
launch, the process waits for the engine as expected, and still takes
at least 30 seconds to return.

I've tracked this down to the point in Thin's request handling cycle
where it passes off the response to EventMachine. When it does, the
process pauses. I haven't had time to look into this further yet, but
I thought I'd leave a message to let everyone know.

John Mettraux

unread,
Jul 22, 2009, 7:30:24 PM7/22/09
to openwfe...@googlegroups.com
On Thu, Jul 23, 2009 at 4:25 AM, gmcinnes<grant....@eyesopen.ca> wrote:
>
> (...)

>
> So, if I understand correctly, the engine should go off and do its
> thing asynchronously and Sinatra should return
> the 201 to the client immediately.  This is the expected behaviour,
> and indeed, what I see when using Mongrel or WEBrick as the webserver.
>
> When using Thin, although the engine returns immediately, the halt
> statement seems to be involved in a timeout before it returns - it
> takes at least 30 seconds.  If I add a :wait_for => true to the engine
> launch, the process waits for the engine as expected, and still takes
> at least 30 seconds to return.
>
> I've tracked this down to the point in Thin's request handling cycle
> where it passes off the response to EventMachine.  When it does, the
> process pauses.  I haven't had time to look into this further yet, but
> I thought I'd leave a message to let everyone know.

Hello Grant,

Very interesting. I'd like to try and reproduce the issue. Could you
please indicate the versions of the gems you are using ? (rack,
sinatra, thin, mongrel, ruote and also the ruby version).


Thanks in advance,

--
John Mettraux - http://jmettraux.wordpress.com

John Mettraux

unread,
Oct 6, 2009, 7:53:00 PM10/6/09
to openwferu-users
On Wed, Oct 7, 2009 at 1:04 AM, gmcinnes <grant....@eyesopen.ca> wrote:
>
> John, if you're still interested in this, I've finally found the time
> to break it out and create a minimal app that reproduces this. It's
> still happening with sinatra (0.9.2), ruote (0.9.20), thin (1.2.2).
> If you're interested, I can make it available however you prefer...
> just let me know.

Hello Grant,

I'm still interested. I will try your testcase on Snow Leopard with
ruby 1.8.7p72 unless told otherwise.

Meanwhile ruote is moving on :

http://github.com/jmettraux/ruote/tree/ruote2.0

There is an experiment with ruote 2.0 and sinatra at :

http://github.com/jmettraux/ruote-http

And Kenneth is working with sinatra as well :

http://github.com/kennethkalmer/ruote-kit


Looking forward to have a look at your test case. Best regards,

gmcinnes

unread,
Oct 7, 2009, 3:58:11 PM10/7/09
to ruote
Ok John. I'm using the same os / ruby, so you should see the
symptoms.

I've made the test app available on github at:
http://github.com/gmcinnes/Ruote--Sinatra--Thin-test-app

Run start_server.sh to start the thin server with ruote backing and
then in a different place run test.sh (requires curl) to fire off a
couple of requests to the thin server, and see the delays in question.
Obviously if you don't have curl you can fire off requests any other
way you find convenient, using the stuff in test.sh as a template.

Let me know if you have any questions. Probably I've done something
here to cause the problem, but I can't figure out what.

I had things isolated to the point where thin hands off the request to
EventMachine, and I know that ruote is using EM too, so I thought it
might be some conflict, but now I'm not so sure... when I investigated
today, I couldn't isolate that point.

Best of luck, and let me know how I can help.

Oh, and thanks! I have no idea how you get the time, but its much
appreciated!

Cheers,
-grant

On Oct 6, 7:53 pm, John Mettraux <jmettr...@openwfe.org> wrote:

John Mettraux

unread,
Oct 7, 2009, 10:14:34 PM10/7/09
to openwfe...@googlegroups.com
On Thu, Oct 8, 2009 at 4:58 AM, gmcinnes <grant....@eyesopen.ca> wrote:
>
> Let me know if you have any questions.  Probably I've done something
> here to cause the problem, but I can't figure out what.
>
> I had things isolated to the point where thin hands off the request to
> EventMachine, and I know that ruote is using EM too, so I thought it
> might be some conflict, but now I'm not so sure... when I investigated
> today, I couldn't isolate that point.

Hello Grant,

ruote 0.9.x is not using EM, ruote 2.0 uses it if present.

I've played with your test case for a while and could reproduce the
issue with ruote 0.9.21 (trunk).

Sinatra 0.9.4 with thin 1.2.4 on ruby 1.8.7p72.

With ruote "trunk" :

running test.sh takes 30s, 60s, 60s. Adding "nada" as the output of
the "post /process" runs with the same times.

With ruote 0.9.20

running test.sh triggers a few stack level too deep at the beginning,
but test.sh always replies in like 0.035s, consistently, and the
"stack level too deep" vanishes.

That's weird.

It took me a bit of back and forth, some time and now I'm wondering.
Since you've left the issue sleep for 2.5 months, is it necessary to
find a solution ?

Ruote 2.0 is coming along well and the integration with sinatra[/thin]
is promising :

http://github.com/jmettraux/ruote-http
http://github.com/kennethkalmer/ruote-kit


Best regards, thanks for the feedback,

gmcinnes

unread,
Oct 20, 2009, 6:08:27 PM10/20/09
to ruote
Absolutely not neccessary to find a solution. I'm using rackup to
drive the thing, and I just changed the server to mongrel. Works fine.

-g

On Oct 7, 10:14 pm, John Mettraux <jmettr...@openwfe.org> wrote:
Reply all
Reply to author
Forward
0 new messages