Created
March 5, 2019 13:14
-
-
Save jenny-codes/7d6b6fb335a61d8bb67aa71211bded8e to your computer and use it in GitHub Desktop.
At database querying the GIL is released.
This file contains 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
require 'thwait' | |
require 'pg' | |
start = Time.now | |
first_sleep = Thread.new do | |
puts 'Starting sleep 1' | |
conn = PG::Connection.open(dbname: 'test') | |
conn.exec('SELECT pg_sleep(1);') | |
puts 'Finished sleep 1' | |
end | |
second_sleep = Thread.new do | |
puts 'Starting sleep 2' | |
conn = PG::Connection.open(dbname: 'test2') | |
conn.exec('SELECT pg_sleep(1);') | |
puts 'Finished sleep 2' | |
end | |
random = Thread.new do | |
puts 'In a random thread' | |
end | |
ThWait.all_waits(first_sleep, second_sleep, random) | |
puts "Time it took: #{Time.now - start}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment