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

Commit0f17da9

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Added a new scripting meta command
\usleep [milliseconds|:variable]which can be used in -f scripts to insert a thinking time betweenother commands.Jan
1 parent7af3a6f commit0f17da9

File tree

2 files changed

+107
-6
lines changed

2 files changed

+107
-6
lines changed

‎contrib/pgbench/README.pgbench

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PostgreSQL: pgsql/contrib/pgbench/README.pgbench,v 1.18 2007/04/08 01:15:07 ishii Exp $
1+
$PostgreSQL: pgsql/contrib/pgbench/README.pgbench,v 1.19 2007/07/06 13:36:55 wieck Exp $
22

33
pgbench README
44

@@ -231,6 +231,16 @@ o -f option
231231

232232
Variables can also be defined by using -D option.
233233

234+
\usleep usec
235+
236+
causes script execution to sleep for the specified duration in
237+
microseconds.
238+
239+
example:
240+
241+
\setrandom usec 1000000 3000000
242+
\usleep :usec
243+
234244
Example, TPC-B like benchmark can be defined as follows(scaling
235245
factor = 1):
236246

‎contrib/pgbench/pgbench.c

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.66 2007/05/24 18:54:10 tgl Exp $
2+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.67 2007/07/06 13:36:55 wieck Exp $
33
*
44
* pgbench: a simple benchmark program for PostgreSQL
55
* written by Tatsuo Ishii
@@ -114,6 +114,8 @@ typedef struct
114114
intecnt;/* error count */
115115
intlisten;/* 0 indicates that an async query has been
116116
* sent */
117+
intsleeping;/* 1 indicates that the client is napping */
118+
structtimevaluntil;/* napping until */
117119
Variable*variables;/* array of variable definitions */
118120
intnvariables;
119121
structtimevaltxn_begin;/* used for measuring latencies */
@@ -445,6 +447,20 @@ doCustom(CState * state, int n, int debug)
445447
top:
446448
commands=sql_files[st->use_file];
447449

450+
if (st->sleeping)
451+
{/* are we sleeping? */
452+
intusec;
453+
structtimevalnow;
454+
455+
gettimeofday(&now,NULL);
456+
usec= (st->until.tv_sec-now.tv_sec)*1000000+
457+
st->until.tv_usec-now.tv_usec;
458+
if (usec <=0)
459+
st->sleeping=0;/* Done sleeping, go ahead with next command */
460+
else
461+
return;/* Still sleeping, nothing to do here */
462+
}
463+
448464
if (st->listen)
449465
{/* are we receiver? */
450466
if (commands[st->state]->type==SQL_COMMAND)
@@ -711,6 +727,32 @@ doCustom(CState * state, int n, int debug)
711727

712728
st->listen=1;
713729
}
730+
elseif (pg_strcasecmp(argv[0],"usleep")==0)
731+
{
732+
char*var;
733+
intusec;
734+
structtimevalnow;
735+
736+
if (*argv[1]==':')
737+
{
738+
if ((var=getVariable(st,argv[1]+1))==NULL)
739+
{
740+
fprintf(stderr,"%s: undefined variable %s\n",argv[0],argv[1]);
741+
st->ecnt++;
742+
return;
743+
}
744+
usec=atoi(var);
745+
}
746+
else
747+
usec=atoi(argv[1]);
748+
749+
gettimeofday(&now,NULL);
750+
st->until.tv_sec=now.tv_sec+ (now.tv_usec+usec) /1000000;
751+
st->until.tv_usec= (now.tv_usec+usec) %1000000;
752+
st->sleeping=1;
753+
754+
st->listen=1;
755+
}
714756

715757
gototop;
716758
}
@@ -921,9 +963,21 @@ process_commands(char *buf)
921963
fprintf(stderr,"%s: extra argument \"%s\" ignored\n",
922964
my_commands->argv[0],my_commands->argv[j]);
923965
}
966+
elseif (pg_strcasecmp(my_commands->argv[0],"usleep")==0)
967+
{
968+
if (my_commands->argc<2)
969+
{
970+
fprintf(stderr,"%s: missing argument\n",my_commands->argv[0]);
971+
returnNULL;
972+
}
973+
974+
for (j=2;j<my_commands->argc;j++)
975+
fprintf(stderr,"%s: extra argument \"%s\" ignored\n",
976+
my_commands->argv[0],my_commands->argv[j]);
977+
}
924978
else
925979
{
926-
fprintf(stderr,"invalid command %s\n",my_commands->argv[0]);
980+
fprintf(stderr,"Invalid command %s\n",my_commands->argv[0]);
927981
returnNULL;
928982
}
929983
}
@@ -1143,6 +1197,9 @@ main(int argc, char **argv)
11431197
fd_setinput_mask;
11441198
intnsocks;/* return from select(2) */
11451199
intmaxsock;/* max socket number to be waited */
1200+
structtimevalnow;
1201+
structtimevaltimeout;
1202+
intmin_usec;
11461203

11471204
#ifdefHAVE_GETRLIMIT
11481205
structrlimitrlim;
@@ -1526,11 +1583,33 @@ main(int argc, char **argv)
15261583
FD_ZERO(&input_mask);
15271584

15281585
maxsock=-1;
1586+
min_usec=-1;
15291587
for (i=0;i<nclients;i++)
15301588
{
15311589
Command**commands=sql_files[state[i].use_file];
15321590

1533-
if (state[i].con&&commands[state[i].state]->type!=META_COMMAND)
1591+
if (state[i].sleeping)
1592+
{
1593+
intthis_usec;
1594+
intsock=PQsocket(state[i].con);
1595+
1596+
if (min_usec<0)
1597+
{
1598+
gettimeofday(&now,NULL);
1599+
min_usec=0;
1600+
}
1601+
1602+
this_usec= (state[i].until.tv_sec-now.tv_sec)*1000000+
1603+
state[i].until.tv_usec-now.tv_usec;
1604+
1605+
if (this_usec>0&& (min_usec==0||this_usec<min_usec))
1606+
min_usec=this_usec;
1607+
1608+
FD_SET(sock,&input_mask);
1609+
if (maxsock<sock)
1610+
maxsock=sock;
1611+
}
1612+
elseif (state[i].con&&commands[state[i].state]->type!=META_COMMAND)
15341613
{
15351614
intsock=PQsocket(state[i].con);
15361615

@@ -1547,8 +1626,18 @@ main(int argc, char **argv)
15471626

15481627
if (maxsock!=-1)
15491628
{
1550-
if ((nsocks=select(maxsock+1,&input_mask, (fd_set*)NULL,
1551-
(fd_set*)NULL, (structtimeval*)NULL))<0)
1629+
if (min_usec >=0)
1630+
{
1631+
timeout.tv_sec=min_usec /1000000;
1632+
timeout.tv_usec=min_usec %1000000;
1633+
1634+
nsocks=select(maxsock+1,&input_mask, (fd_set*)NULL,
1635+
(fd_set*)NULL,&timeout);
1636+
}
1637+
else
1638+
nsocks=select(maxsock+1,&input_mask, (fd_set*)NULL,
1639+
(fd_set*)NULL, (structtimeval*)NULL);
1640+
if (nsocks<0)
15521641
{
15531642
if (errno==EINTR)
15541643
continue;
@@ -1557,6 +1646,7 @@ main(int argc, char **argv)
15571646
fprintf(stderr,"select failed: %s\n",strerror(errno));
15581647
exit(1);
15591648
}
1649+
#ifdefNOT_USED
15601650
elseif (nsocks==0)
15611651
{/* timeout */
15621652
fprintf(stderr,"select timeout\n");
@@ -1567,6 +1657,7 @@ main(int argc, char **argv)
15671657
}
15681658
exit(0);
15691659
}
1660+
#endif
15701661
}
15711662

15721663
/* ok, backend returns reply */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp