On Wed, May 22, 2013 at 11:11 PM, Andres Freund <and...@2ndquadrant.com> wrote:
> Make that actually having acquired an xid. We skip a large part of the
> work if a transaction doesn't yet have one afair. I don't think the mere
> presence of 600 idle connections without an xid in contrast to just
> having max_connection at 600 should actually make a difference in the
> cost of acquiring a snapshot?

Attached is a slightly updated version of the patch I'm using for
testing, and an updated version of the pg_cxn source that I'm using to
open lotsa connections.  With this version, I can do this:

./pg_cxn -n 600 -c BEGIN -c 'SELECT txid_current()'

...which I think is sufficient to make sure all those transactions
have XIDs.  Then I reran the "depend" test case (create a schema with
1000,000 functions and then drop the schema with CASCADE) that I
mentioned in my original posting.  Here are the results:

MVCC Off: Create 8685.662 ms, Drop 9973.233 ms
MVCC On: Create 7931.039 ms, Drop 10189.189 ms
MVCC Off: Create 7810.084 ms, Drop 9594.580 ms
MVCC On: Create 8854.577 ms, Drop 10240.024 ms

OK, let's try the rebuild-the-relcache test using the same pg_cxn
scenario (600 transactions that have started a transaction and
selected txid_current()).

[rhaas ~]$ time for s in `seq 1 1000`; do rm -f
pgdata/global/pg_internal.init && psql -c 'SELECT 2+2' >/dev/null;
done

MVCC catalog access on:
real    0m11.006s
user    0m2.746s
sys     0m2.664s

MVCC catalog access off:
real    0m10.583s
user    0m2.745s
sys     0m2.661s

MVCC catalog access on:
real    0m10.646s
user    0m2.750s
sys     0m2.661s

MVCC catalog access off:
real    0m10.823s
user    0m2.756s
sys     0m2.681s

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment: mvcc-catalog-access-v2.patch
Description: Binary data

/*
 * pg_cxn.c
 */

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "libpq-fe.h"

struct cmd_list;
typedef struct cmd_list cmd_list;

struct cmd_list
{
	char   *cmd;
	cmd_list   *next;
};

static void pg_connect(const char *conninfo, cmd_list *);
static cmd_list *add_command(cmd_list *, char *);
static void usage(void);

int
main(int argc, char **argv)
{
	int		c;
	int		n = 1;
	int		optindex;
	int		i;
	const char *conninfo;
	cmd_list   *cmds;

	while ((c = getopt_long(argc, argv, "n:c:", NULL, &optindex)) != -1)
	{
		switch (c)
		{
			case 'n':
				n = atoi(optarg);
				break;
			case 'c':
				cmds = add_command(cmds, optarg);
				break;
			default:
				usage();
				break;
		}
	}
	argv += optind;
	argc -= optind;

	if (argc > 0)
		conninfo = argv[0];
	else
		conninfo = "";

	for (i = 0; i < n; ++i)
		pg_connect(conninfo, cmds);

	printf("Established %d connections.\n", n);

	while (1)
		sleep(3600);

	return 0;
}

static cmd_list *
add_command(cmd_list *cmds, char *cmd)
{
	cmd_list   *newnode;

	newnode = malloc(sizeof(cmd_list));
	if (newnode == NULL)
	{
		perror("malloc");
		exit(1);
	}
	newnode->cmd = cmd;
	newnode->next = cmds;
	return newnode;
}

static void
pg_connect(const char *conninfo, cmd_list *cmds)
{
	PGconn	   *conn;

	/* Make a connection to the database */
	conn = PQconnectdb(conninfo);

	/* Check to see that the backend connection was successfully made */
	if (PQstatus(conn) != CONNECTION_OK)
	{
		fprintf(stderr, "%s", PQerrorMessage(conn));
		exit(1);
	}

	/* Execute commands. */
	while (cmds != NULL)
	{
		PGresult *res;

		res = PQexec(conn, cmds->cmd);
		if (PQresultStatus(res) == PGRES_FATAL_ERROR)
		{
			fprintf(stderr, "%s", PQresultErrorMessage(res));
			exit(1);
		}
		if (PQresultStatus(res) != PGRES_COMMAND_OK
			&& PQresultStatus(res) != PGRES_TUPLES_OK)
		{
			fprintf(stderr, "unexpected result status: %s\n",
					PQresStatus(PQresultStatus(res)));
			exit(1);
		}
		PQclear(res);
		cmds = cmds->next;
	}
}

static void
usage()
{
	fprintf(stderr, "Usage: pg_cxn [OPTION] [CONNECTION-STRING]\n\n"
		"Options:\n"
		"  -n NUM		Number of connections to open.\n"
		"  -c SQL		SQL to execute on each connection.\n"
		"				(You can repeat this option more than once.)\n");
	exit(1);
}
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to