Skip to content

Instantly share code, notes, and snippets.

@jtoy
Created February 16, 2012 12:28

Revisions

  1. jtoy created this gist Feb 16, 2012.
    61 changes: 61 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    require 'rsolr'
    require 'thread'
    require "optparse"

    $opts = {}

    Thread.abort_on_exception = true

    threads = []
    $q = Queue.new

    OptionParser.new do |o|
    o.on("-u","--url URL","url") do |u|
    $opts[:url] = u
    end
    o.parse!
    end

    (25).times do |t|
    threads << Thread.new do
    puts
    s = RSolr.connect(:url => $opts[:url])
    while true
    a = $q.pop
    retry_count = 0
    if a
    begin
    s.add a
    rescue Exception => e
    puts e
    end
    end
    end
    end
    end

    s = "this is a long string " * 10000
    a = []
    1_000_000_000.times do |i|
    while $q.size > 100
    puts "sleeping, q size: #{$q.size} i:#{i}"
    sleep 1
    end
    doc = {}
    doc["id"] = i
    doc["false_b"] = false
    doc["true_b"] = true
    doc["description_text"] = s
    doc["indexed_at_dt"] = Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
    a << doc
    if i % 25 == 0 && i != 0
    puts i
    $q << a
    a = []
    end
    end

    while $q.length > 0 do
    sleep 1
    puts "#{$q.length}"
    end