0

I inserted a recommendation system in my program. An important part of the algorithm is to find the similarity between users and for this I have much access to the database. For this reason I was thinking of keeping a few things in memory, for example a Hash attribute that would be started every time I turned the server on and update that Hash from time to time ...

Class User 
  ... 
  def init
    User.all.each {| user |similarity [user.id] similarity_with (user)} 
  end 
  ... 
end 

The big problem is that I do not know how to do (if there is any callback) for when I turn the server on to initialize the attribute and how do I do it to update it from time to time ... I'd better create a similarity $matrix[user][user] to the program rather than per user attribute ??

Searching the database is taking too long, so I want to keep enough memory thing ... Thanks!

2
  • 6
    If the question is how to keep data in memory in between requests or even Ruby processes, you will need to use something like Redis or Memcached.
    – Sergey
    Aug 14, 2014 at 22:44
  • Consider what will happen if your system turns out to be a major hit, and you have millions of users. Keeping data in memory the way you're headed will cause a big slowdown as the program starts and you build the cache, and it'll kill your database and network I/O. As @Sergey says, use something external to your code that is designed and optimized for caching data, and put that on a separate machine. Aug 15, 2014 at 17:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.