Skip to content

Instantly share code, notes, and snippets.

@jtoy
Created February 16, 2012 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtoy/1844519 to your computer and use it in GitHub Desktop.
Save jtoy/1844519 to your computer and use it in GitHub Desktop.
this eats up all the memory on rsolr
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment