mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 09:26:30 +00:00
* Refactor stats to use atomics When we are dealing with a high number of connections, generated stats cannot be consumed fast enough by the stats collector loop. This makes the stats subsystem inconsistent and a log of warning messages are thrown due to unregistered server/clients. This change refactors the stats subsystem so it uses atomics: - Now counters are handled using U64 atomics - Event system is dropped and averages are calculated using a loop every 15 seconds. - Now, instead of snapshots being generated ever second we keep track of servers/clients that have registered. Each pool/server/client has its own instance of the counter and makes changes directly, instead of adding an event that gets processed later. * Manually mplement Hash/Eq in `config::Address` ignoring stats * Add tests for client connection counters * Allow connecting to dockerized dev pgcat from the host * stats: Decrease cl_idle when idle socket disconnects
29 lines
738 B
Ruby
29 lines
738 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'pg'
|
|
require_relative 'helpers/pgcat_helper'
|
|
|
|
QUERY_COUNT = 300
|
|
MARGIN_OF_ERROR = 0.35
|
|
|
|
def with_captured_stdout_stderr
|
|
sout = STDOUT.clone
|
|
serr = STDERR.clone
|
|
STDOUT.reopen("/tmp/out.txt", "w+")
|
|
STDERR.reopen("/tmp/err.txt", "w+")
|
|
STDOUT.sync = true
|
|
STDERR.sync = true
|
|
yield
|
|
return File.read('/tmp/out.txt'), File.read('/tmp/err.txt')
|
|
ensure
|
|
STDOUT.reopen(sout)
|
|
STDERR.reopen(serr)
|
|
end
|
|
|
|
def clients_connected_to_pool(pool_index: 0, processes:)
|
|
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
|
|
results = admin_conn.async_exec("SHOW POOLS")[pool_index]
|
|
admin_conn.close
|
|
results['cl_idle'].to_i + results['cl_active'].to_i + results['cl_waiting'].to_i
|
|
end
|