Slow Performance in Heroku during Grape::Middleware::Formatter.call

894 views
Skip to first unread message

ad...@keenwawa.com

unread,
Nov 11, 2014, 5:11:58 PM11/11/14
to ruby-...@googlegroups.com
Hi all,

I am noticing some odd behavior with Grape in Heroku. Requests are coming back extremely slowly and New Relic tells me that Grape::Middleware::Formatter.call requests are the key source of the problem. Unfortunately my version of New Relic doesn't give me deeper detail, but Grape middle-ware only calls are taking up to 500ms to execute. This is with DB hits, application code, and other externalities removed in reporting.

A couple extra points:
- This behavior does not occur on my local development machine (a recent macbook pro).
- The Gemfile.lock is identical on my local dev machine and on Heroku (it is attached).
- I'm using Unicorn.
- I've locked my version of Rails (principally used for ActiveRecord) and Ruby.
- I am running two Heroku 2x dynos (1g of ram)
- Heroku and New Relic report that memory is holding stable about about 40% of the available and that the CPU is not going wild.

I'm at a bit of a loss to explain what's happening. Does anyone have any insight into this?

Best regards,
Adam Hiatt
Gemfile.lock

ad...@keenwawa.com

unread,
Nov 11, 2014, 9:25:10 PM11/11/14
to ruby-...@googlegroups.com
I found another person on Stackoverflow who has the same issue, but there is no resolution their either:

Daniel Doubrovkine

unread,
Nov 12, 2014, 6:58:53 AM11/12/14
to ruby-...@googlegroups.com
First, identify which formatter is being used. I am going to guess you're returning JSON, so this is https://github.com/intridea/grape/blob/master/lib/grape/formatter/json.rb.

This is what it does:

return object.to_json if object.respond_to?(:to_json)
MultiJson.dump(object)

Move this part into your API to debug, explicitly call 'to_json' on whatever your API is returning and shortcut the formatter by doing the following:

formatter :json, lambda { |object, env| object }

(this will prevent a call to to_json twice).

This should help you debug.





--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages