Created
October 22, 2012 16:18
-
-
Save drewkerrigan/3932331 to your computer and use it in GitHub Desktop.
Rolling Average Tweaks
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
| ############## test_example.rb # Changed 5.times to 1.times and back | |
| # start some external clients to add values to the Riak server | |
| # 5.times do |t| | |
| 1.times do |t| | |
| pids << fork { | |
| `bundle exec rake example:create_data_points ROW=#{t} CLIENT=local#{t}` | |
| } | |
| end | |
| pids.each do |pid| | |
| Process.waitpid(pid) | |
| end | |
| ############## Rakefile # Added timer method | |
| ... | |
| ... | |
| ... | |
| task :default => :test | |
| namespace(:example) do | |
| def timer() | |
| beginning_time = Time.now | |
| yield | |
| (Time.now - beginning_time) | |
| end | |
| task :create_data_points do | |
| stats = File.open("stats.txt", "a") | |
| require File.join(ROOT_DIR,'lib','riak_rolling_average') | |
| require File.join(ROOT_DIR,'lib','data_set') | |
| #data = File.readlines(File.join(ROOT_DIR,'test','data'))[ENV['ROW'].to_i] | |
| data = DataSet.deserialize(JSON.parse(File.read(File.join(ROOT_DIR,'test','data',"split_#{ENV['ROW']}")))).data | |
| count = 0 | |
| data.each do |triple| | |
| elapsed = timer do | |
| dp = DataPoint.new( | |
| :type => 'storage', | |
| :category => 'write', | |
| :value => triple.data['bytes'], | |
| :unit => 'bytes', | |
| :time => triple.data['time'], | |
| :batch_size => triple.data['count'], | |
| :application => triple.application, | |
| :user => triple.user | |
| ) | |
| DataPointDocument.create(:data_point => dp) | |
| end | |
| stats.write "#{Time.now.strftime("%Y%m%d%H%M%S")},#{elapsed}\n" | |
| count += 1 | |
| end | |
| puts count.to_s | |
| stats.close unless file == nil | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment