Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large array in database won't load in rails view

I am trying to pull in data from an array into a view to form a chart. The array is stored in a database field and is very large. The array contains around 70k+ smaller arrays that look like this, [1234567890, 5]. Every time I try to render the data in a view it gets cut off. It never loads the full array so the page does not render. No errors are given. Any ideas of what may be causing this?

I am running Ruby 2.0.0-p195, Rails 3.2.13, Postgres 9.2

like image 651
user2272408 Avatar asked Nov 12 '22 03:11

user2272408


1 Answers

It's a pretty weird problem. It could be something timing out during fetching and just returning part of the data, depending on where it timed out.

What I'd check:

  • How is the memory usage doing? Does the result improves when I add ram?
  • Does it always gets cut off at the same point?
  • Do you get data in batch (find_each)? Try playing with the batch size.
  • Can the request itself be improved ?
  • If the rails logs are fine, try looking at nginx (or whatever you use)

If all options fail try loading this asynchronously by batch by doing multiple ajax calls.

like image 128
marcgg Avatar answered Nov 15 '22 04:11

marcgg