Created
April 25, 2013 15:37
-
-
Save pantulis/5460679 to your computer and use it in GitHub Desktop.
Prueba de carga en CouchDB y búsqueda por tags en ElasticSearch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'rubygems' | |
require 'json/ext' | |
require 'couchrest' | |
require 'tire' | |
require 'yajl/json_gem' | |
require 'faker' | |
class ElasticSearchTest | |
attr_accessor :num_items, :num_packs | |
TAGS = %w(tag1 tag2 tag3 tag4 tag5 tag6 tag7 tag8 tag9 tag10 tag11) | |
def initialize(num_packs, num_items = 25) | |
@num_items = num_items | |
@num_packs = num_packs | |
end | |
def random_tags | |
len = rand(TAGS.length-6) | |
TAGS.shuffle[0..len] | |
end | |
def setup | |
db = CouchRest.database("http://127.0.0.1:5984/couchdb-test") | |
@count = 0 | |
for n in 1..@num_packs | |
elems = [] | |
for m in 1..@num_items | |
elems << { :name => Faker::Name.name, :tags => random_tags(), :created_at => Time.now() } | |
end | |
response = db.bulk_save(elems) | |
end | |
end | |
def run tags | |
s = Tire.search 'couchdb-test' do | |
for tag in tags do | |
filter :terms, :tags => [ tag ] | |
#query do | |
# string "name:*#{tag}*" | |
#end | |
end | |
from "1" | |
size "1000" | |
end | |
s.sort {by :created_at, 'desc'} | |
s.results | |
end | |
def debug_results(items) | |
for i in items | |
puts "(#{i[:created_at]}) :" + i[:name] + " " + i[:tags].to_s | |
end | |
end | |
end | |
include Benchmark | |
[[1,100], [100, 1000], [1000,1000]].each do |packs, items| | |
test = ElasticSearchTest.new(packs,items) | |
ts = Benchmark.realtime { test.setup } | |
tr = Benchmark.realtime { @results = test.run(['tag1','tag3','tag2','tag4']) } | |
test.debug_results(@results) | |
puts "#{packs*items} (#{packs} * #{items}) = #{ts} + #{tr} = #{tr+ts} (resultados = #{@results.total})" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment