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

Commit6b45e3b

Browse files
committed
Arrange to generate different random sequences in the different child
processes of a pgbench run, when we are using -j > 1 and are emulatingthreads via fork(). Otherwise the children all inherit the same randomsequence state and produce the same random-number sequence.In the threaded case the different threads will share one RNG state, sothey will produce different subsets of one sequence, which is maybe morecorrelated than a purist would like but will not be "the same". So weleave that case alone.First noticed by Takahiro Itagaki, and is also part of the explanationfor the pgbench misbehavior recently reported by Jaime Casanova.
1 parentd8e511f commit6b45e3b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 16 additions & 4 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.91 2009/09/10 13:59:57 ishii Exp $
7+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.92 2009/12/11 21:50:06 tgl Exp $
88
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
99
* ALL RIGHTS RESERVED;
1010
*
@@ -1916,7 +1916,7 @@ main(int argc, char **argv)
19161916
INSTR_TIME_SET_CURRENT(start_time);
19171917
srandom((unsignedint)INSTR_TIME_GET_MICROSEC(start_time));
19181918

1919-
/* processbultin SQL scripts */
1919+
/* processbuiltin SQL scripts */
19201920
switch (ttype)
19211921
{
19221922
case0:
@@ -2201,6 +2201,7 @@ pthread_create(pthread_t *thread,
22012201
{
22022202
fork_pthread*th;
22032203
void*ret;
2204+
instr_timestart_time;
22042205

22052206
th= (fork_pthread*)malloc(sizeof(fork_pthread));
22062207
pipe(th->pipes);
@@ -2211,20 +2212,31 @@ pthread_create(pthread_t *thread,
22112212
free(th);
22122213
returnerrno;
22132214
}
2214-
if (th->pid!=0)/* parent process */
2215+
if (th->pid!=0)/*inparent process */
22152216
{
22162217
close(th->pipes[1]);
22172218
*thread=th;
22182219
return0;
22192220
}
22202221

2221-
/* child process */
2222+
/*inchild process */
22222223
close(th->pipes[0]);
22232224

22242225
/* set alarm again because the child does not inherit timers */
22252226
if (duration>0)
22262227
setalarm(duration);
22272228

2229+
/*
2230+
* Set a different random seed in each child process. Otherwise they
2231+
* all inherit the parent's state and generate the same "random"
2232+
* sequence. (In the threaded case, the different threads will obtain
2233+
* subsets of the output of a single random() sequence, which should be
2234+
* okay for our purposes.)
2235+
*/
2236+
INSTR_TIME_SET_CURRENT(start_time);
2237+
srandom(((unsignedint)INSTR_TIME_GET_MICROSEC(start_time))+
2238+
((unsignedint)getpid()));
2239+
22282240
ret=start_routine(arg);
22292241
write(th->pipes[1],ret,sizeof(TResult));
22302242
close(th->pipes[1]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp