Please find attached a small patch submission, for reference to the next commit fest.

Each thread reports its progress about every the number of seconds specified with the option. May be particularly useful for long running pgbench invocations, which should always be the case.

 shell> ./pgbench -T 16 --progress 5 -c 4 -j 2 test
 starting vacuum...end.
 thread 0 running at 53.194457 tps after 5.0 s
 thread 1 running at 59.792203 tps after 5.0 s
 [ bzzzz... ]
 thread 0 running at 56.050592 tps after 10.0 s
 thread 1 running at 54.075444 tps after 10.1 s
 [ bzzzz... ]
 thread 0 running at 49.746026 tps after 15.0 s
 thread 1 running at 48.560258 tps after 15.1 s
 [ bzzzz... ]
 transaction type: TPC-B (sort of)
 scaling factor: 1
 query mode: simple
 number of clients: 4
 number of threads: 2
 duration: 16 s
 number of transactions actually processed: 1725
 tps = 107.034958 (including connections establishing)
 tps = 107.094691 (excluding connections establishing)


--
Fabien.
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index bc01f07..f5de7ab 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -163,6 +163,7 @@ char	   *index_tablespace = NULL;
 bool		use_log;			/* log transaction latencies to a file */
 bool		use_quiet;			/* quiet logging onto stderr */
 int			agg_interval;		/* log aggregates instead of individual transactions */
+int			progress = 0;       /* thread progress report every this seconds */
 bool		is_connect;			/* establish connection for each transaction */
 bool		is_latencies;		/* report per-command latencies */
 int			main_pid;			/* main process id used in log filename */
@@ -361,6 +362,8 @@ usage(void)
 		   "  -S           perform SELECT-only transactions\n"
 	 "  -t NUM       number of transactions each client runs (default: 10)\n"
 		   "  -T NUM       duration of benchmark test in seconds\n"
+		   "  -P SEC, --progress SEC\n"
+		   "               show thread progress report every SEC seconds\n"
 		   "  -v           vacuum all four standard tables before tests\n"
 		   "\nCommon options:\n"
 		   "  -d             print debugging output\n"
@@ -2086,6 +2089,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},
+		{"progress", required_argument, NULL, 'P'},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -2152,7 +2156,7 @@ main(int argc, char **argv)
 	state = (CState *) pg_malloc(sizeof(CState));
 	memset(state, 0, sizeof(CState));
 
-	while ((c = getopt_long(argc, argv, "ih:nvp:dqSNc:j:Crs:t:T:U:lf:D:F:M:", long_options, &optindex)) != -1)
+	while ((c = getopt_long(argc, argv, "ih:nvp:dqSNc:j:Crs:t:T:U:lf:D:F:M:P:", long_options, &optindex)) != -1)
 	{
 		switch (c)
 		{
@@ -2307,6 +2311,16 @@ main(int argc, char **argv)
 					exit(1);
 				}
 				break;
+			case 'P':
+				progress = atoi(optarg);
+				if (progress <= 0)
+				{
+					fprintf(stderr,
+					   "thread progress delay (-P) must not be negative (%s)\n",
+							optarg);
+					exit(1);
+				}
+				break;
 			case 0:
 				/* This covers long options which take no argument. */
 				break;
@@ -2666,6 +2680,9 @@ threadRun(void *arg)
 	int			nstate = thread->nstate;
 	int			remains = nstate;		/* number of remaining clients */
 	int			i;
+	/* for reporting progress: */
+	int64		last_report = INSTR_TIME_GET_MICROSEC(thread->start_time);
+	int64		last_count = 0;
 
 	AggVals		aggs;
 
@@ -2829,6 +2846,29 @@ threadRun(void *arg)
 				st->con = NULL;
 			}
 		}
+
+		/* per thread progress report, about every 5s */
+		if (progress)
+		{
+			instr_time now_time;
+			int64 now, run;
+			INSTR_TIME_SET_CURRENT(now_time);
+			now = INSTR_TIME_GET_MICROSEC(now_time);
+			run = now - last_report;
+			if (run >= progress * 1000000)
+			{
+				/* generate and show report */
+				int64 count = 0;
+				for (i=0; i<nstate; i++)
+					count += state[i].cnt;
+				fprintf(stderr, "thread %d running at %f tps after %.1f s\n",
+						thread->tid, 1000000.0 * (count-last_count) / run,
+						(now - INSTR_TIME_GET_MICROSEC(thread->start_time))/
+						1000000.0);
+				last_count = count;
+				last_report = now;
+			}
+		}
 	}
 
 done:
diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml
index 79b4baf..01c2f7c 100644
--- a/doc/src/sgml/pgbench.sgml
+++ b/doc/src/sgml/pgbench.sgml
@@ -425,6 +425,16 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
      </varlistentry>
 
      <varlistentry>
+      <term><option>-P</option> <replaceable>sec</></term>
+      <term><option>--progress</option> <replaceable>sec</></term>
+      <listitem>
+       <para>
+	Show thread progress report about every <literal>sec</> seconds.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-s</option> <replaceable>scale_factor</></term>
       <listitem>
        <para>
-- 
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