Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ffb14f

Browse files
committed
Portability and documentation fixes for threaded pgbench patch.
1 parent3da0dfb commit7ffb14f

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

‎contrib/pgbench/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# $PostgreSQL: pgsql/contrib/pgbench/Makefile,v 1.16 2007/11/10 23:59:51 momjian Exp $
1+
# $PostgreSQL: pgsql/contrib/pgbench/Makefile,v 1.17 2009/08/03 18:30:55 tgl Exp $
22

33
PROGRAM = pgbench
44
OBJS= pgbench.o
55

66
PG_CPPFLAGS = -I$(libpq_srcdir)
7-
PG_LIBS =$(libpq_pgport)
7+
PG_LIBS =$(libpq_pgport)$(PTHREAD_LIBS)
88

99
ifdefUSE_PGXS
1010
PG_CONFIG = pg_config
@@ -16,3 +16,7 @@ top_builddir = ../..
1616
include$(top_builddir)/src/Makefile.global
1717
include$(top_srcdir)/contrib/contrib-global.mk
1818
endif
19+
20+
ifneq ($(PORTNAME), win32)
21+
overrideCFLAGS +=$(PTHREAD_CFLAGS)
22+
endif

‎contrib/pgbench/pgbench.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* A simple benchmark program for PostgreSQL
55
* Originally written by Tatsuo Ishii and enhanced by many contributors.
66
*
7-
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.89 2009/08/0315:18:14 ishii Exp $
7+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.90 2009/08/03 18:30:55 tgl Exp $
88
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
99
* ALL RIGHTS RESERVED;
1010
*
@@ -71,23 +71,27 @@
7171
/* Use native win32 threads on Windows */
7272
typedefstructwin32_pthread*pthread_t;
7373
typedefintpthread_attr_t;
74+
7475
staticintpthread_create(pthread_t*thread,pthread_attr_t*attr,void* (*start_routine)(void*),void*arg);
7576
staticintpthread_join(pthread_tth,void**thread_return);
7677

7778
#elif defined(ENABLE_THREAD_SAFETY)
78-
/* Use platform-dependent pthread */
79+
/* Use platform-dependent pthreadcapability*/
7980
#include<pthread.h>
8081

8182
#else
83+
/* Use emulation with fork. Rename pthread identifiers to avoid conflicts */
8284

8385
#include<sys/wait.h>
84-
/* Use emulation with fork. Rename pthread idendifiers to avoid conflictions */
86+
8587
#definepthread_tpg_pthread_t
8688
#definepthread_attr_tpg_pthread_attr_t
8789
#definepthread_createpg_pthread_create
8890
#definepthread_joinpg_pthread_join
91+
8992
typedefstructfork_pthread*pthread_t;
9093
typedefintpthread_attr_t;
94+
9195
staticintpthread_create(pthread_t*thread,pthread_attr_t*attr,void* (*start_routine)(void*),void*arg);
9296
staticintpthread_join(pthread_tth,void**thread_return);
9397

@@ -136,7 +140,7 @@ FILE *LOGFILE = NULL;
136140

137141
booluse_log;/* log transaction latencies to a file */
138142

139-
intis_connect;/* establish connectionfor each transaction */
143+
intis_connect;/* establish connection for each transaction */
140144

141145
char*pghost="";
142146
char*pgport="";
@@ -185,7 +189,7 @@ typedef struct
185189
{
186190
pthread_tthread;/* thread handle */
187191
CState*state;/* array of CState */
188-
intnstate;/* length of state */
192+
intnstate;/* length of state[] */
189193
instr_timestart_time;/* thread start time */
190194
}TState;
191195

@@ -647,20 +651,25 @@ doCustom(CState *st, instr_time *conn_time)
647651
*/
648652
if (use_log&&commands[st->state+1]==NULL)
649653
{
654+
instr_timenow;
650655
instr_timediff;
651-
doublesec;
652-
doublemsec;
653656
doubleusec;
654657

655-
INSTR_TIME_SET_CURRENT(diff);
658+
INSTR_TIME_SET_CURRENT(now);
659+
diff=now;
656660
INSTR_TIME_SUBTRACT(diff,st->txn_begin);
657-
sec=INSTR_TIME_GET_DOUBLE(diff);
658-
msec=INSTR_TIME_GET_MILLISEC(diff);
659661
usec= (double)INSTR_TIME_GET_MICROSEC(diff);
660662

661-
fprintf(LOGFILE,"%d %d %.0f %d %.0f %.0f\n",
663+
#ifndefWIN32
664+
/* This is more than we really ought to know about instr_time */
665+
fprintf(LOGFILE,"%d %d %.0f %d %ld %ld\n",
662666
st->id,st->cnt,usec,st->use_file,
663-
sec,usec-sec*1000.0);
667+
(long)now.tv_sec, (long)now.tv_usec);
668+
#else
669+
/* On Windows, instr_time doesn't provide a timestamp anyway */
670+
fprintf(LOGFILE,"%d %d %.0f %d 0 0\n",
671+
st->id,st->cnt,usec,st->use_file);
672+
#endif
664673
}
665674

666675
if (commands[st->state]->type==SQL_COMMAND)
@@ -1269,15 +1278,17 @@ process_commands(char *buf)
12691278
}
12701279

12711280
/*
1272-
* Split argument into number and unitfor"sleep 1ms"or so.
1281+
* Split argument into number and unitto allow"sleep 1ms"etc.
12731282
* We don't have to terminate the number argument with null
1274-
* because it will parsed with atoi,that ignores trailing
1283+
* because it willbeparsed with atoi,which ignores trailing
12751284
* non-digit characters.
12761285
*/
12771286
if (my_commands->argv[1][0]!=':')
12781287
{
12791288
char*c=my_commands->argv[1];
1280-
while (isdigit(*c)) {c++; }
1289+
1290+
while (isdigit((unsignedchar)*c))
1291+
c++;
12811292
if (*c)
12821293
{
12831294
my_commands->argv[2]=c;
@@ -1772,7 +1783,7 @@ main(int argc, char **argv)
17721783

17731784
if (nclients %nthreads!=0)
17741785
{
1775-
fprintf(stderr,"number of clients (%d) must be a multiple number of threads (%d)\n",nclients,nthreads);
1786+
fprintf(stderr,"number of clients (%d) must be a multipleofnumber of threads (%d)\n",nclients,nthreads);
17761787
exit(1);
17771788
}
17781789

‎doc/src/sgml/pgbench.sgml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgbench.sgml,v 1.9 2009/08/0315:18:14 ishii Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgbench.sgml,v 1.10 2009/08/03 18:30:55 tgl Exp $ -->
22

33
<sect1 id="pgbench">
44
<title>pgbench</title>
@@ -27,13 +27,14 @@ transaction type: TPC-B (sort of)
2727
scaling factor: 10
2828
query mode: simple
2929
number of clients: 10
30+
number of threads: 1
3031
number of transactions per client: 1000
3132
number of transactions actually processed: 10000/10000
3233
tps = 85.184871 (including connections establishing)
3334
tps = 85.296346 (excluding connections establishing)
3435
</programlisting>
3536

36-
The firstfive lines report some of the most important parameter
37+
The firstsix lines report some of the most important parameter
3738
settings. The next line reports the number of transactions completed
3839
and intended (the latter being just the product of number of clients
3940
and number of transactions per client); these will be equal unless the run
@@ -174,9 +175,11 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
174175
<row>
175176
<entry><literal>-j</literal> <replaceable>threads</></entry>
176177
<entry>
177-
Number of worker threads. Clients are equally-divided into those
178-
threads and executed in it. The number of clients must be a multiple
179-
number of threads. Default is 1.
178+
Number of worker threads within <application>pgbench</application>.
179+
Using more than one thread can be helpful on multi-CPU machines.
180+
The number of clients must be a multiple of the number of threads,
181+
since each thread is given the same number of client sessions to manage.
182+
Default is 1.
180183
</entry>
181184
</row>
182185
<row>
@@ -267,7 +270,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
267270
<entry><literal>-C</literal></entry>
268271
<entry>
269272
Establish a new connection for each transaction, rather than
270-
doing it just once per clientthread.
273+
doing it just once per clientsession.
271274
This is useful to measure the connection overhead.
272275
</entry>
273276
</row>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp