@@ -2819,6 +2819,7 @@ main(int argc, char **argv)
2819
2819
int64 latency_late = 0 ;
2820
2820
2821
2821
int i ;
2822
+ int nclients_dealt ;
2822
2823
2823
2824
#ifdef HAVE_GETRLIMIT
2824
2825
struct rlimit rlim ;
@@ -3114,6 +3115,14 @@ main(int argc, char **argv)
3114
3115
}
3115
3116
}
3116
3117
3118
+ /*
3119
+ * Don't need more threads than there are clients. (This is not merely an
3120
+ * optimization; throttle_delay is calculated incorrectly below if some
3121
+ * threads have no clients assigned to them.)
3122
+ */
3123
+ if (nthreads > nclients )
3124
+ nthreads = nclients ;
3125
+
3117
3126
/* compute a per thread delay */
3118
3127
throttle_delay *= nthreads ;
3119
3128
@@ -3153,12 +3162,6 @@ main(int argc, char **argv)
3153
3162
if (nxacts <= 0 && duration <= 0 )
3154
3163
nxacts = DEFAULT_NXACTS ;
3155
3164
3156
- if (nclients % nthreads != 0 )
3157
- {
3158
- fprintf (stderr , "number of clients (%d) must be a multiple of number of threads (%d)\n" , nclients , nthreads );
3159
- exit (1 );
3160
- }
3161
-
3162
3165
/* --sampling-rate may be used only with -l */
3163
3166
if (sample_rate > 0.0 && !use_log )
3164
3167
{
@@ -3359,19 +3362,24 @@ main(int argc, char **argv)
3359
3362
3360
3363
/* set up thread data structures */
3361
3364
threads = (TState * ) pg_malloc (sizeof (TState ) * nthreads );
3365
+ nclients_dealt = 0 ;
3366
+
3362
3367
for (i = 0 ; i < nthreads ; i ++ )
3363
3368
{
3364
3369
TState * thread = & threads [i ];
3365
3370
3366
3371
thread -> tid = i ;
3367
- thread -> state = & state [nclients / nthreads * i ];
3368
- thread -> nstate = nclients / nthreads ;
3372
+ thread -> state = & state [nclients_dealt ];
3373
+ thread -> nstate =
3374
+ (nclients - nclients_dealt + nthreads - i - 1 ) / (nthreads - i );
3369
3375
thread -> random_state [0 ] = random ();
3370
3376
thread -> random_state [1 ] = random ();
3371
3377
thread -> random_state [2 ] = random ();
3372
3378
thread -> throttle_latency_skipped = 0 ;
3373
3379
thread -> latency_late = 0 ;
3374
3380
3381
+ nclients_dealt += thread -> nstate ;
3382
+
3375
3383
if (is_latencies )
3376
3384
{
3377
3385
/* Reserve memory for the thread to store per-command latencies */
@@ -3395,6 +3403,9 @@ main(int argc, char **argv)
3395
3403
}
3396
3404
}
3397
3405
3406
+ /* all clients must be assigned to a thread */
3407
+ Assert (nclients_dealt == nclients );
3408
+
3398
3409
/* get start up time */
3399
3410
INSTR_TIME_SET_CURRENT (start_time );
3400
3411
0 commit comments