测试数据库schema:

drop table if exists t1;

drop table if exists t2;

drop table if exists t3;

create table t1(id int primary key, value1 int, value2 varchar(200));

create index s1 on t1(value1);

create table t2(id int primary key, value1 int, value2 varchar(200));

create index s2 on t2(value1);

create table t3(id int primary key, value1 int, value2 varchar(200));

create index s3 on t3(value1);

t1:1000万行;t2:1亿行;t3:3亿行。

id是连续的;value1为0 - 1000000000之间的随机值;value2为平均长度为100,最大长度为200的字符串。

PG和MySQL的配置请看:

http://blog.csdn.net/liyuming0000/article/details/51023511

http://blog.csdn.net/liyuming0000/article/details/51014191

测试负载:

1.      单表上的不同类型读负载

单点(主键)随机读负载

主键范围读负载

非主键的读(二级索引读)负载

2.      短事务

单行更新操作(insert、delete、replace、update)

QPS:每秒查询数

QRS:查询响应时间(单位为ms)

TPS:每秒事务数

TRS:事务响应时间(单位为ms)

统计表中第二栏的响应时间与第一栏的每秒操作数按顺序一一对应

实验一

实验目的:测试MySQL和PG针对主键随机读负载的最优吞吐量。

测试负载:select value1 from table where id = ?,以预编译的形式执行,id是在主键范围上均匀分布。

MySQL:

数据表t1:

线程数

QPS

QRS

10

35522, 36419

0.285, 0.279

20

64540, 64716

0.314, 0.313

50

107399, 105946

0.473, 0.480

100

109425, 110050

0.922, 0.917

150

109569, 111209

1.381, 1.361

200

115449, 115601

1.747, 1.744

250

116336, 116004

2.167, 2.173

300

115520, 115265

2.626, 2.629

数据表t2:

线程数

QPS

QRS

10

2679, 35821

3.735, 0.282

20

22583, 63940

0.889, 0.316

50

81851, 107456

0.619, 0.474

100

94480, 109425

1.068, 0.921

150

108686, 109180

1.390, 1.387

200

116322, 115101

1.733, 1.751

250

116211, 114987

2.168, 2.190

300

115134, 114702

2.630, 2.643

数据表t3:

线程数

QPS

QRS

10

1110, 30518

8.989, 0.331

20

3717, 52904

5.369, 0.384

50

18882, 75080

2.655, 0.675

100

42844, 87145

2.342, 1.156

150

98669, 91366

1.530, 1.654

200

61733, 88915

3.247, 2.259

250

67503, 85314

3.712, 2.942

300

88601, 84400

3.407, 3.570

PG:

数据表t1:

线程数

QPS

QRS

10

37879, 38148, 12728, 38237

0.275, 0.266, 0.790, 0.265

20

75037, 68906, 78759, 77142

0.273, 0.294, 0.261, 0.265

50

139676, 135779, 137780, 135497

0.366, 0.375, 0.371, 0.377

100

181549, 185476, 175890, 173170

0.560, 0.548, 0.580, 0.588

150

222857, 219711, 230571, 204284

0.695, 0.698, 0.670, 0.751

200

245709, 231214, 245812, 240065

0.834, 0.878, 0.836, 0.851

250

246533, 228139, 248405, 238104

1.044, 1.115, 1.041, 1.075

300

246229, 237196, 239975, 226885

1.259, 1.302, 1.294, 1.357

数据表t2:

线程数

QPS

QRS

10

30784, 37991, 917, 35821

0.329, 0.274, 10.867, 0.282

20

54830, 70700, 7591, 72989

0.370, 0.287, 2.636, 0.280

50

122400, 136795, 91058, 137434

0.417, 0.374, 0.558, 0.372

100

131690, 180934, 132992, 179460

0.768, 0.563, 0.780, 0.567

150

152968, 206199, 196900, 217128

0.993, 0.743, 0.776, 0.706

200

182414, 221721, 221870, 221576

1.112, 0.924, 0.921, 0.921

250

212466, 225449, 221794, 215628

1.210, 1.142, 1.154, 1.184

300

168306, 212136, 211857, 206145

1.813, 1.455, 1.456, 1.491

数据表t3:

线程数

QPS

QRS

10

330, 1958, 961, 5021

29.612, 5.097, 10.348, 1.993

20

1728, 4049, 4533, 31004

11.522, 4.935, 4.406, 0.649

50

3158, 6568, 7593, 83657

15.717, 7.596, 6.574, 0.606

100

3520, 25436, 9688, 108118

27.875, 3.933, 10.279, 0.934

150

3600, 23254, 10862, 121425

40.687, 6.445, 13.718, 1.247

200

3497, 70062, 14395, 124518

55.519, 2.862, 13.801, 1.618

250

3500, 121358, 10639, 27538

69.554, 2.096, 23.299, 9.050

300

3321, 19276, 6610, 99964

84.137, 15.477, 44.068, 3.024

实验二

实验目的:测试MySQL和PG针对主键范围读负载的最优吞吐量。

测试负载:select value1 from table where id between ? and ?,以预编译的形式执行,第一个id在主键范围上均匀分布,range大小为0- 100的一个随机值。

MySQL:

数据表t1:

线程数

QPS

QRS

10

22452, 25006

0.449, 0.403

20

43140, 43006

0.468, 0.472

50

70608, 70080

0.715, 0.721

100

94768, 95183

1.063, 1.059

150

97737, 97151

1.545, 1.555

200

97927, 98472

2.050, 2.040

250

98619, 99345

2.547, 2.530

300

100064, 99955

3.017, 3.021

数据表t2:

线程数

QPS

QRS

10

2570, 24857

3.884, 0.405

20

29401, 42460

0.684, 0.477

50

61110, 70015

0.827, 0.720

100

94516, 94408

1.067, 1.068

150

96446, 96910

1.567, 1.561

200

97494, 97542

2.061, 2.060

250

97760, 97704

2.570, 2.571

300

98889, 98637

3.054, 3.062

数据表t3:

线程数

QPS

QRS

10

9572, 21742

1.047, 0.463

20

20050, 33051

1.001, 0.610

50

21181, 36658

2.364, 1.370

100

27500, 30698

3.639, 3.260

150

29248, 31415

5.138, 4.777

200

28920, 31580

6.901, 6.331

250

28576, 31648

8.737, 7.899

300

28379, 28405

10.547, 10.535

PG:

数据表t1:

线程数

QPS

QRS

10

9186, 16412

1.091, 0.613

20

25985, 25271

0.775, 0.797

50

46036, 46076

1.094, 1.095

100

53837, 53283

1.868, 1.886

150

58129, 58131

2.594, 2.593

200

57260, 57216

3.501, 3.504

250

56566, 57160

4.431, 4.386

300

55157, 55696

5.458, 5.404

数据表t2:

线程数

QPS

QRS

10

669, 23234

14.835, 0.436

20

1546, 38537

12.839, 0.523

50

60498, 77893

0.835, 0.650

100

80612, 94784

1.255, 1.068

150

93270, 93079

1.622, 1.625

200

89407, 89216

2.250, 2.255

250

81304, 79588

3.092, 3.157

300

75970, 64522

3.969, 4.672

数据表t3:

线程数

QPS

QRS

10

478, 22644

20.777, 0.444

20

6711, 36593

2.981, 0.550

50

6810, 57875

7.325, 0.871

100

11043, 61672

9.021, 1.630

150

64012, 62183

2.354, 2.423

200

56233, 55116

3.561, 3.634

250

49752, 50874

5.033, 4.923

300

46629, 46937

6.442, 6.402

实验三

实验目的:测试MySQL和PG针对非主键随机读(二级索引读)负载的最优吞吐量。

测试负载:select * from table where value1 = ?,以预编译的形式执行,value1为0- 1000000000之间的随机值。

MySQL:

数据表t1:

线程数

QPS

QRS

10

29816, 31100

0.340, 0.325

20

54376, 55684

0.372, 0.362

50

84479, 87363

0.600, 0.577

100

91269, 93196

1.117, 1.104

150

93550, 92525

1.631, 1.649

200

95492, 93564

2.124, 2.170

250

92432, 92742

2.738, 2.729

300

91378, 91544

3.314, 3.307

数据表t2:

线程数

QPS

QRS

10

12599, 31100

0.797, 0.325

20

29404, 53556

0.688, 0.377

50

54002, 78978

0.930, 0.637

100

63735, 71337

1.601, 1.436

150

63476, 84751

2.394, 1.801

200

94778, 94339

2.140, 2.151

250

92824, 90551

2.727, 2.793

300

91093, 87221

3.325, 3.473

数据表t3:

线程数

QPS

QRS

10

5766, 29885

1.735, 0.338

20

47508, 52086

0.425, 0.386

50

78072, 81274

0.644, 0.619

100

117900, 104350

0.879, 0.991

150

