ruby-on-railslogging

How to calculate time taken for request to be served in rails?


I want to calculate the time taken by application to serve a particular request. i.e.. difference between the time the request comes to the server and time the server responded with response back

In c#, we have something called Global.ascx in which we have the functions like Application_BeginRequest and Application_EndRequest which can be used for this purpose.

Similarly does rails contains these types of functions where I can record the request timings?


Solution

  • Rails will by default log the time taken to serve each request. These logs go to the console and log/development.log if you're running a development server, and to wherever you have your production logs configured to go in production mode.

    You're looking for a line that reads something like:

    Completed 200 OK in 16ms (Views: 6.2ms | ActiveRecord: 1.8ms)
    

    If you need to measure something more granular than the entire request you could start with the guide on instrumentation: https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller.