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

Commit9dff14c

Browse files
knizhnikkelvich
authored andcommitted
Make it possible to sepcify update percent in dtmbench for multimaster
1 parent9343f3d commit9dff14c

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

‎contrib/multimaster/tests/dtmbench.cpp‎

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ typedef uint32_t xid_t;
4040
structthread
4141
{
4242
pthread_t t;
43-
size_t proceeded;
43+
size_t transactions;
44+
size_t updates;
45+
size_t selects;
4446
size_t aborts;
4547
int id;
4648

4749
voidstart(int tid,thread_proc_t proc) {
4850
id = tid;
49-
proceeded =0;
51+
updates =0;
52+
selects =0;
5053
aborts =0;
54+
transactions =0;
5155
pthread_create(&t,NULL, proc,this);
5256
}
5357

@@ -62,13 +66,15 @@ struct config
6266
int nWriters;
6367
int nIterations;
6468
int nAccounts;
69+
int updatePercent;
6570
vector<string> connections;
6671

6772
config() {
6873
nReaders =1;
6974
nWriters =10;
7075
nIterations =1000;
7176
nAccounts =100000;
77+
updatePercent =100;
7278
}
7379
};
7480

@@ -123,7 +129,8 @@ void* reader(void* arg)
123129
printf("Total=%ld\n", sum);
124130
prevSum = sum;
125131
}
126-
t.proceeded +=1;
132+
t.transactions +=1;
133+
t.selects +=1;
127134
txn.commit();
128135
}
129136
returnNULL;
@@ -142,16 +149,26 @@ void* writer(void* arg)
142149
int srcAcc =random() % cfg.nAccounts;
143150
int dstAcc =random() % cfg.nAccounts;
144151
try {
145-
exec(txn,"update t set v = v - 1 where u=%d", srcAcc);
146-
exec(txn,"update t set v = v + 1 where u=%d", dstAcc);
152+
if (random() %100 < cfg.updatePercent) {
153+
exec(txn,"update t set v = v - 1 where u=%d", srcAcc);
154+
exec(txn,"update t set v = v + 1 where u=%d", dstAcc);
155+
t.updates +=2;
156+
}else {
157+
int64_t sum =execQuery(txn,"select v from t where u=%d", srcAcc)
158+
+execQuery(txn,"select v from t where u=%d", dstAcc);
159+
if (sum > cfg.nIterations*cfg.nWriters || sum < -cfg.nIterations*cfg.nWriters) {
160+
printf("Wrong sum=%ld\n", sum);
161+
}
162+
t.selects +=2;
163+
}
147164
txn.commit();
165+
t.transactions +=1;
148166
}catch (pqxx_exceptionconst& x) {
149167
txn.abort();
150168
t.aborts +=1;
151169
i -=1;
152170
continue;
153171
}
154-
t.proceeded +=1;
155172
}
156173
returnNULL;
157174
}
@@ -188,6 +205,9 @@ int main (int argc, char* argv[])
188205
case'n':
189206
cfg.nIterations =atoi(argv[++i]);
190207
continue;
208+
case'p':
209+
cfg.updatePercent =atoi(argv[++i]);
210+
continue;
191211
case'c':
192212
cfg.connections.push_back(string(argv[++i]));
193213
continue;
@@ -201,6 +221,7 @@ int main (int argc, char* argv[])
201221
"\t-w N\tnumber of writers (10)\n"
202222
"\t-a N\tnumber of accounts (100000)\n"
203223
"\t-n N\tnumber of iterations (1000)\n"
224+
"\t-p N\tupdate percent (100)\n"
204225
"\t-c STR\tdatabase connection string\n"
205226
"\t-i\tinitialize database\n");
206227
return1;
@@ -216,10 +237,11 @@ int main (int argc, char* argv[])
216237

217238
vector<thread>readers(cfg.nReaders);
218239
vector<thread>writers(cfg.nWriters);
219-
size_t nReads =0;
220-
size_t nWrites =0;
221240
size_t nAborts =0;
222-
241+
size_t nUpdates =0;
242+
size_t nSelects =0;
243+
size_t nTransactions =0;
244+
223245
for (int i =0; i < cfg.nReaders; i++) {
224246
readers[i].start(i, reader);
225247
}
@@ -229,29 +251,35 @@ int main (int argc, char* argv[])
229251

230252
for (int i =0; i < cfg.nWriters; i++) {
231253
writers[i].wait();
232-
nWrites += writers[i].proceeded;
254+
nUpdates += writers[i].updates;
255+
nSelects += writers[i].selects;
233256
nAborts += writers[i].aborts;
257+
nTransactions += writers[i].transactions;
234258
}
235259

236260
running =false;
237261

238262
for (int i =0; i < cfg.nReaders; i++) {
239263
readers[i].wait();
240-
nReads += readers[i].proceeded;
264+
nSelects += readers[i].selects;
265+
nTransactions += writers[i].transactions;
241266
}
242267

243268
time_t elapsed =getCurrentTime() - start;
244269

245270
printf(
246-
"{\"update_tps\":%f,\"read_tps\":%f,"
247-
"\"readers\":%d,\"writers\":%d,\"aborts\":%ld,\"abort_percent\": %d,"
248-
"\"accounts\":%d,\"iterations\":%d,\"hosts\":%ld}\n",
249-
(double)(nWrites*USEC)/elapsed,
250-
(double)(nReads*USEC)/elapsed,
271+
"{\"tps\":%f,\"transactions\":%ld,"
272+
"\"selects\":%ld,\"updates\":%ld,\"aborts\":%ld,\"abort_percent\": %d,"
273+
"\"readers\":%d,\"writers\":%d,\"update_percent\":%d,\"accounts\":%d,\"iterations\":%d,\"hosts\":%ld}\n",
274+
(double)(nTransactions*USEC)/elapsed,
275+
nTransactions,
276+
nSelects,
277+
nUpdates,
278+
nAborts,
279+
(int)(nAborts*100/nTransactions),
251280
cfg.nReaders,
252281
cfg.nWriters,
253-
nAborts,
254-
(int)(nAborts*100/nWrites),
282+
cfg.updatePercent,
255283
cfg.nAccounts,
256284
cfg.nIterations,
257285
cfg.connections.size()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp