Sha256: d828820bd6012c39ff66ce266e1b172f610349095cdec4807d6a576a9fd746cf

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 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: 8) { 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

coprocs = 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"
coprocs.each(&:interrupt)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polyphony-0.24 examples/interfaces/pg_pool.rb
polyphony-0.23 examples/interfaces/pg_pool.rb
polyphony-0.22 examples/interfaces/pg_pool.rb