mysql - Rails controller action hanging -


i newbie in ruby/rails , have been breaking head problem past 2 days , hoping in forum can me out it.

i working on rails 4 , running application in production using passenger + nginx mysql database (mysql2 adapter). have following code in productscontroller.rb (log_info custom logging wrapper calls rails logger):

def index     log_info("productscontroller", "getting products...")     @products = product.get_products(params[:offset])     log_info("productscontroller", "got products...")      # populate access_url before sending data through     update_products_with_access_url(@products) end 

here definition of get_products function inside product model:

def self.get_products(products_offset)     products_offset ||= 0      product.includes(:categories, :suppliers).             where(active: true).order(updated_at: :desc).             limit(20).             offset(products_offset * 20) end 

the problem application hangs in production (works fine in dev) few mins when index action called. behaviour happening half time - works fine other half of time.

i can see in log action has been called not getting executed. here snippet log file:

i, [2015-06-10t13:31:01.802673 #14916]  info -- : processing productscontroller#index html i, [2015-06-10t13:33:09.718339 #14916]  info -- : [info][2015-06-10 13:33:09 utc][productscontroller][getting products...] i, [2015-06-10t13:33:09.719365 #14916]  info -- : [info][2015-06-10 13:33:09 utc][productscontroller][got products...] d, [2015-06-10t13:33:09.720980 #14916] debug -- :   product load (0.8ms)  select  `products`.* `products` `products`.`active` = 1  order `products`.`updated_at` desc limit 12 offset 0 d, [2015-06-10t13:33:09.725110 #14916] debug -- :   productcategory load (0.5ms)  select `product_categories`.* `product_categories` `product_categories`.`product_id` in (30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19) 

as can see there difference of @ least 2 mins between first 2 lines of log file above. , log shows index action had received call, not sure why taking long (sometimes more 5 mins.) execute first line in index action. suspect there kind of caching happening. earlier thinking call might hanging in connecting mysql database, not sure. missing here?

can please me out in fixing application hang issue?

please check if there before filters, quite can reason of such hangs.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -