This commit is contained in:
Seth Call 2015-01-29 16:13:40 -06:00
parent aec1419e6e
commit 96bc9487c4
7 changed files with 56 additions and 7 deletions

View File

@ -245,4 +245,5 @@ text_messages.sql
text_message_migration.sql
user_model_about_changes.sql
performance_samples.sql
user_presences.sql
user_presences.sql
discard_scores_optimized.sql

View File

@ -0,0 +1,11 @@
DROP FUNCTION IF EXISTS discard_scores();
CREATE FUNCTION discard_scores (INTEGER keep) RETURNS VOID AS $$
BEGIN
DELETE FROM scores WHERE score_dt >
(SELECT score_dt FROM scores s WHERE s.alocidispid = scores.alocidispid AND s.blocidispid = scores.blocidispid ORDER BY DESC score_dt LIMIT 1 OFFSET (keep * 2));
RETURN;
END;
$$ LANGUAGE plpgsql;

View File

@ -42,6 +42,7 @@ require "jam_ruby/resque/resque_hooks"
require "jam_ruby/resque/audiomixer"
require "jam_ruby/resque/quick_mixer"
require "jam_ruby/resque/icecast_config_writer"
require "jam_ruby/resque/stress_job"
require "jam_ruby/resque/scheduled/audiomixer_retry"
require "jam_ruby/resque/scheduled/icecast_config_retry"
require "jam_ruby/resque/scheduled/icecast_source_check"

View File

@ -35,7 +35,6 @@ Resque.before_first_fork do
end
JamRuby::Stats.init(config)
end
# https://devcenter.heroku.com/articles/forked-pg-connections
Resque.before_fork do

View File

@ -0,0 +1,29 @@
require 'resque'
module JamRuby
# this job exists as a way to manually test a bunch of jobs firing at once. It's not a real job.
class StressJob
extend JamRuby::ResqueStats
@queue = :stress_job
@@log = Logging.logger[StressJob]
def self.perform
@@log.debug("STARTING")
100.times do
user = User.first.id
diagnostic = Diagnostic.first.user_id
count = Diagnostic.all.count
end
@@log.debug("ENDING")
end
end
end

View File

@ -522,7 +522,7 @@ describe Score do
it "works" do
Score.createx(LOCA, NODEA, ADDRA, LOCB, NODEB, ADDRB, 20, nil)
Score.count.should == 2
Score.connection.execute("SELECT discard_scores()").check
Score.connection.execute("SELECT discard_scores(5)").check
Score.count.should == 2
end
@ -535,12 +535,12 @@ describe Score do
Score.createx(LOCA, NODEA, ADDRA, LOCB, NODEB, ADDRB, 20, nil)
Score.count.should == 12
Score.connection.execute("SELECT discard_scores()").check
Score.connection.execute("SELECT discard_scores(5)").check
Score.count.should == 12
Score.createx(LOCA, NODEA, ADDRA, LOCB, NODEB, ADDRB, 26, nil)
Score.connection.execute("UPDATE scores set created_at = TIMESTAMP '#{2.days.ago}' WHERE score = 26").cmdtuples.should == 2
Score.connection.execute("SELECT discard_scores()").check
Score.connection.execute("SELECT discard_scores(5)").check
Score.count.should == 12
Score.connection.execute("SELECT * FROM scores WHERE score = 20").ntuples.should == 12
Score.connection.execute("SELECT * FROM scores WHERE scorer = 0").ntuples.should == 6
@ -555,12 +555,12 @@ describe Score do
Score.createx(LOCB, NODEB, ADDRB, LOCA, NODEA, ADDRA, 22, nil)
Score.count.should == 24
Score.connection.execute("SELECT discard_scores()").check
Score.connection.execute("SELECT discard_scores(5)").check
Score.count.should == 24
Score.createx(LOCB, NODEB, ADDRB, LOCA, NODEA, ADDRA, 36, nil)
Score.connection.execute("UPDATE scores set created_at = TIMESTAMP '#{2.days.ago}' WHERE score = 36").cmdtuples.should == 2
Score.connection.execute("SELECT discard_scores()").check
Score.connection.execute("SELECT discard_scores(5)").check
Score.count.should == 24
Score.connection.execute("SELECT * FROM scores WHERE score = 22").ntuples.should == 12
Score.connection.execute("SELECT * FROM scores WHERE score = 22 AND scorer = 0").ntuples.should == 6

View File

@ -0,0 +1,8 @@
task :stress_resque do
Rake::Task['environment'].invoke
10.times do
Resque.enqueue(StressJob)
end
end