Project

General

Profile

Bug #10009 » teste_thread_schedule_2.rb

ariveira (Alexandre Riveira), 07/06/2014 07:33 AM

 
#puts "definindo taskset -c -p 1 #{Process.pid}"
`taskset -c -p 2 #{Process.pid}`
require 'pg'

inicio_geral = Time.now
t1 = Thread.new do
Thread.current[:target] = 0
while true
Thread.current[:target] += 1
end
end

10.downto(0) do |i|
inicio = Time.now
Kernel.sleep(1)
puts "faltando #{i} segundos (#{Time.now - inicio})"
end

puts "zerando thread com contagem em #{t1[:target]}"
t1[:target] = 0

t2 = Thread.new do
Thread.current[:target] = 0
conn = PGconn.open(:dbname => 'mydatabase', :user => 'postgres')
while true
conn.exec("SELECT * FROM mytable WHERE id = 1")
Thread.current[:target] += 1
end
end

t3 = Thread.new do
Thread.current[:target] = 0
while true
Thread.current[:target] += 1
end
end
10.times do
puts "first #{t1[:target]}"
puts "second #{t2[:target]}"
puts "third #{t3[:target]}"
puts "\n\n"
sleep(1)
end
total = t1[:target].to_i + t2[:target].to_i + t3[:target].to_i
puts "total #{total}"
puts "media #{total/(Time.now - inicio_geral).to_i}"
puts "\n\n"
puts "time #{Time.now - inicio_geral}"

(1-1/8)