|
1 | 1 | require 'spec_helper'
|
| 2 | +require 'ruby-prof' |
2 | 3 |
|
3 |
| -describe "Wordnik performance" do |
4 |
| - configure_wordnik |
5 |
| - words = File.open(File.dirname(__FILE__) + "/100words.txt").readlines.map{|w| w.strip} |
6 |
| - start_time = Time.now |
7 |
| - Wordnik.logger.debug "Starting at #{start_time}" |
8 |
| - found = 0 |
9 |
| - defs = 0 |
10 |
| - examples = 0 |
11 |
| - words.each do |word| |
12 |
| - found += 1 if Wordnik.word.get_word(word)["id"]==0 |
13 |
| - defs += Wordnik.word.get_definitions(word).size |
14 |
| - examples += Wordnik.word.get_examples(word).size |
| 4 | +describe "Load Balancer Performance" do |
| 5 | + |
| 6 | + describe "With single host -- host performance" do |
| 7 | + Wordnik.configuration.clear |
| 8 | + Wordnik.configure do |config| |
| 9 | + config.api_key = CREDENTIALS[:api_key] |
| 10 | + config.username = CREDENTIALS[:username] |
| 11 | + config.password = CREDENTIALS[:password] |
| 12 | + config.logger = Logger.new('/dev/null') |
| 13 | + config.host = CREDENTIALS[:host] = 'api.wordnik.com' |
| 14 | + config.hosts = [] |
| 15 | + config.base_path = CREDENTIALS[:base_path] || '/v4' |
| 16 | + end |
| 17 | + start_time = Time.now |
| 18 | + RubyProf.start |
| 19 | + 100000.times {|i| host = Wordnik.configuration.host} |
| 20 | + result = RubyProf.stop |
| 21 | + printer = RubyProf::FlatPrinter.new(result) |
| 22 | + printer.print(STDOUT) |
| 23 | + end |
| 24 | + |
| 25 | + describe "With multiple hosts -- host performance" do |
| 26 | + Wordnik.configuration.clear |
| 27 | + Wordnik.configure do |config| |
| 28 | + config.api_key = CREDENTIALS[:api_key] |
| 29 | + config.username = CREDENTIALS[:username] |
| 30 | + config.password = CREDENTIALS[:password] |
| 31 | + config.logger = Logger.new('/dev/null') |
| 32 | + config.host = CREDENTIALS[:host] = 'api.wordnik.com' |
| 33 | + config.hosts = CREDENTIALS[:hosts] || ['ec2-50-18-25-12.us-west-1.compute.amazonaws.com',' ec2-50-18-67-92.us-west-1.compute.amazonaws.com'] |
| 34 | + config.base_path = CREDENTIALS[:base_path] || '/v4' |
| 35 | + end |
| 36 | + start_time = Time.now |
| 37 | + RubyProf.start |
| 38 | + 100000.times {|i| host = Wordnik.configuration.host} |
| 39 | + result = RubyProf.stop |
| 40 | + printer = RubyProf::FlatPrinter.new(result) |
| 41 | + printer.print(STDOUT) |
15 | 42 | end
|
16 |
| - total = Time.now - start_time |
17 |
| - Wordnik.logger.debug "Found #{found} words out of #{words.size}; #{defs} definitions; #{examples} examples in #{total} milliseconds" |
| 43 | + |
18 | 44 | end
|
| 45 | + |
| 46 | + describe "Wordnik GET performance" do |
| 47 | + |
| 48 | + describe "With single host" do |
| 49 | + RubyProf.start |
| 50 | + Wordnik.configuration.clear |
| 51 | + Wordnik.configure do |config| |
| 52 | + config.api_key = CREDENTIALS[:api_key] |
| 53 | + config.username = CREDENTIALS[:username] |
| 54 | + config.password = CREDENTIALS[:password] |
| 55 | + config.logger = Logger.new('/dev/null') |
| 56 | + config.host = CREDENTIALS[:host] = 'api.wordnik.com' |
| 57 | + config.hosts = [] |
| 58 | + config.base_path = CREDENTIALS[:base_path] || '/v4' |
| 59 | + end |
| 60 | + words = File.open(File.dirname(__FILE__) + "/100words.txt").readlines.map{|w| w.strip} |
| 61 | + start_time = Time.now |
| 62 | + Wordnik.logger.debug "Starting at #{start_time}" |
| 63 | + found = 0 |
| 64 | + defs = 0 |
| 65 | + examples = 0 |
| 66 | + words.each do |word| |
| 67 | + found += 1 if Wordnik.word.get_word(word)["id"]==0 |
| 68 | + defs += Wordnik.word.get_definitions(word).size |
| 69 | + examples += Wordnik.word.get_examples(word).size |
| 70 | + end |
| 71 | + total = Time.now - start_time |
| 72 | + result = RubyProf.stop |
| 73 | + STDOUT.puts "Found #{found} words out of #{words.size}; #{defs} definitions; #{examples} examples in #{total} seconds" |
| 74 | + printer = RubyProf::FlatPrinter.new(result) |
| 75 | + printer.print(STDOUT) |
| 76 | + end |
| 77 | + |
| 78 | + describe "With two hosts" do |
| 79 | + RubyProf.start |
| 80 | + Wordnik.configuration.clear |
| 81 | + Wordnik.configure do |config| |
| 82 | + config.api_key = CREDENTIALS[:api_key] |
| 83 | + config.username = CREDENTIALS[:username] |
| 84 | + config.password = CREDENTIALS[:password] |
| 85 | + config.logger = Logger.new('/dev/null') |
| 86 | + config.host = CREDENTIALS[:host] = 'api.wordnik.com' |
| 87 | + config.hosts = CREDENTIALS[:hosts] || ['ec2-50-18-25-12.us-west-1.compute.amazonaws.com',' ec2-50-18-67-92.us-west-1.compute.amazonaws.com'] |
| 88 | + config.base_path = CREDENTIALS[:base_path] || '/v4' |
| 89 | + end |
| 90 | + words = File.open(File.dirname(__FILE__) + "/100words.txt").readlines.map{|w| w.strip} |
| 91 | + start_time = Time.now |
| 92 | + Wordnik.logger.debug "Starting at #{start_time}" |
| 93 | + found = 0 |
| 94 | + defs = 0 |
| 95 | + examples = 0 |
| 96 | + words.each do |word| |
| 97 | + found += 1 if Wordnik.word.get_word(word)["id"]==0 |
| 98 | + defs += Wordnik.word.get_definitions(word).size |
| 99 | + examples += Wordnik.word.get_examples(word).size |
| 100 | + end |
| 101 | + total = Time.now - start_time |
| 102 | + result = RubyProf.stop |
| 103 | + STDOUT.puts "Found #{found} words out of #{words.size}; #{defs} definitions; #{examples} examples in #{total} seconds" |
| 104 | + printer = RubyProf::FlatPrinter.new(result) |
| 105 | + printer.print(STDOUT) |
| 106 | + end |
| 107 | + |
| 108 | +describe "With three hosts -- one invalid" do |
| 109 | + RubyProf.start |
| 110 | + Wordnik.configuration.clear |
| 111 | + Wordnik.configure do |config| |
| 112 | + config.api_key = CREDENTIALS[:api_key] |
| 113 | + config.username = CREDENTIALS[:username] |
| 114 | + config.password = CREDENTIALS[:password] |
| 115 | + config.logger = Logger.new('/dev/null') |
| 116 | + config.host = CREDENTIALS[:host] = 'api.wordnik.com' |
| 117 | + config.hosts = CREDENTIALS[:hosts] || ['ec2-50-18-25-12.us-west-1.compute.amazonaws.com', |
| 118 | + 'ec2-50-18-67-92.us-west-1.compute.amazonaws.com', |
| 119 | + 'localhost'] |
| 120 | + config.base_path = CREDENTIALS[:base_path] || '/v4' |
| 121 | + end |
| 122 | + words = File.open(File.dirname(__FILE__) + "/100words.txt").readlines.map{|w| w.strip} |
| 123 | + start_time = Time.now |
| 124 | + Wordnik.logger.debug "Starting at #{start_time}" |
| 125 | + found = 0 |
| 126 | + defs = 0 |
| 127 | + examples = 0 |
| 128 | + words.each do |word| |
| 129 | + found += 1 if Wordnik.word.get_word(word)["id"]==0 |
| 130 | + defs += Wordnik.word.get_definitions(word).size |
| 131 | + examples += Wordnik.word.get_examples(word).size |
| 132 | + end |
| 133 | + total = Time.now - start_time |
| 134 | + result = RubyProf.stop |
| 135 | + STDOUT.puts "Found #{found} words out of #{words.size}; #{defs} definitions; #{examples} examples in #{total} seconds" |
| 136 | + printer = RubyProf::FlatPrinter.new(result) |
| 137 | + printer.print(STDOUT) |
| 138 | + end |
| 139 | + |
| 140 | + end |
0 commit comments