119688, 99406

1.293, 1.547

200

116280, 99048

1.749, 2.050

250

111753, 101421

2.272, 2.500

300

101104, 103070

3.001, 2.944

PG:

数据表t1:

线程数

QPS

QRS

10

34602, 42245, 26062, 38628

0.292, 0.242, 0.390, 0.269

20

65380, 75027, 63108, 62195

0.309, 0.271, 0.321, 0.329

50

133498, 145874, 127170, 86124

0.379, 0.347, 0.398, 0.586

100

198000, 200500, 199750, 115637

0.535, 0.527, 0.532, 0.897

150

224123, 212524, 222461, 153878

0.710, 0.743, 0.709, 1.006

200

270601, 276565, 270500, 168952

0.784, 0.768, 0.782, 1.219

250

278647, 287017, 278250, 197342

0.944, 0.924, 0.948, 1.304

300

269562, 283278, 271995, 277041

1.160, 1.123, 1.149, 1.140

数据表t2:

线程数

QPS

QRS

10

3048, 33721, 3097, 30111

3.280, 0.301, 3.227, 0.336

20

11063, 66795, 11013, 55440

1.810, 0.305, 1.817, 0.365

50

27153, 123778, 26733, 110513

1.843, 0.409, 1.872, 0.457

100

60388, 181340, 72942, 174132

1.685, 0.582, 1.403, 0.602

150

83470, 233631, 110977, 226715

1.827, 0.675, 1.383, 0.698

200

112169, 234799, 146271, 224762

1.816, 0.888, 1.404, 0.926

250

169017, 229063, 183515, 224988

1.517, 1.132, 1.402, 1.152

300

213542, 219782, 149234, 216786

1.445, 1.405, 2.051, 1.425

数据表t3:

线程数

QPS

QRS

10

1525, 16151, 2684, 10321

6.544, 0.623, 3.722, 0.970

20

12672, 30203, 7691, 19471

1.581, 0.667, 2.600, 1.031

50

23476, 70133, 14906, 53962

2.134, 0.717, 3.351, 0.930

100

50900, 134443, 16844, 114204

1.993, 0.770, 5.948, 0.906

150

63731, 137467, 20654, 153763

2.389, 1.122, 7.262, 1.008

200

41965, 100772, 28681, 153861

4.799, 2.022, 6.994, 1.334

250

31493, 69308, 22689, 88058

7.951, 3.651, 11.010, 2.882

300

26825, 42008, 16551, 50553

11.169, 7.168, 18.027, 5.962

实验四

实验目的:测试MySQL和PG针对单行更新insert负载的性能。

测试负载:insert into table values (?, ?, ?),以预编译的形式执行,分别向数据表t1-t3最大主键后面乱序插入数据。

MySQL:

数据表t1:

线程数

TPS

TRS

10

9780, 9054

1.026, 1.108

20

10540, 15020

1.901, 1.338

50

13746, 19291

3.647, 2.622

100

19248, 19988

5.260, 5.040

150

15215, 18666

8.201, 8.053

200

16616, 16911

12.056, 11.873

250

16811, 16780

14.847, 14.873

300

16387, 17461

18.159, 17.168

数据表t2:

线程数

TPS

TRS

10

9027, 2933

1.112, 3.413

20

3187, 3627

6.262, 5.511

50

3626, 3662

13.674, 13.587

100

3665, 3689

27.047, 26.997

150

3451, 3600

42.603, 41.347

200

3400, 3402

57.620, 57.149

250

2657, 2587

90.501, 90.802

300

2700, 2769

103.547, 100.720

数据表t3:

线程数

TPS

TRS

10

1860, 780

5.431, 12.876

20

985, 1840

20.381, 10.948

50

650, 1747

73.945, 28.967

100

801, 1608

117.895, 60.001

150

795, 1688

166.787, 85.463

200

993, 1090

196.999, 167.334

250

1250, 1251

186.354, 182.215

300

1294, 1287

202.240, 204.294

PG:

数据表t1:

线程数

TPS

TRS

10

22322, 29616

0.453, 0.341

20

25984, 25011

0.780, 0.810

50

32649, 32544

1.555, 1.563

100

38058, 37790

2.671, 2.689

150

36300, 38201

4.188, 3.977

200

35039, 39091

5.813, 5.210

250

38826, 39566

6.564, 6.442

300

39369, 38639

7.716, 7.863

数据表t2:

线程数

TPS

TRS

10

1780, 17547

5.606, 0.581

20

4816, 27066

4.157, 0.754

50

10588, 10246

4.736, 4.907

100

6615, 34539

15.045, 2.943

150

17732, 36897

8.488, 4.114

200

9066, 13647

21.873, 14.652

250

37037, 35813

6.870, 7.092

300

13841, 37389

21.585, 8.106

数据表t3:

线程数

TPS

TRS

10

1467, 181

6.853, 53.855

20

2042, 655

9.902, 30.181

50

1424, 2185

34.748, 22.945

100

582, 4969

158.765, 20.586

150

1050, 4388

132.584, 34.757

200

2263, 3313

86.446, 59.566

250

2067, 2551

117.791, 97.917

300

2628, 1604

110.286, 178.498

实验五

实验目的:测试MySQL和PG针对单行更新delete负载的性能。

测试负载:delete from table where id = ?,以预编译的形式执行,乱序地将实验四插入的数据删掉。

MySQL:

数据表t1:

线程数

TPS

TRS

10

7540, 9054, 8738, 8928

1.328, 1.108, 1.146, 1.123

20

10165, 12498, 12300, 12308

1.980, 1.609, 1.636, 1.632

50

14906, 14700, 15040, 14842

3.380, 3.425, 3.346, 3.389

100

15173, 15399, 15596, 15698

6.630, 6.511, 6.447, 6.409

150

15215, 15085, 15460, 15408

9.910, 9.978, 9.752, 9.770

200

14698, 14913, 15197, 15080

13.639, 13.393, 13.128, 13.265

250

14631, 14323, 14640, 14425

16.991, 17.364, 16.962, 17.178

300

14086, 13971, 14215, 13908

21.209, 21.379, 21.056, 21.439

数据表t2:

线程数

TPS

TRS

10

4458, 2585, 2568, 2589

2.244, 3.867, 3.892, 3.862

20

2596, 2647, 2614, 2638

7.683, 7.536, 7.631, 7.555

50

2558, 2567, 2564, 2567

19.359, 19.284, 19.280, 19.270

100

2715, 2505, 2463, 2500

35.937, 38.775, 39.856, 39.202

150

2755, 2850, 2706, 2786

52.647, 51.473, 53.066, 52.566

200

2825, 2807, 2803, 2817

67.632, 68.065, 69.000, 67.763

250

3039, 3034, 3000, 3001

77.707, 77.661, 81.811, 81.581

300

3000, 2983, 3000, 2715

96.423, 98.871, 98.586, 102.035

数据表t3:

线程数

TPS

TRS

10

968, 650, 816, 790

10.387, 15.248, 12.170, 12.626

20

1029, 882, 843, 840

19.405, 22.486, 23.482, 23.384

50

811, 895, 850, 850

58.882, 54.255, 57.844, 58.650

100

1014, 848, 800, 800

94.327, 111.425, 116.341, 117.083

150

750, 750, 750, 750

184.678, 176.016, 174.454, 176.316

200

800, 801, 609, 604

221.390, 220.013, 253.197, 257.262

250

781, 1004, 750, 750

259.920, 238.098, 306.762, 308.28

300

718, 601, 600, 600

338.063, 361.751, 355.295, 360.073

PG:

数据表t1:

线程数

TPS

TRS

10

39087, 40948

0.261, 0.255

20

68326, 57180

0.298, 0.360

50

100000, 100000

0.541, 0.543

100

90900, 90900

1.140, 1.155

150

68804, 77522

2.209, 1.992

200

66696, 66720

3.090, 3.095

250

55942, 57034

4.554, 4.486

300

47085, 42041

6.447, 7.182

数据表t2:

线程数

TPS

TRS

10

21872, 33258

0.462, 0.306

20

22153, 22729

0.911, 0.887

50

18500, 28890

2.736, 1.750

100

71400, 80228

1.468, 1.298

150

34045, 71928

4.467, 2.124

200

62112, 55379

3.349, 3.713

250

54708, 52518

4.710, 4.876

300

20448, 47515

14.678, 6.400

数据表t3:

线程数

TPS

TRS

10

30870, 21837

0.330, 0.463

20

2023, 3494

9.827, 5.718

50

2236, 29400

22.151, 1.715

100

3611, 4488

27.144, 21.970

150

8280, 4588

18.077, 32.624

200

38756, 57644

5.244, 3.591

250

3251, 8080

72.193, 30.816

300

8418, 31918

35.248, 9.468

实验六

实验目的:测试MySQL和PG针对单行更新replace负载的性能。

测试负载:replace into table values (?, ?, ?),以预编译的形式执行,分别向数据表t1-t3最大主键后面乱序插入数据。

MySQL:

数据表t1:

线程数

TPS

TRS

10

10280, 8864

0.978, 1.131

20

14921, 16005

1.349, 1.261

50

19488, 19656

2.585, 2.573

100

19008, 18992

5.302, 5.290

150

19011, 18229

7.909, 8.231

200

17356, 16783

11.571, 11.957

250

16398, 16542

15.237, 15.076

300

15622, 15915

19.218, 18.806

数据表t2:

线程数

TPS

TRS

10

3220, 2988

3.106, 3.348

20

3659, 3672

5.462, 5.440

50

3655, 3703

13.636, 13.456

100

3603, 3604

27.575, 27.480

150

3600, 3603

41.314, 40.680

200

3403, 3404

57.186, 57.183

250

2778, 2750

84.653, 87.301

300

2731, 3006

101.099, 93.306

数据表t3:

线程数

TPS

TRS

10

704, 800

14.111, 12.366

20

1180, 1200

16.737, 16.486

50

1200, 1155

41.220, 41.840

100

1178, 1110

83.044, 83.921

150

1136, 1088

124.972, 125.448

200

1051, 1024

167.331, 167.549

250

1000, 1000

240.751, 245.993

300

900, 900

289.758, 289.524

实验七

实验目的:测试MySQL和PG针对单行更新update负载的性能。

测试负载:update table set value1 = ? where id = ?,以预编译的形式执行,id是在数据表的主键上均与分布。

MySQL:

数据表t1:

线程数

TPS

TRS

10

7010, 6340

1.437, 1.589

20

10282, 10338

1.961, 1.953

50

13023, 12885

3.859, 3.902

100

14147, 13932

7.089, 7.179

150

14418, 14469

10.417, 10.377

200

14533, 14559

13.743, 13.746

250

13924, 14507

17.928, 17.190

300

13618, 13349

22.125, 22.517

数据表t2:

线程数

TPS

TRS

10

2180, 2672

4.582, 3.743

20

3232, 3265

6.200, 6.123

50

2956, 3007

16.769, 16.530

100

3000, 3141

33.034, 31.234

150

3236, 3301

45.444, 45.179

200

3103, 3206

62.496, 60.233

250

3252, 3031

74.124, 77.840

300

3309, 3304

87.070, 88.002

数据表t3:

线程数

TPS

TRS

10

580, 540

17.015, 18.280

20

660, 675

30.091, 29.341

50

651, 651

73.050, 72.618

100

601, 604

144.215, 144.858

150

600, 600

220.370, 218.125

200

600, 600

292.573, 296.538

250

500, 500

359.083, 363.771

300

600, 600

424.396, 425.272

PG:

数据表t1:

线程数

TPS

TRS

10

5302, 33413

1.900, 0.315

20

50714, 58092

0.422, 0.381

50

65777, 75000

0.797, 0.716

100

74865, 71400

1.393, 1.446

150

66420, 64432

2.317, 2.404

200

56352, 56998

3.665, 3.618

250

47413, 50595

5.419, 5.121

300

46081, 45721

6.764, 6.788

数据表t2:

线程数

TPS

TRS

10

2319, 4794

4.317, 2.100

20

2518, 5564

7.936, 3.620

50

5650, 9324

8.854, 5.390

100

8900, 8866

11.264, 11.649

150

15590, 13911

9.673, 10.825

200

16142, 23621

12.447, 8.542

250

17974, 31060

13.968, 8.207

300

7262, 22420

40.746, 13.578

数据表t3:

线程数

TPS

TRS

10

298, 1407

33.305, 7.091

20

467, 2755

41.772, 7.320

50

798, 899

61.389, 54.870

100

2056, 5882

47.532, 16.890

150

2179, 1195

66.978, 118.706

200

2310, 2200

82.787, 89.539

250

3104, 4924

76.796, 50.000

300

3769, 8146

77.792, 36.697

测试结论:

1.      PG和MySQL在大数据表时,更新操作性能都会急剧下降;

2.      PG无论读写性能都比MySQL好一点;

3.      PG的delete和update操作应该作了特殊优化,但是性能不是很稳定。
---------------------
作者:小宇0000
来源:CSDN
原文:https://blog.csdn.net/liyuming0000/article/details/51240798
版权声明:本文为博主原创文章,转载请附上博文链接!

发表评论

邮箱地址不会被公开。 必填项已用*标注