D.pl.txt
text/plain
Filename: D.pl.txt
Type: text/plain
Part: 3
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
# no. of concurrent txn
my $concurrent_txns = 2000;
# max_connections to be set
my $max_connections = $concurrent_txns + 100;
# Setup node
my $node = PostgreSQL::Test::Cluster->new('publisher');
$node->init(allows_streaming => 'logical');
$node->append_conf(
'postgresql.conf', q[
shared_buffers = 40GB
max_worker_processes = 32
max_parallel_maintenance_workers = 24
max_parallel_workers = 32
synchronous_commit = on
checkpoint_timeout = 1d
max_wal_size = 24GB
min_wal_size = 15GB
autovacuum = off
logical_decoding_work_mem = 40GB
]);
$node->append_conf('postgresql.conf', "max_connections = $max_connections");
$node->start;
$node->safe_psql(
'postgres', qq(
CREATE TABLE tab_conc1(a int);
CREATE PUBLICATION regress_pub1 for table tab_conc1;
SELECT * FROM pg_create_logical_replication_slot('regression_slot1', 'pgoutput');
));
my $psql_timeout_secs = 4 * $PostgreSQL::Test::Utils::timeout_default;
my @background_psqls;
# create $concurrent_txns sessions
foreach my $i (1 .. $concurrent_txns)
{
my $background_psql = $node->background_psql(
'postgres',
on_error_stop => 0,
timeout => $psql_timeout_secs);
push (@background_psqls, $background_psql);
}
# begin txn in each session
foreach my $background_psql (@background_psqls)
{
$background_psql->query_safe(qq[BEGIN;INSERT INTO tab_conc1 VALUES (11);]);
}
# invalidate message is distributed to all $concurrent_txns transactions
foreach my $i (1 .. 1)
{
$node->safe_psql('postgres', 'ALTER PUBLICATION regress_pub1 DROP TABLE tab_conc1;');
$node->safe_psql('postgres', 'ALTER PUBLICATION regress_pub1 ADD TABLE tab_conc1;');
}
# Insert will build cache for each txn as cache is invalidated for each txn in previous step
foreach my $background_psql (@background_psqls)
{
$background_psql->query_safe(qq[INSERT INTO tab_conc1 VALUES (12); COMMIT;]);
$background_psql->quit;
}
# Measure the decoding time via SQL interface - pg_logical_slot_get_binary_changes
my $start = Time::HiRes::gettimeofday();
my $result = $node->safe_psql('postgres',
"SELECT count(*) FROM pg_logical_slot_get_binary_changes('regression_slot1', NULL, NULL, 'proto_version', '4', 'publication_names', 'regress_pub1');");
my $end = Time::HiRes::gettimeofday();
printf("time elapsed %f\n", $end - $start);
# check with patch
#is($result, $concurrent_txns * 6 , 'changes were decoded properly');
# check with HEAD
is($result, $concurrent_txns * 4 + 1, 'changes were decoded properly');
$node->stop('fast');
done_testing();