Changeset 275
- Timestamp:
- 11/18/07 12:41:01 (11 months ago)
- Files:
-
- trunk/demo/app/models/stats.rb (modified) (1 diff)
- trunk/demo/test/smoke/drb_smoke_test.rb (modified) (5 diffs)
- trunk/demo/test/smoke/process_stats.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/stats.rb
r271 r275 1 1 class Stats < ActiveRecord::Base 2 def self.compute(kind) 3 start_date = minimum :created_at 4 sql = <<-END 5 select min(processing_time), max(processing_time), avg(processing_time), stddev(processing_time), 6 concat_ws(':', hour(timediff(created_at, ?)), lpad(minute(timediff(created_at, ?)), 2, '0')) as time, 7 group_concat(processing_time) as data 8 from stats 9 where kind=? group by time; 10 END 11 result = connection.execute sanitize_sql([sql, start_date, start_date, kind.to_s]) 12 returning [] do |res| 13 while row = result.fetch_row 14 data = row.last.split(',').map{|t|t.to_i} 15 median = data.size.odd? ? data[data.size/2] : ((data[data.size/2-1]+data[data.size/2]) / 2.0) 16 res << { :min => row[0].to_f, :max => row[1].to_f, :avg => row[2].to_f, :stddev => row[3].to_f, :time => row[4], :median => median } 17 end 18 end 19 end 2 20 end trunk/demo/test/smoke/drb_smoke_test.rb
r274 r275 10 10 module DrbSmokeTest 11 11 12 RECORDS_PER_PROCESS = 10000 12 RECORDS_PER_PROCESS = 100000 13 13 NUM_PROCESSES = 10 # should be an even number 14 NUM_RECORDS_PER_LOGENTRY = 10 014 NUM_RECORDS_PER_LOGENTRY = 10 15 15 NUM_DOCS = 50 16 NUM_TERMS = 100016 NUM_TERMS = 600 17 17 18 18 TIME_FACTOR = 1000.to_f / NUM_RECORDS_PER_LOGENTRY … … 53 53 end 54 54 55 puts "built #{NUM_DOCS} documents with an avg. size of #{DOCUMENTS.join.size / NUM_DOCS} Byte ."55 puts "built #{NUM_DOCS} documents with an avg. size of #{DOCUMENTS.join.size / NUM_DOCS} Bytes." 56 56 57 57 class Monitor … … 97 97 Content.create! :title => "record #{@id} / #{i}", :description => DrbSmokeTest::random_document 98 98 end 99 sleep 0.199 #sleep 0.1 100 100 if i % NUM_RECORDS_PER_LOGENTRY == 0 101 101 # write stats … … 108 108 end 109 109 Stats.create! :process_id => @id, :kind => 'finished' 110 puts "#{@i} finished" 110 111 end 111 112 end … … 114 115 def run 115 116 while Monitor::running? 116 result = nil 117 time = benchmark do 118 result = Content.find_with_ferret 'findme', :lazy => true 117 # search with concurrent writes 118 do_search 119 end 120 t = Time.now 121 while (Time.now - t) < 5.minutes 122 # the writers have finished, now hammer the server with searches for another 5 minutes 123 do_search 124 end 125 puts "#{@i} finished" 126 end 127 128 # run a search and log it's results. 129 # Search is done with a query consisting of the term 'findme' 130 # (which is guaranteed to yield 20 results) and a random term from 131 # the word list, ORed together 132 def do_search 133 hits = 0 134 time = benchmark do 135 NUM_RECORDS_PER_LOGENTRY.times do 136 result = Content.find_id_by_contents "findme OR #{WORDS.random_word}" 137 hits += result.first 119 138 end 120 Stats.create! :process_id => @id, :kind => 'search', :info => "total_hits: #{result.total_hits} ; results: #{result.size}",121 :processing_time => time * 1000,122 :open_connections => Monitor::count_connections123 sleep 1124 139 end 140 Stats.create! :process_id => @id, :kind => 'search', :info => "avg total_hits: #{hits/NUM_RECORDS_PER_LOGENTRY.to_f}", 141 :processing_time => time * TIME_FACTOR, 142 :open_connections => Monitor::count_connections 125 143 end 126 144
