After publishing some test results with pgbench on SSD with varying page size, Josh Berkus pointed out that pgbench uses small 100-bytes tuples, and that results may be different with other tuple sizes.

This patch adds an option to change the default tuple size, so that this can be tested easily.

--
Fabien.
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 2f7d80e..709022c 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -119,6 +119,10 @@ int			scale = 1;
  */
 int			fillfactor = 100;
 
+/* approximate number of bytes for rows
+ */
+int			tupsize = 100;
+
 /*
  * create foreign key constraints on the tables?
  */
@@ -359,6 +363,7 @@ usage(void)
 	"                           create indexes in the specified tablespace\n"
 	 "  --tablespace=TABLESPACE  create tables in the specified tablespace\n"
 		   "  --unlogged-tables        create tables as unlogged tables\n"
+		   "  --tuple-size=NUM         target tuple size (default: 100)\n"
 		   "\nBenchmarking options:\n"
 		   "  -c, --client=NUM         number of concurrent database clients (default: 1)\n"
 		   "  -C, --connect            establish new connection for each transaction\n"
@@ -1704,32 +1709,37 @@ init(bool is_no_vacuum)
 		const char *table;		/* table name */
 		const char *smcols;		/* column decls if accountIDs are 32 bits */
 		const char *bigcols;	/* column decls if accountIDs are 64 bits */
-		int			declare_fillfactor;
+		int			declare_fillfactor; /* whether to add a fillfactor */
+		int			tupsize_correction; /* tupsize correction */
 	};
 	static const struct ddlinfo DDLs[] = {
 		{
 			"pgbench_history",
-			"tid int,bid int,aid    int,delta int,mtime timestamp,filler char(22)",
-			"tid int,bid int,aid bigint,delta int,mtime timestamp,filler char(22)",
-			0
+			"tid int,bid int,aid    int,delta int,mtime timestamp,filler char",
+			"tid int,bid int,aid bigint,delta int,mtime timestamp,filler char",
+			0,
+			78
 		},
 		{
 			"pgbench_tellers",
-			"tid int not null,bid int,tbalance int,filler char(84)",
-			"tid int not null,bid int,tbalance int,filler char(84)",
-			1
+			"tid int not null,bid int,tbalance int,filler char",
+			"tid int not null,bid int,tbalance int,filler char",
+			1,
+			16
 		},
 		{
 			"pgbench_accounts",
-			"aid    int not null,bid int,abalance int,filler char(84)",
-			"aid bigint not null,bid int,abalance int,filler char(84)",
-			1
+			"aid    int not null,bid int,abalance int,filler char",
+			"aid bigint not null,bid int,abalance int,filler char",
+			1,
+			16
 		},
 		{
 			"pgbench_branches",
-			"bid int not null,bbalance int,filler char(88)",
-			"bid int not null,bbalance int,filler char(88)",
-			1
+			"bid int not null,bbalance int,filler char",
+			"bid int not null,bbalance int,filler char",
+			1,
+			12
 		}
 	};
 	static const char *const DDLINDEXes[] = {
@@ -1767,6 +1777,9 @@ init(bool is_no_vacuum)
 		char		buffer[256];
 		const struct ddlinfo *ddl = &DDLs[i];
 		const char *cols;
+		int 		ts = tupsize - ddl->tupsize_correction;
+
+		if (ts < 1) ts = 1;
 
 		/* Remove old table, if it exists. */
 		snprintf(buffer, sizeof(buffer), "drop table if exists %s", ddl->table);
@@ -1790,9 +1803,9 @@ init(bool is_no_vacuum)
 
 		cols = (scale >= SCALE_32BIT_THRESHOLD) ? ddl->bigcols : ddl->smcols;
 
-		snprintf(buffer, sizeof(buffer), "create%s table %s(%s)%s",
+		snprintf(buffer, sizeof(buffer), "create%s table %s(%s(%d))%s",
 				 unlogged_tables ? " unlogged" : "",
-				 ddl->table, cols, opts);
+				 ddl->table, cols, ts, opts);
 
 		executeStatement(con, buffer);
 	}
@@ -2504,6 +2517,7 @@ main(int argc, char **argv)
 		{"unlogged-tables", no_argument, &unlogged_tables, 1},
 		{"sampling-rate", required_argument, NULL, 4},
 		{"aggregate-interval", required_argument, NULL, 5},
+		{"tuple-size", required_argument, NULL, 6},
 		{"rate", required_argument, NULL, 'R'},
 		{NULL, 0, NULL, 0}
 	};
@@ -2811,6 +2825,15 @@ main(int argc, char **argv)
 				}
 #endif
 				break;
+			case 6:
+				initialization_option_set = true;
+				tupsize = atoi(optarg);
+				if (tupsize <= 0)
+				{
+					fprintf(stderr, "invalid tuple size: %d\n", tupsize);
+					exit(1);
+				}
+				break;
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
 				exit(1);
diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml
index 23bfa9e..e6210e7 100644
--- a/doc/src/sgml/pgbench.sgml
+++ b/doc/src/sgml/pgbench.sgml
@@ -515,6 +515,15 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
      </varlistentry>
 
      <varlistentry>
+      <term><option>--tuple-size=</option><replaceable>size</></term>
+      <listitem>
+       <para>
+        Set target size of tuples. Default is 100 bytes.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-v</option></term>
       <term><option>--vacuum-all</option></term>
       <listitem>
-- 
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