From ef42591e391efeee625ac139ed6e9c07a3c38eb0 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Fri, 16 Sep 2011 12:40:49 +0100 Subject: Remove the canary --- lib/canary.rb | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 lib/canary.rb diff --git a/lib/canary.rb b/lib/canary.rb deleted file mode 100644 index afe3a16..0000000 --- a/lib/canary.rb +++ /dev/null @@ -1,55 +0,0 @@ -# encoding: UTF-8 -require 'logger' - -# A little canary class to make sure that threads are are overloaded. -class Canary - - # Accessor. - attr_reader :sleep_time - - # Accessor. - attr_reader :threshold - - # Default constructor. - def initialize (st=1, log=nil) - if Float != st.class and Fixnum != st.class - raise ArgumentError.new( - "Expected either Fixnum or Float for time to sleep, got #{st.class}.") - end - @sleep_time = st - @threshold = (0.05 * @sleep_time) + @sleep_time - @logger = log - end - - # Runs the check. - def run - loop do - self.do_test() - end - end - - def do_test - time_start = Time.now - sleep(@sleep_time) - time_end = Time.now - time_elapsed = (time_end - time_start).abs - if @threshold < time_elapsed - @logger.fatal("Time elapsed is #{time_elapsed} > #{@threshold} therefore Canary is dead.") - return false - else - @logger.debug("Time elapsed is #{time_elapsed} < #{@threshold} therefore Canary is alive.") - return true - end - end - - # Starts a canary in a thread. - def self.start (st=1, log=nil) - #Thread.abort_on_exception = true - thr = Thread.new() do - Thread.current[:name] = "Canary Thread" - twiti = Canary.new(st, log) - twiti.run() - end - end - -end -- cgit v1.2.1