Optimized pgbench for 8.3

Started by ITAGAKI Takahiroalmost 19 years ago10 messages
#1ITAGAKI Takahiro
itagaki.takahiro@oss.ntt.co.jp
1 attachment(s)

The attached is a patch to optimize contrib/pgbench using new 8.3 features.

- Use DROP IF EXISTS to suppress errors for initial loadings.
- Use a combination of TRUNCATE and COPY to reduce WAL on creating
the accounts table.

Also, there are some cosmetic changes.

- Change the output of -v option from "starting full vacuum..."
to "starting vacuum accounts..." in reflection of the fact.
- Shape duplicated error checks into executeStatement().

There is a big performance win in "COPY with no WAL" feature.
Thanks for the efforts!

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Attachments:

pgbench-8.3.patchapplication/octet-stream; name=pgbench-8.3.patchDownload
*** pgbench.c.orig	Mon Jan 22 11:17:30 2007
--- pgbench.c	Mon Mar  5 14:59:14 2007
*************** getrand(int min, int max)
*** 188,199 ****
  	return min + (int) (((max - min) * (double) random()) / MAX_RANDOM_VALUE + 0.5);
  }
  
  /* set up a connection to the backend */
  static PGconn *
  doConnect(void)
  {
  	PGconn	   *con;
- 	PGresult   *res;
  
  	con = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName,
  					   login, pwd);
--- 188,213 ----
  	return min + (int) (((max - min) * (double) random()) / MAX_RANDOM_VALUE + 0.5);
  }
  
+ /* call PQexec() and exit() on failure */
+ static void
+ executeStatement(PGconn *con, const char* sql)
+ {
+ 	PGresult   *res;
+ 
+ 	res = PQexec(con, sql);
+ 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ 	{
+ 		fprintf(stderr, "%s", PQerrorMessage(con));
+ 		exit(1);
+ 	}
+ 	PQclear(res);
+ }
+ 
  /* set up a connection to the backend */
  static PGconn *
  doConnect(void)
  {
  	PGconn	   *con;
  
  	con = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName,
  					   login, pwd);
*************** doConnect(void)
*** 216,228 ****
  		return (NULL);
  	}
  
! 	res = PQexec(con, "SET search_path = public");
! 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 	{
! 		fprintf(stderr, "%s", PQerrorMessage(con));
! 		exit(1);
! 	}
! 	PQclear(res);
  
  	return (con);
  }
--- 230,236 ----
  		return (NULL);
  	}
  
! 	executeStatement(con, "SET search_path = public");
  
  	return (con);
  }
*************** init(void)
*** 720,737 ****
  	PGconn	   *con;
  	PGresult   *res;
  	static char *DDLs[] = {
! 		"drop table branches",
  		"create table branches(bid int not null,bbalance int,filler char(88))",
! 		"drop table tellers",
  		"create table tellers(tid int not null,bid int,tbalance int,filler char(84))",
! 		"drop table accounts",
  		"create table accounts(aid int not null,bid int,abalance int,filler char(84))",
! 		"drop table history",
! 	"create table history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"};
  	static char *DDLAFTERs[] = {
  		"alter table branches add primary key (bid)",
  		"alter table tellers add primary key (tid)",
! 	"alter table accounts add primary key (aid)"};
  
  
  	char		sql[256];
--- 728,745 ----
  	PGconn	   *con;
  	PGresult   *res;
  	static char *DDLs[] = {
! 		"drop table if exists branches",
  		"create table branches(bid int not null,bbalance int,filler char(88))",
! 		"drop table if exists tellers",
  		"create table tellers(tid int not null,bid int,tbalance int,filler char(84))",
! 		"drop table if exists accounts",
  		"create table accounts(aid int not null,bid int,abalance int,filler char(84))",
! 		"drop table if exists history",
! 		"create table history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"};
  	static char *DDLAFTERs[] = {
  		"alter table branches add primary key (bid)",
  		"alter table tellers add primary key (tid)",
! 		"alter table accounts add primary key (aid)"};
  
  
  	char		sql[256];
*************** init(void)
*** 741,817 ****
  	if ((con = doConnect()) == NULL)
  		exit(1);
  
! 	for (i = 0; i < (sizeof(DDLs) / sizeof(char *)); i++)
! 	{
! 		res = PQexec(con, DDLs[i]);
! 		if (strncmp(DDLs[i], "drop", 4) && PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
! 	}
  
! 	res = PQexec(con, "begin");
! 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 	{
! 		fprintf(stderr, "%s", PQerrorMessage(con));
! 		exit(1);
! 	}
! 	PQclear(res);
  
  	for (i = 0; i < nbranches * scale; i++)
  	{
  		snprintf(sql, 256, "insert into branches(bid,bbalance) values(%d,0)", i + 1);
! 		res = PQexec(con, sql);
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
  	}
  
  	for (i = 0; i < ntellers * scale; i++)
  	{
  		snprintf(sql, 256, "insert into tellers(tid,bid,tbalance) values (%d,%d,0)"
  				 ,i + 1, i / ntellers + 1);
! 		res = PQexec(con, sql);
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
  	}
  
! 	res = PQexec(con, "end");
! 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
  	{
  		fprintf(stderr, "%s", PQerrorMessage(con));
  		exit(1);
  	}
  	PQclear(res);
  
- 	/*
- 	 * occupy accounts table with some data
- 	 */
- 	fprintf(stderr, "creating tables...\n");
  	for (i = 0; i < naccounts * scale; i++)
  	{
  		int			j = i + 1;
  
- 		if (j % 10000 == 1)
- 		{
- 			res = PQexec(con, "copy accounts from stdin");
- 			if (PQresultStatus(res) != PGRES_COPY_IN)
- 			{
- 				fprintf(stderr, "%s", PQerrorMessage(con));
- 				exit(1);
- 			}
- 			PQclear(res);
- 		}
- 
  		snprintf(sql, 256, "%d\t%d\t%d\t\n", j, i / naccounts + 1, 0);
  		if (PQputline(con, sql))
  		{
--- 749,794 ----
  	if ((con = doConnect()) == NULL)
  		exit(1);
  
! 	for (i = 0; i < lengthof(DDLs); i++)
! 		executeStatement(con, DDLs[i]);
  
! 	executeStatement(con, "begin");
  
  	for (i = 0; i < nbranches * scale; i++)
  	{
  		snprintf(sql, 256, "insert into branches(bid,bbalance) values(%d,0)", i + 1);
! 		executeStatement(con, sql);
  	}
  
  	for (i = 0; i < ntellers * scale; i++)
  	{
  		snprintf(sql, 256, "insert into tellers(tid,bid,tbalance) values (%d,%d,0)"
  				 ,i + 1, i / ntellers + 1);
! 		executeStatement(con, sql);
  	}
  
! 	executeStatement(con, "commit");
! 
! 	/*
! 	 * fill the accounts table with some data
! 	 */
! 	fprintf(stderr, "creating tables...\n");
! 
! 	executeStatement(con, "begin");
! 	executeStatement(con, "truncate accounts");
! 
! 	res = PQexec(con, "copy accounts from stdin");
! 	if (PQresultStatus(res) != PGRES_COPY_IN)
  	{
  		fprintf(stderr, "%s", PQerrorMessage(con));
  		exit(1);
  	}
  	PQclear(res);
  
  	for (i = 0; i < naccounts * scale; i++)
  	{
  		int			j = i + 1;
  
  		snprintf(sql, 256, "%d\t%d\t%d\t\n", j, i / naccounts + 1, 0);
  		if (PQputline(con, sql))
  		{
*************** init(void)
*** 820,881 ****
  		}
  
  		if (j % 10000 == 0)
- 		{
- 			/*
- 			 * every 10000 tuples, we commit the copy command. this should
- 			 * avoid generating too much WAL logs
- 			 */
  			fprintf(stderr, "%d tuples done.\n", j);
- 			if (PQputline(con, "\\.\n"))
- 			{
- 				fprintf(stderr, "very last PQputline failed\n");
- 				exit(1);
- 			}
- 
- 			if (PQendcopy(con))
- 			{
- 				fprintf(stderr, "PQendcopy failed\n");
- 				exit(1);
- 			}
- 
- #ifdef NOT_USED
- 
- 			/*
- 			 * do a checkpoint to purge the old WAL logs
- 			 */
- 			res = PQexec(con, "checkpoint");
- 			if (PQresultStatus(res) != PGRES_COMMAND_OK)
- 			{
- 				fprintf(stderr, "%s", PQerrorMessage(con));
- 				exit(1);
- 			}
- 			PQclear(res);
- #endif   /* NOT_USED */
- 		}
  	}
! 	fprintf(stderr, "set primary key...\n");
! 	for (i = 0; i < (sizeof(DDLAFTERs) / sizeof(char *)); i++)
  	{
! 		res = PQexec(con, DDLAFTERs[i]);
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
  	}
! 
! 	/* vacuum */
! 	fprintf(stderr, "vacuum...");
! 	res = PQexec(con, "vacuum analyze");
! 	if (PQresultStatus(res) != PGRES_COMMAND_OK)
  	{
! 		fprintf(stderr, "%s", PQerrorMessage(con));
  		exit(1);
  	}
! 	PQclear(res);
! 	fprintf(stderr, "done.\n");
  
  	PQfinish(con);
  }
  
--- 797,828 ----
  		}
  
  		if (j % 10000 == 0)
  			fprintf(stderr, "%d tuples done.\n", j);
  	}
! 	if (PQputline(con, "\\.\n"))
  	{
! 		fprintf(stderr, "very last PQputline failed\n");
! 		exit(1);
  	}
! 	if (PQendcopy(con))
  	{
! 		fprintf(stderr, "PQendcopy failed\n");
  		exit(1);
  	}
! 	executeStatement(con, "commit");
! 
! 	/*
! 	 * create indexes
! 	 */
! 	fprintf(stderr, "set primary key...\n");
! 	for (i = 0; i < lengthof(DDLAFTERs); i++)
! 		executeStatement(con, DDLAFTERs[i]);
  
+ 	/* vacuum */
+ 	fprintf(stderr, "vacuum...");
+ 	executeStatement(con, "vacuum analyze");
+ 
+ 	fprintf(stderr, "done.\n");
  	PQfinish(con);
  }
  
*************** main(int argc, char **argv)
*** 1155,1161 ****
  	int			c;
  	int			is_init_mode = 0;		/* initialize mode? */
  	int			is_no_vacuum = 0;		/* no vacuum at all before testing? */
! 	int			is_full_vacuum = 0;		/* do full vacuum before testing? */
  	int			debug = 0;		/* debug flag */
  	int			ttype = 0;		/* transaction type. 0: TPC-B, 1: SELECT only,
  								 * 2: skip update of branches and tellers */
--- 1102,1108 ----
  	int			c;
  	int			is_init_mode = 0;		/* initialize mode? */
  	int			is_no_vacuum = 0;		/* no vacuum at all before testing? */
! 	int			do_vacuum_accounts = 0;	/* do vacuum accounts before testing? */
  	int			debug = 0;		/* debug flag */
  	int			ttype = 0;		/* transaction type. 0: TPC-B, 1: SELECT only,
  								 * 2: skip update of branches and tellers */
*************** main(int argc, char **argv)
*** 1214,1220 ****
  				is_no_vacuum++;
  				break;
  			case 'v':
! 				is_full_vacuum++;
  				break;
  			case 'p':
  				pgport = optarg;
--- 1161,1167 ----
  				is_no_vacuum++;
  				break;
  			case 'v':
! 				do_vacuum_accounts++;
  				break;
  			case 'p':
  				pgport = optarg;
*************** main(int argc, char **argv)
*** 1451,1499 ****
  	if (!is_no_vacuum)
  	{
  		fprintf(stderr, "starting vacuum...");
! 		res = PQexec(con, "vacuum branches");
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
! 
! 		res = PQexec(con, "vacuum tellers");
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
! 
! 		res = PQexec(con, "delete from history");
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
! 		res = PQexec(con, "vacuum history");
! 		if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 		{
! 			fprintf(stderr, "%s", PQerrorMessage(con));
! 			exit(1);
! 		}
! 		PQclear(res);
! 
  		fprintf(stderr, "end.\n");
  
! 		if (is_full_vacuum)
  		{
! 			fprintf(stderr, "starting full vacuum...");
! 			res = PQexec(con, "vacuum analyze accounts");
! 			if (PQresultStatus(res) != PGRES_COMMAND_OK)
! 			{
! 				fprintf(stderr, "%s", PQerrorMessage(con));
! 				exit(1);
! 			}
! 			PQclear(res);
  			fprintf(stderr, "end.\n");
  		}
  	}
--- 1398,1413 ----
  	if (!is_no_vacuum)
  	{
  		fprintf(stderr, "starting vacuum...");
! 		executeStatement(con, "vacuum branches");
! 		executeStatement(con, "vacuum tellers");
! 		executeStatement(con, "delete from history");
! 		executeStatement(con, "vacuum history");
  		fprintf(stderr, "end.\n");
  
! 		if (do_vacuum_accounts)
  		{
! 			fprintf(stderr, "starting vacuum accounts...");
! 			executeStatement(con, "vacuum analyze accounts");
  			fprintf(stderr, "end.\n");
  		}
  	}
#2Bruce Momjian
bruce@momjian.us
In reply to: ITAGAKI Takahiro (#1)
Re: Optimized pgbench for 8.3

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------

ITAGAKI Takahiro wrote:

The attached is a patch to optimize contrib/pgbench using new 8.3 features.

- Use DROP IF EXISTS to suppress errors for initial loadings.
- Use a combination of TRUNCATE and COPY to reduce WAL on creating
the accounts table.

Also, there are some cosmetic changes.

- Change the output of -v option from "starting full vacuum..."
to "starting vacuum accounts..." in reflection of the fact.
- Shape duplicated error checks into executeStatement().

There is a big performance win in "COPY with no WAL" feature.
Thanks for the efforts!

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#3Bruce Momjian
bruce@momjian.us
In reply to: ITAGAKI Takahiro (#1)
Re: Optimized pgbench for 8.3

Tatsuo, would you please comment on this patch?

---------------------------------------------------------------------------

ITAGAKI Takahiro wrote:

The attached is a patch to optimize contrib/pgbench using new 8.3 features.

- Use DROP IF EXISTS to suppress errors for initial loadings.
- Use a combination of TRUNCATE and COPY to reduce WAL on creating
the accounts table.

Also, there are some cosmetic changes.

- Change the output of -v option from "starting full vacuum..."
to "starting vacuum accounts..." in reflection of the fact.
- Shape duplicated error checks into executeStatement().

There is a big performance win in "COPY with no WAL" feature.
Thanks for the efforts!

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#4Tatsuo Ishii
ishii@postgresql.org
In reply to: Bruce Momjian (#3)
Re: Optimized pgbench for 8.3

Tatsuo, would you please comment on this patch?

Sure. I will come up with a comment by the end of this week.
--
Tatsuo Ishii
SRA OSS, Inc. Japan

Show quoted text

---------------------------------------------------------------------------

ITAGAKI Takahiro wrote:

The attached is a patch to optimize contrib/pgbench using new 8.3 features.

- Use DROP IF EXISTS to suppress errors for initial loadings.
- Use a combination of TRUNCATE and COPY to reduce WAL on creating
the accounts table.

Also, there are some cosmetic changes.

- Change the output of -v option from "starting full vacuum..."
to "starting vacuum accounts..." in reflection of the fact.
- Shape duplicated error checks into executeStatement().

There is a big performance win in "COPY with no WAL" feature.
Thanks for the efforts!

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#5Tatsuo Ishii
ishii@postgresql.org
In reply to: Tatsuo Ishii (#4)
Re: Optimized pgbench for 8.3

Tatsuo, would you please comment on this patch?

Sure. I will come up with a comment by the end of this week.

The patches look good to me.

BTW, is anybody working on enabling the fill factor to the tables used
by pgbench? 8.3 will introduce HOT, and I think adding the feature
will make it easier to test HOT.
--
Tatsuo Ishii
SRA OSS, Inc. Japan

Show quoted text

---------------------------------------------------------------------------

ITAGAKI Takahiro wrote:

The attached is a patch to optimize contrib/pgbench using new 8.3 features.

- Use DROP IF EXISTS to suppress errors for initial loadings.
- Use a combination of TRUNCATE and COPY to reduce WAL on creating
the accounts table.

Also, there are some cosmetic changes.

- Change the output of -v option from "starting full vacuum..."
to "starting vacuum accounts..." in reflection of the fact.
- Shape duplicated error checks into executeStatement().

There is a big performance win in "COPY with no WAL" feature.
Thanks for the efforts!

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tatsuo Ishii (#5)
Re: Optimized pgbench for 8.3

Tatsuo Ishii <ishii@postgresql.org> writes:

The patches look good to me.

Please commit whatever you think is reasonable.

BTW, is anybody working on enabling the fill factor to the tables used
by pgbench? 8.3 will introduce HOT, and I think adding the feature
will make it easier to test HOT.

I'm not 100% sure that HOT will make it ... but I agree that it'd be
useful for pgbench to support different fillfactor choices. Please
add if you have time.

regards, tom lane

#7Tatsuo Ishii
ishii@postgresql.org
In reply to: ITAGAKI Takahiro (#1)
Re: Optimized pgbench for 8.3

Patch committed. Thanks.
--
Tatsuo Ishii
SRA OSS, Inc. Japan

Show quoted text

The attached is a patch to optimize contrib/pgbench using new 8.3 features.

- Use DROP IF EXISTS to suppress errors for initial loadings.
- Use a combination of TRUNCATE and COPY to reduce WAL on creating
the accounts table.

Also, there are some cosmetic changes.

- Change the output of -v option from "starting full vacuum..."
to "starting vacuum accounts..." in reflection of the fact.
- Shape duplicated error checks into executeStatement().

There is a big performance win in "COPY with no WAL" feature.
Thanks for the efforts!

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

#8Bruce Momjian
bruce@momjian.us
In reply to: ITAGAKI Takahiro (#1)
Re: Optimized pgbench for 8.3

FYI, patch applied by Tatsuo. Thanks.

---------------------------------------------------------------------------

ITAGAKI Takahiro wrote:

The attached is a patch to optimize contrib/pgbench using new 8.3 features.

- Use DROP IF EXISTS to suppress errors for initial loadings.
- Use a combination of TRUNCATE and COPY to reduce WAL on creating
the accounts table.

Also, there are some cosmetic changes.

- Change the output of -v option from "starting full vacuum..."
to "starting vacuum accounts..." in reflection of the fact.
- Shape duplicated error checks into executeStatement().

There is a big performance win in "COPY with no WAL" feature.
Thanks for the efforts!

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#9Pavan Deolasee
pavan.deolasee@gmail.com
In reply to: Tatsuo Ishii (#5)
1 attachment(s)
Re: [HACKERS] Optimized pgbench for 8.3

On 4/6/07, Tatsuo Ishii <ishii@postgresql.org> wrote:

BTW, is anybody working on enabling the fill factor to the tables used
by pgbench? 8.3 will introduce HOT, and I think adding the feature
will make it easier to test HOT.

Please see if the attached patch looks good. It adds a new -F option
which can be used to set fillfactor for tellers, accounts and branches
tables. Default is 100 and anything between 10 and 100 is acceptable.

Thanks,
Pavan

--

EnterpriseDB http://www.enterprisedb.com

Attachments:

pgbench_fillfactor.patchapplication/octet-stream; name=pgbench_fillfactor.patchDownload
Index: README.pgbench
===================================================================
RCS file: /home/cvs/postgres/cvs/pgsql/contrib/pgbench/README.pgbench,v
retrieving revision 1.17
diff -c -r1.17 README.pgbench
*** README.pgbench	6 Apr 2007 09:16:15 -0000	1.17
--- README.pgbench	7 Apr 2007 16:42:45 -0000
***************
*** 57,64 ****
  	accounts	100000
  	history		0
  
! 	You can increase the number of tuples by using -s option. See
! 	below.
  
    (2) Run the benchmark test
  
--- 57,65 ----
  	accounts	100000
  	history		0
  
! 	You can increase the number of tuples by using -s option. branches,
! 	tellers and accounts tables are created with a fillfactor which is
! 	set using -F option. See below.
  
    (2) Run the benchmark test
  
***************
*** 162,167 ****
--- 163,172 ----
  		0 201 2513 0 1175850569 608
  		0 202 2038 0 1175850569 2663
  
+ 	-F fillfactor
+ 		Create tables with the given fillfactor. Default is 100.
+ 		This should be used with -i (initialize) option.
+ 		
  	-d
  		debug option.
  
Index: pgbench.c
===================================================================
RCS file: /home/cvs/postgres/cvs/pgsql/contrib/pgbench/pgbench.c,v
retrieving revision 1.64
diff -c -r1.64 pgbench.c
*** pgbench.c	6 Apr 2007 09:16:16 -0000	1.64
--- pgbench.c	7 Apr 2007 16:42:45 -0000
***************
*** 65,70 ****
--- 65,76 ----
  int			scale = 1;
  
  /*
+  * fillfactor. for example, fillfactor = 90 will use only 90 percent
+  * space during inserts and leave 10 percent free.
+  */
+ int			fillfactor = 100;
+ 
+ /*
   * end of configurable parameters
   *********************************************************************/
  
***************
*** 178,184 ****
  usage(void)
  {
  	fprintf(stderr, "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-D varname=value][-n][-C][-v][-S][-N][-f filename][-l][-U login][-P password][-d][dbname]\n");
! 	fprintf(stderr, "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-U login][-P password][-d][dbname]\n");
  }
  
  /* random number generator */
--- 184,190 ----
  usage(void)
  {
  	fprintf(stderr, "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-D varname=value][-n][-C][-v][-S][-N][-f filename][-l][-U login][-P password][-d][dbname]\n");
! 	fprintf(stderr, "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor] [-F fillfactor] [-U login][-P password][-d][dbname]\n");
  }
  
  /* random number generator */
***************
*** 730,740 ****
  	PGresult   *res;
  	static char *DDLs[] = {
  		"drop table if exists branches",
! 		"create table branches(bid int not null,bbalance int,filler char(88))",
  		"drop table if exists tellers",
! 		"create table tellers(tid int not null,bid int,tbalance int,filler char(84))",
  		"drop table if exists accounts",
! 		"create table accounts(aid int not null,bid int,abalance int,filler char(84))",
  		"drop table if exists history",
  		"create table history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"};
  	static char *DDLAFTERs[] = {
--- 736,746 ----
  	PGresult   *res;
  	static char *DDLs[] = {
  		"drop table if exists branches",
! 		"create table branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=%d)",
  		"drop table if exists tellers",
! 		"create table tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=%d)",
  		"drop table if exists accounts",
! 		"create table accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=%d)",
  		"drop table if exists history",
  		"create table history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"};
  	static char *DDLAFTERs[] = {
***************
*** 751,757 ****
  		exit(1);
  
  	for (i = 0; i < lengthof(DDLs); i++)
! 		executeStatement(con, DDLs[i]);
  
  	executeStatement(con, "begin");
  
--- 757,778 ----
  		exit(1);
  
  	for (i = 0; i < lengthof(DDLs); i++)
! 	{
! 		/*
! 		 * set fillfactor for branches, tellers and accounts tables
! 		 */
! 		if ((strstr(DDLs[i], "create table branches") == DDLs[i]) ||
! 			(strstr(DDLs[i], "create table tellers") == DDLs[i]) ||
! 			(strstr(DDLs[i], "create table accounts") == DDLs[i]))
! 		{
! 			char ddl_stmt[128];
! 			snprintf(ddl_stmt, 128, DDLs[i], fillfactor);
! 			executeStatement(con, ddl_stmt);
! 			continue;
! 		}
! 		else
! 			executeStatement(con, DDLs[i]);
! 	}
  
  	executeStatement(con, "begin");
  
***************
*** 1153,1159 ****
  
  	memset(state, 0, sizeof(*state));
  
! 	while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:U:P:CNSlf:D:")) != -1)
  	{
  		switch (c)
  		{
--- 1174,1180 ----
  
  	memset(state, 0, sizeof(*state));
  
! 	while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:U:P:CNSlf:D:F:")) != -1)
  	{
  		switch (c)
  		{
***************
*** 1258,1263 ****
--- 1279,1292 ----
  					}
  				}
  				break;
+ 			case 'F':
+ 				fillfactor = atoi(optarg);
+ 				if ((fillfactor < 10) || (fillfactor > 100))
+ 				{
+ 					fprintf(stderr, "invalid fillfactor: %d\n", fillfactor);
+ 					exit(1);
+ 				}
+ 				break;
  			default:
  				usage();
  				exit(1);
#10Tatsuo Ishii
ishii@postgresql.org
In reply to: Pavan Deolasee (#9)
Re: [HACKERS] Optimized pgbench for 8.3

Patch committed. Thanks.
--
Tatsuo Ishii
SRA OSS, Inc. Japan

Show quoted text

On 4/6/07, Tatsuo Ishii <ishii@postgresql.org> wrote:

BTW, is anybody working on enabling the fill factor to the tables used
by pgbench? 8.3 will introduce HOT, and I think adding the feature
will make it easier to test HOT.

Please see if the attached patch looks good. It adds a new -F option
which can be used to set fillfactor for tellers, accounts and branches
tables. Default is 100 and anything between 10 and 100 is acceptable.

Thanks,
Pavan

--

EnterpriseDB http://www.enterprisedb.com