Postgresql的瓶颈既不是CPU,也不是网络,也不是I/O



我们正在测试我们的应用程序的性能,它使用Postgresql13作为数据库。它的插入和更新量很大,我们无法在数据库中获得超过65k的TPS。但最常见的瓶颈都不适用(CPU/网络/磁盘IO(。

我们也和pgbench进行了多次组合,但这些组合不能超过65k。例如

pgbench -i -s 50 -U postgres -h <DB_HOST> -d <DB_NAME>
pgbench -c 64 -j 32 -t 100000 -h <DB_HOST> -U postgres <DB_NAME>
starting vacuum...end.
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 50
query mode: simple
number of clients: 64
number of threads: 32
number of transactions per client: 100000
number of transactions actually processed: 6400000/6400000
latency average = 0.976 ms
tps = 65584.664360 (including connections establishing)
tps = 65594.330678 (excluding connections establishing)

(使用更多的客户端导致更少的TPS(

数据库服务器具有以下规格:

  • 64核(Intel Xeon Gold 6130(Skylake,2.10GHz,2个CPU/节点,16核/CPU((
  • 192 GiB RAM(12*16GiB DIMM DDR4同步注册(缓冲(2666 MHz(0.4 ns((
  • 2*SSD SATA Samsung MZ7KM240HMHQ0D3(一个用于WAL,一个用于数据(
  • 10 Gbps网络链路
  • 操作系统:Debian 11

我们使用以下配置:

shared_buffers=65551953kB
effective_cache_size=147491895kB
huge_pages=on
min_wal_size=4GB
max_wal_size=16GB
wal_buffers=1GB
work_mem=2GB
maintenance_work_mem=4GB
checkpoint_completion_target=0.9
checkpoint_timeout = 15min
random_page_cost=1.1
bgwriter_flush_after = 2MB
effective_io_concurrency = 200
# Disabled just for performance experiments
fsync = off
synchronous_commit = off
full_page_writes = on
max_worker_processes=64
max_parallel_workers=64
max_parallel_workers_per_gather=10
max_parallel_maintenance_workers=12

当我们达到65k TPS时,我们在服务器上有以下资源使用情况:

我们的应用程序:

  • CPU:25%
  • I/O利用率:分别为30%。60%(瓦尔(
  • 网络:输入200Mbps输出125Mbps

pgbench:

  • CPU:75%
  • I/O利用率:分别为2%。5%(瓦尔(
  • 网络:输入/输出~500Mbps

我们还将WAL和数据临时放入RAM,以验证磁盘是否不是问题所在,但这也没有影响。

有人知道我们的瓶颈在哪里吗?

(我们已经考虑过分片,但希望尽可能多地使用单个服务器(

编辑:

运行pgbench时的vmstat 1 -S M

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
1  0      0  92009     25  18316    0    0     3   318  405   22 26 11 63  0  0
0  0      0  92009     25  18316    0    0     0     0  261  320  0  0 100  0  0
0  0      0  92009     25  18316    0    0     0 46616  216  257  0  0 100  0  0
45  0      0  92260     25  17996    0    0     0     0 509124 781029 35 13 52  0  0
44  1      0  92252     25  17998    0    0     0 82192 743920 1140285 51 20 30  0  0
50  0      0  92247     25  18003    0    0     0 65564 740366 1152212 52 18 30  0  0
41  0      0  92243     25  18005    0    0     0     0 736052 1138409 50 20 30  0  0
35  0      0  92240     25  18009    0    0     0     0 734265 1138483 50 20 30  0  0
36  0      0  92238     25  18012    0    0     0   264 741315 1152409 52 19 29  0  0
43  0      0  92236     25  18016    0    0     0    36 740374 1147759 51 20 29  0  0
46  0      0  92231     25  18020    0    0     0 163856 737491 1166498 53 19 28  0  0
47  0      0  92228     25  18023    0    0     0     0 741582 1171814 52 19 28  0  0
43  0      0  92223     25  18027    0    0     0 61584 741537 1168119 53 19 28  0  0
46  0      0  92220     25  18030    0    0     0    36 739695 1167456 53 19 28  0  0
43  0      0  92216     25  18034    0    0     0   228 741992 1150333 52 20 29  0  0
38  0      0  92214     25  18036    0    0     0 147464 740589 1166289 52 19 28  0  0
41  0      0  92209     25  18042    0    0     0     0 737148 1162946 52 19 28  0  0
44  0      0  92207     25  18044    0    0     0  2480 741757 1173128 53 19 28  0  0
39  0      0  92205     25  18049    0    0     0    48 740404 1170644 53 19 28  0  0
52  0      0  92201     25  18051    0    0     0   292 739032 1159037 52 19 28  0  0
42  1      0  92198     25  18054    0    0     0 20072 740101 1165594 52 20 28  0  0
51  0      0  92194     25  18059    0    0     0 45464 738055 1165382 53 19 28  0  0
41  0      0  92190     25  18062    0    0     0     0 742838 1172377 53 19 28  0  0
45  0      0  92185     25  18067    0    0     0    36 740704 1174534 53 19 28  0  0
50  0      0  92182     25  18069    0    0     0    92 741691 1150716 52 19 28  0  0
42  0      0  92177     25  18073    0    0     0    28 740220 1168488 53 18 28  0  0
44  0      0  92174     25  18077    0    0     0     0 738818 1164769 53 19 28  0  0
46  0      0  92172     25  18080    0    0     0     0 740720 1169902 53 19 28  0  0
46  0      0  92166     25  18083    0    0     0 90404 592524 945810 42 15 43  0  0
45  0      0  92161     25  18087    0    0     0  3884 746310 1159898 52 19 28  0  0
49  0      0  92157     25  18090    0    0     0    20 747242 1177750 53 19 28  0  0
36  0      0  92152     25  18094    0    0     0     0 744477 1173832 53 19 28  0  0
46  0      0  92149     25  18098    0    0     0     0 746194 1172700 53 19 28  0  0
39  0      0  92147     26  18101    0    0     0 49768 745651 1177462 54 18 28  0  0
43  0      0  92143     26  18105    0    0     0   212 744968 1161110 53 19 28  0  0
43  0      0  92138     26  18109    0    0     0     0 743223 1176960 54 19 28  0  0
43  0      0  92135     26  18112    0    0     0 81920 745168 1173574 53 19 28  0  0
48  0      0  92132     26  18116    0    0     0     0 743174 1169255 53 19 28  0  0
48  0      0  92129     26  18120    0    0     0    68 592295 933445 42 15 43  0  0
41  0      0  92124     26  18123    0    0     0    76 740354 1162221 52 19 28  0  0
49  0      0  92120     26  18125    0    0     0     0 738456 1158291 53 19 28  0  0
39  0      0  92117     26  18129    0    0     0 147536 740735 1162479 52 20 28  0  0
49  0      0  92113     26  18133    0    0     0     0 737209 1165532 53 20 28  0  0
49  0      0  92111     26  18137    0    0     0    40 741185 1168133 54 19 28  0  0
45  0      0  92110     26  18140    0    0     0  4000 740693 1141945 52 20 28  0  0
42  0      0  92105     26  18144    0    0     0     0 741857 1168830 53 19 28  0  0
43  0      0  92102     26  18147    0    0     0     8 742546 1168867 54 18 28  0  0
43  0      0  92101     26  18150    0    0     0 147456 741941 1166646 53 19 28  0  0
41  1      0  92097     26  18154    0    0     0 64192 740052 1169040 53 19 28  0  0
48  0      0  92094     26  18158    0    0     0 27484 737224 1139511 52 20 28  0  0
47  0      0  92087     26  18162    0    0     0     0 740821 1165037 53 19 28  0  0
54  0      0  92059     26  18164    0    0     0     4 737109 1155098 53 19 27  0  0
38  0      0  92051     26  18170    0    0     0 147456 701847 1075069 55 20 25  0  0
35  0      0  92064     26  18174    0    0     0    44 723153 1125736 54 19 27  0  0
48  0      0  92056     26  18179    0    0     0 53008 734590 1134838 52 19 29  0  0
46  0      0  92053     26  18183    0    0     0     0 741595 1166891 53 19 28  0  0
46  0      0  92049     26  18186    0    0     0     0 740196 1170838 54 19 27  0  0
31  1      0  92045     26  18191    0    0     0 98304 741800 1170076 54 18 28  0  0
44  0      0  92043     26  18194    0    0     0 49188 733352 1173652 53 20 27  0  0
43  0      0  92028     26  18198    0    0     0   116 733522 1151497 53 20 27  0  0
44  0      0  92037     26  18201    0    0     0     0 730364 1137665 53 19 27  0  0
37  0      0  92035     26  18204    0    0     0     0 742348 1164945 53 19 28  0  0
44  0      0  92031     26  18208    0    0     0     0 739273 1165044 53 19 28  0  0
52  0      0  92028     26  18211    0    0     0 147888 739274 1164496 53 19 28  0  0
50  0      0  92024     26  18215    0    0     0   144 739684 1145210 53 19 28  0  0
50  0      0  92020     26  18219    0    0     0     0 742847 1167779 54 18 28  0  0
38  0      0  92016     26  18223    0    0     0     0 738079 1166580 53 19 28  0  0
36  0      0  92013     26  18226    0    0     0     0 742687 1171101 54 18 27  0  0
48  0      0  92009     26  18229    0    0     0 147500 741536 1166846 53 19 28  0  0
40  0      0  92006     26  18233    0    0     0 94600 740746 1147102 52 20 28  0  0
45  0      0  92001     26  18238    0    0     0     0 741119 1163851 53 19 28  0  0
48  0      0  91999     26  18241    0    0     0     0 740995 1167197 53 19 28  0  0
35  0      0  91996     26  18244    0    0     0     0 742235 1165666 53 19 28  0  0
44  1      0  91993     26  18248    0    0     0 49192 741392 1164506 53 19 28  0  0
43  1      0  91990     26  18251    0    0     0 124876 743695 1144639 52 19 29  0  0
48  0      0  91987     26  18255    0    0     0 24864 737759 1159383 52 20 28  0  0
44  0      0  91983     26  18258    0    0     0     0 740224 1164983 53 19 28  0  0
43  0      0  91980     26  18262    0    0     0     0 741742 1168140 54 19 27  0  0
18  0      0  91976     26  18267    0    0     0    36 737449 1162293 53 19 28  0  0
49  0      0  91973     26  18269    0    0     0 147576 741462 1148048 52 20 28  0  0
43  0      0  91969     26  18274    0    0     0     0 742408 1168332 54 19 27  0  0
43  0      0  91966     26  18277    0    0     0     0 738803 1164992 53 19 28  0  0
39  0      0  91963     26  18280    0    0     0     4 737891 1159372 52 19 28  0  0
43  0      0  91962     26  18283    0    0     0    40 741888 1166835 53 19 28  0  0
48  0      0  91958     26  18287    0    0     0 164144 738677 1145900 52 20 28  0  0
46  0      0  91955     26  18291    0    0     0     0 740956 1165789 53 19 28  0  0
44  0      0  91952     26  18295    0    0     0     0 741055 1166460 53 19 28  0  0
44  0      0  91948     26  18299    0    0     0     8 739414 1165698 53 19 28  0  0
46  0      0  91945     26  18301    0    0     0    48 743218 1165277 53 19 28  0  0
36  0      0  91941     26  18305    0    0     0   208 736320 1134425 51 20 29  0  0
47  0      0  91936     26  18309    0    0     0 239096 739799 1159730 52 19 28  0  0
45  0      0  91932     26  18312    0    0     0     0 742477 1167618 53 20 28  0  0
45  0      0  91928     26  18316    0    0     0     0 736442 1159690 52 20 28  0  0
47  0      0  91926     26  18319    0    0     0    76 737145 1157620 52 20 28  0  0
48  0      0  91921     26  18323    0    0     0    64 739999 1146323 52 19 29  0  0
50  0      0  91918     26  18326    0    0     0 197176 739590 1159797 52 19 28  0  0
50  0      0  91915     26  18330    0    0     0     0 740533 1166111 53 19 28  0  0
52  0      0  91911     26  18334    0    0     0     0 739776 1161328 52 20 28  0  0
42  0      0  91907     26  18338    0    0     0    60 590783 929545 41 16 43  0  0
39  0      0  91904     26  18341    0    0     0  4248 744434 1161062 52 19 29  0  0
41  1      0  91900     26  18345    0    0     0 114688 741817 1163511 53 19 28  0  0
14  0      0  91928     26  18349    0    0     0 32768 598242 996868 43 15 42  0  0
0  0      0  91951     26  18349    0    0     0     0 41914 84357  3  1 96  0  0
0  0      0  91952     26  18349    0    0     0    36  174  204  0  0 100  0  0
0  0      0  91954     26  18349    0    0     0   276 7897 13403  0  0 99  0  0
0  0      0  91954     26  18349    0    0     0     0 1911 3678  0  0 100  0  0
0  0      0  91954     26  18349    0    0     0 147456  330  351  0  0 100  0  0

编辑:

当在与数据库相同的系统上运行时,与上面相同的pgbench基准测试给出了大约68k,并且只选择540k(来自远程系统的507k(。

CPU:75%是用户还是用户+系统?无论如何,75%的操作系统CPU具有超线程意味着所有内核都100%繁忙。

您使用简单的tpc-b协议,它强调网络和上下文切换。看见https://franckpachot.medium.com/do-you-know-what-you-are-measuring-with-pgbench-d8692a33e3d6

相关内容

  • 没有找到相关文章

最新更新