Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A sinatra app will work, but the {un}serializing, and the HTML parsing could impact performance compared to a DRb service.</p> <p>Here's an example, based on your example in the related question. I'm using a hash instead of an array so you can use user ids as indexes. This way there is no need to keep both a table on interests and a table of user ids on the server. Note that the interest table is "transposed" compared to your example, which is the way you want it anyways, so it can be updated in one call.</p> <pre><code># server.rb require 'drb' class InterestServer &lt; Hash include DRbUndumped # don't send the data over! def closest(cur_user_id) cur_interests = fetch(cur_user_id) selected_interests = cur_interests.each_index.select{|i| cur_interests[i]} scores = map do |user_id, interests| nb_match = selected_interests.count{|i| interests[i] } [nb_match, user_id] end scores.sort! end end DRb.start_service nil, InterestServer.new puts DRb.uri DRb.thread.join # client.rb uri = ARGV.shift require 'drb' DRb.start_service interest_server = DRbObject.new nil, uri USERS_COUNT = 10_000 INTERESTS_COUNT = 500 # Mock users users = Array.new(USERS_COUNT) { {:id =&gt; rand(100000)+100000} } # Initial send over user interests users.each do |user| interest_server[user[:id]] = Array.new(INTERESTS_COUNT) { rand(10) == 0 } end # query at will puts interest_server.closest(users.first[:id]).inspect # update, say there's a new user: new_user = {:id =&gt; 42} users &lt;&lt; new_user # This guy is interested in everything! interest_server[new_user[:id]] = Array.new(INTERESTS_COUNT) { true } puts interest_server.closest(users.first[:id])[-2,2].inspect # Will output our first user and this new user which both match perfectly </code></pre> <p>To run in terminal, start the server and give the output as the argument to the client:</p> <pre><code>$ ruby server.rb druby://mal.lan:51630 $ ruby client.rb druby://mal.lan:51630 [[0, 100035], ...] [[45, 42], [45, 178902]] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload