Sha256: 3367755a305c7f4c1f8ea3b8b17557a466dd0c6dde1a1903c248e77b451d96cf

Contents?: true

Size: 879 Bytes

Versions: 6

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony/postgres'

PGOPTS = {
  host:     '/tmp',
  user:     'reality',
  password: nil,
  dbname:   'reality',
  sslmode:  'require'
}.freeze

DBPOOL = Polyphony::ResourcePool.new(limit: 16) { PG.connect(PGOPTS) }

def get_records(db)
  db.query('select pg_sleep(0.001) as test')
  # puts "got #{res.ntuples} records: #{res.to_a}"
rescue StandardError => e
  puts "got error: #{e.inspect}"
  puts e.backtrace.join("\n")
end

CONCURRENCY = ARGV.first ? ARGV.first.to_i : 10
puts "concurrency: #{CONCURRENCY}"

DBPOOL.preheat!
t0 = Time.now
count = 0

fibers = CONCURRENCY.times.map do
  spin do
    loop do
      DBPOOL.acquire do |db|
        get_records(db)
        count += 1
      end
    end
  end
end
sleep 5
puts "count: #{count} query rate: #{count / (Time.now - t0)} queries/s"
fibers.each(&:interrupt)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
polyphony-0.30 examples/interfaces/pg_pool.rb
polyphony-0.29 examples/interfaces/pg_pool.rb
polyphony-0.28 examples/interfaces/pg_pool.rb
polyphony-0.27 examples/interfaces/pg_pool.rb
polyphony-0.26 examples/interfaces/pg_pool.rb
polyphony-0.25 examples/interfaces/pg_pool.rb