为什么使用sync.pool解决OOM问题后,性能却下降了?

本文分享研发小伙伴(在2021年7月)分析测试同事在测试海东青1.3.7版本时所遇到的一个性能问题的思路,希望能够帮助大家增加对Golang GC机制及其影响的了解。(本文使用的Golang版本:1.16.7,虽然Golang版本较老,但是也可以为大家排查问题提供一个思路)

如您想了解海东青或下载使用,可以阅读:关于FalconTSDB海东青时序数据库

背景

在测试同学某次测试数据库性能时发现:连续进行多次写入测试会导致数据库OOM(因为测试写入会发送大量的数据写入请求)。

研发同学通过pprof分析发现,有大量的内存消耗发生在读取HTTP body里,因此研发同学使用sync.pool内存重用解决了OOM问题,最终合并到1.3分支。(具体优化方法可以参考这篇文章,原理相似:文章链接

但当准备发布最新版1.3时,测试同学在对它进行性能测试时发现,它相较于v1.3.6 tag版本出现了写入性能下降

问题排查

通过查看数据库1.3最近的变更,发现两个可疑改动;于是基于1.3分支代码临时修改进行验证,证实了问题是在使用sync.pool优化内存使用解决OOM问题所导致的。

因此我们在1.3的分支下checkout新分支并去掉sync.pool作为一个版本(下文称之为 none-pool),用它与1.3进行对比分析以排查问题。

对比分析

先说明下测试环境:

1. 测试数据库服务器硬件参数:16核,64G内存,SSD

2. 测试机器硬件参数:8核、16G内存,SSD

测试方法:

在测试机器上使用bulk_load_influx(64并发、5000batch,跨机器)分别对none-pool和1.3进行性能测试。

测试过程中的监控信息如下(每一张图的左边为none-pool,右边为1.3):

图片

图片

图片

图片

性能测试结果:

1. none-pool版本性能结果为:mean point rate 331760.917623/sec (55 QPS)

2. 1.3版本性能结果为:mean point rate 270958.899289/sec   (54 QPS)

可以看出,两个版本的CPU利用率几乎完全一样,但none-pool性能更好,使用内存更高。(虽然IO也更高,但这是由于吞吐更大所造成的,属于正常现象)。

这是为什么呢?是否两个版本在执行写入时导致了系统其他件运行情况不一样呢?比如数据文件的Compact次数不一样?但通过数据库日志我们发现,两个版本导致的compact次数是一致的,而且也没有发现其他可疑的表现。

故差异仅仅在内存使用量上。

所以当前就有一个疑问:为什么使用内存更高却性能更好呢?(注意:在我们写入流程中并没有所谓空间换时间的机制,所以不存在使用更多的内存来提高写入速度的机制)

Profile分析

于是我们再次测试(只持续写入30s),并使用pprof profile 分析。

分析结果:

none-pool版本的火焰图如下:

图片

性能测试结果:

loaded 8631360 items in 26.796450sec with 64 workers (mean point rate 322108.339374/sec, mean value rate 3614771.364091/s, 137.09MB/sec from stdin)

1.3版本的火焰图如下:

图片

性能测试结果:

loaded 8631360 items in 30.785515sec with 64 workers (mean point rate 280370.813925/sec, mean value rate 3146383.578497/s, 119.33MB/sec from stdin)

可以看出,none-pool 版本在gc mark模块占用的CPU消耗少很多。GC CPU降低的比例恰好和写入吞吐高出的比例吻合。

所以产生了一个新的疑问:为什么内存使用更高,但是gc mark使用的CPU占比反而更少呢?(因为通常我们会认为内存越大,gc开销越高)

GC trace

经同事提醒,GC的触发跟内存大小有关系,于是通过查询资料,找到GOGC环境变量:https://pkg.go.dev/runtime 。那么是否因为在内存分配更多的情况下,导致GC触发条件更难满足,所以GC次数变少,所以gc mark占用的CPU更少呢?

于是我们这次打开 GODEBUG=gctrace=1 环境变量重新测试,进行跟踪数据库进程的gc 日志,启动海东青命令如下:

GODEBUG=gctrace=1 ./fctsdb -config test.conf

gc日志内容格式说明可以参考:https://pkg.go.dev/runtime#pkg-overview,这里截取小部分说明:

gctrace: setting gctrace=1 causes the garbage collector to emit a single line to standard
error at each collection, summarizing the amount of memory collected and the
length of the pause. The format of this line is subject to change.
Currently, it is:
        gc # @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, # P
where the fields are as follows:
        gc #        the GC number, incremented at each GC
        @#s         time in seconds since program start
        #%          percentage of time spent in GC since program start
        #+...+#     wall-clock/CPU times for the phases of the GC
        #->#-># MB  heap size at GC start, at GC end, and live heap
        # MB goal   goal heap size
        # P         number of processors used

none-pool版本运行时gc日志如下:

gc 1 @2.900s 0%: 0.026+0.65+0.015 ms clock, 0.41+0.24/1.1/0.50+0.25 ms cpu, 4->4->1 MB, 5 MB goal, 16 P
gc 2 @7.815s 0%: 0.042+0.78+0.037 ms clock, 0.67+0/0.96/1.2+0.60 ms cpu, 4->4->2 MB, 5 MB goal, 16 P
gc 3 @7.826s 0%: 0.049+3.5+0.012 ms clock, 0.78+0/4.1/0.55+0.19 ms cpu, 9->11->9 MB, 10 MB goal, 16 P
gc 4 @7.842s 0%: 0.14+2.7+0.020 ms clock, 2.2+0.23/5.8/5.2+0.33 ms cpu, 20->20->14 MB, 21 MB goal, 16 P
gc 5 @7.857s 0%: 0.082+1.2+0.032 ms clock, 1.3+0.40/3.6/1.8+0.51 ms cpu, 28->29->20 MB, 29 MB goal, 16 P
gc 6 @7.868s 0%: 1.6+4.5+0.11 ms clock, 26+0.47/9.1/3.6+1.8 ms cpu, 40->44->36 MB, 41 MB goal, 16 P
gc 7 @7.890s 0%: 0.12+5.8+0.050 ms clock, 2.0+3.4/17/2.1+0.80 ms cpu, 69->78->64 MB, 73 MB goal, 16 P
gc 8 @7.920s 0%: 0.38+9.4+0.12 ms clock, 6.2+5.6/35/0+2.0 ms cpu, 117->130->100 MB, 128 MB goal, 16 P
gc 9 @7.963s 0%: 0.18+23+0.22 ms clock, 2.9+13/82/0+3.6 ms cpu, 183->218->182 MB, 201 MB goal, 16 P
gc 10 @8.038s 0%: 0.38+54+0.024 ms clock, 6.1+37/198/0+0.39 ms cpu, 316->390->327 MB, 364 MB goal, 16 P
gc 11 @8.185s 0%: 0.43+96+0.13 ms clock, 6.9+84/373/97+2.2 ms cpu, 548->705->596 MB, 655 MB goal, 16 P
gc 12 @8.392s 0%: 0.26+90+0.13 ms clock, 4.2+21/357/0+2.1 ms cpu, 954->1105->587 MB, 1192 MB goal, 16 P
gc 13 @8.591s 1%: 0.51+112+0.13 ms clock, 8.2+33/440/0+2.1 ms cpu, 991->1214->770 MB, 1174 MB goal, 16 P
gc 14 @8.825s 1%: 0.28+145+0.007 ms clock, 4.5+105/571/1.9+0.12 ms cpu, 1290->1598->1031 MB, 1541 MB goal, 16 P
gc 15 @9.208s 2%: 0.32+278+0.15 ms clock, 5.2+98/1106/0+2.4 ms cpu, 1692->2160->1419 MB, 2063 MB goal, 16 P
gc 16 @9.724s 2%: 1.4+249+0.16 ms clock, 22+9.8/907/0+2.6 ms cpu, 2291->2694->1435 MB, 2838 MB goal, 16 P
gc 17 @10.276s 3%: 3.0+254+0.035 ms clock, 48+414/995/0+0.56 ms cpu, 2422->2920->1675 MB, 2871 MB goal, 16 P
gc 18 @10.790s 4%: 0.32+224+0.13 ms clock, 5.2+113/895/0+2.2 ms cpu, 2750->3196->1717 MB, 3351 MB goal, 16 P
gc 19 @11.402s 4%: 0.30+295+0.13 ms clock, 4.9+475/1180/0+2.1 ms cpu, 2911->3512->2162 MB, 3434 MB goal, 16 P
gc 20 @12.129s 5%: 0.28+323+0.78 ms clock, 4.5+210/1291/31+12 ms cpu, 3554->4278->2418 MB, 4324 MB goal, 16 P
gc 21 @12.847s 5%: 1.9+302+0.28 ms clock, 30+83/1180/0+4.5 ms cpu, 4013->4542->2407 MB, 4836 MB goal, 16 P
gc 22 @13.645s 5%: 0.34+255+0.18 ms clock, 5.4+70/1011/0+2.9 ms cpu, 4176->4754->2670 MB, 4815 MB goal, 16 P
gc 23 @14.481s 5%: 2.4+265+0.24 ms clock, 38+130/1044/0+3.9 ms cpu, 4695->5201->2815 MB, 5341 MB goal, 16 P
gc 24 @15.400s 6%: 0.33+223+0.12 ms clock, 5.3+217/887/0+2.0 ms cpu, 5042->5542->3027 MB, 5630 MB goal, 16 P
gc 25 @16.306s 6%: 0.23+216+0.10 ms clock, 3.6+171/859/0+1.6 ms cpu, 5462->5888->3179 MB, 6055 MB goal, 16 P
gc 26 @17.224s 6%: 0.23+282+0.090 ms clock, 3.7+815/1128/0+1.4 ms cpu, 5821->6370->3714 MB, 6358 MB goal, 16 P
gc 27 @18.243s 6%: 0.25+494+0.16 ms clock, 4.0+458/1912/14+2.6 ms cpu, 6655->7386->4227 MB, 7429 MB goal, 16 P
gc 28 @19.558s 6%: 0.29+274+0.25 ms clock, 4.7+211/1095/0+4.0 ms cpu, 7589->8159->4248 MB, 8454 MB goal, 16 P
gc 29 @20.615s 6%: 0.41+236+0.18 ms clock, 6.7+527/941/0+2.9 ms cpu, 7776->8376->4537 MB, 8497 MB goal, 16 P
gc 30 @21.724s 7%: 0.42+289+0.24 ms clock, 6.8+316/1152/0+3.9 ms cpu, 8275->8848->4850 MB, 9075 MB goal, 16 P
gc 31 @23.195s 7%: 3.2+297+0.32 ms clock, 51+1037/1186/1.4+5.2 ms cpu, 8948->9501->5306 MB, 9701 MB goal, 16 P
gc 32 @24.924s 7%: 0.37+358+0.33 ms clock, 6.0+690/1337/0.17+5.3 ms cpu, 9733->10233->5482 MB, 10613 MB goal, 16 P
gc 33 @26.598s 7%: 3.7+278+0.19 ms clock, 60+322/1112/0+3.1 ms cpu, 10190->10630->5358 MB, 10964 MB goal, 16 P
gc 34 @28.189s 7%: 0.31+288+0.005 ms clock, 5.1+1045/1152/32+0.082 ms cpu, 10111->10534->5514 MB, 10717 MB goal, 16 P
gc 35 @29.706s 7%: 0.35+254+0.28 ms clock, 5.6+703/1003/0+4.4 ms cpu, 10369->10779->5377 MB, 11028 MB goal, 16 P
gc 36 @31.565s 7%: 0.29+207+0.14 ms clock, 4.7+722/826/0+2.2 ms cpu, 10152->10440->5182 MB, 10755 MB goal, 16 P
gc 37 @33.241s 7%: 0.21+279+0.12 ms clock, 3.4+1361/1113/1.5+1.9 ms cpu, 9855->10188->5391 MB, 10364 MB goal, 16 P
gc 38 @35.119s 6%: 0.13+51+0.016 ms clock, 2.1+2.6/203/558+0.25 ms cpu, 10198->10271->4616 MB, 10783 MB goal, 16 P

gc日志表明,并发标记的总时间消耗:7019.53 ms,进程STW总和:408.26 ms。

1.3版本运行时gc日志如下:

gc 1 @14.028s 0%: 0.027+0.47+0.010 ms clock, 0.44+0.053/1.1/0.34+0.17 ms cpu, 4->4->1 MB, 5 MB goal, 16 P
gc 2 @14.034s 0%: 0.058+0.45+0.002 ms clock, 0.93+0/1.1/0.49+0.039 ms cpu, 4->4->2 MB, 5 MB goal, 16 P
gc 3 @14.036s 0%: 0.063+0.51+0.025 ms clock, 1.0+0/1.0/0.20+0.41 ms cpu, 5->5->4 MB, 6 MB goal, 16 P
gc 4 @14.042s 0%: 0.088+2.2+0.20 ms clock, 1.4+0.11/2.7/0.18+3.2 ms cpu, 11->11->9 MB, 12 MB goal, 16 P
gc 5 @14.051s 0%: 0.060+0.76+0.035 ms clock, 0.96+0.33/1.9/0.42+0.56 ms cpu, 19->19->12 MB, 20 MB goal, 16 P
gc 6 @14.061s 0%: 0.077+1.1+0.037 ms clock, 1.2+0.52/3.8/0.84+0.59 ms cpu, 25->26->20 MB, 26 MB goal, 16 P
gc 7 @14.075s 0%: 0.096+2.9+0.020 ms clock, 1.5+1.4/5.9/3.8+0.32 ms cpu, 40->46->38 MB, 41 MB goal, 16 P
gc 8 @14.095s 0%: 0.10+6.5+1.5 ms clock, 1.6+0.76/14/7.9+24 ms cpu, 70->85->69 MB, 76 MB goal, 16 P
gc 9 @14.128s 0%: 0.36+9.7+0.10 ms clock, 5.8+1.4/30/10+1.7 ms cpu, 123->140->110 MB, 138 MB goal, 16 P
gc 10 @14.169s 0%: 0.37+25+0.040 ms clock, 6.0+10/92/0+0.64 ms cpu, 194->241->202 MB, 220 MB goal, 16 P
gc 11 @14.241s 0%: 0.19+54+0.23 ms clock, 3.1+7.4/214/0+3.7 ms cpu, 343->430->358 MB, 405 MB goal, 16 P
gc 12 @14.369s 0%: 0.17+73+0.21 ms clock, 2.8+3.6/292/248+3.5 ms cpu, 592->735->593 MB, 717 MB goal, 16 P
gc 13 @14.545s 0%: 0.26+87+0.11 ms clock, 4.2+24/347/0+1.8 ms cpu, 984->1163->554 MB, 1186 MB goal, 16 P
gc 14 @14.775s 0%: 0.20+90+0.17 ms clock, 3.3+135/357/0+2.8 ms cpu, 940->1142->715 MB, 1108 MB goal, 16 P
gc 15 @14.974s 0%: 0.21+120+0.13 ms clock, 3.4+26/467/8.0+2.1 ms cpu, 1170->1397->779 MB, 1430 MB goal, 16 P
gc 16 @15.288s 1%: 0.26+217+0.16 ms clock, 4.2+103/848/0+2.6 ms cpu, 1313->1574->911 MB, 1559 MB goal, 16 P
gc 17 @15.734s 1%: 0.28+220+0.081 ms clock, 4.5+458/880/46+1.3 ms cpu, 1532->1931->1325 MB, 1823 MB goal, 16 P
gc 18 @16.202s 2%: 0.22+263+0.15 ms clock, 3.6+38/1045/0+2.4 ms cpu, 2121->2422->1147 MB, 2651 MB goal, 16 P
gc 19 @16.690s 2%: 0.21+252+0.15 ms clock, 3.4+344/1010/0+2.5 ms cpu, 1953->2346->1277 MB, 2294 MB goal, 16 P
gc 20 @17.157s 2%: 0.80+315+0.17 ms clock, 12+137/1258/0+2.7 ms cpu, 2119->2427->1199 MB, 2554 MB goal, 16 P
gc 21 @17.759s 3%: 0.27+241+0.10 ms clock, 4.3+692/965/0+1.6 ms cpu, 2063->2459->1361 MB, 2399 MB goal, 16 P
gc 22 @18.274s 3%: 0.29+325+0.17 ms clock, 4.7+140/1289/40+2.7 ms cpu, 2207->2621->1363 MB, 2722 MB goal, 16 P
gc 23 @18.923s 4%: 0.26+227+0.17 ms clock, 4.2+99/884/0+2.7 ms cpu, 2278->2700->1304 MB, 2727 MB goal, 16 P
gc 24 @19.450s 4%: 0.22+275+0.073 ms clock, 3.6+446/1102/0+1.1 ms cpu, 2207->2677->1432 MB, 2609 MB goal, 16 P
gc 25 @19.970s 4%: 0.25+293+0.18 ms clock, 4.0+81/1074/0+2.9 ms cpu, 2342->2869->1451 MB, 2864 MB goal, 16 P
gc 26 @20.627s 5%: 0.28+320+0.021 ms clock, 4.5+564/1277/0+0.34 ms cpu, 2400->2971->1632 MB, 2902 MB goal, 16 P
gc 27 @21.312s 5%: 0.27+390+0.12 ms clock, 4.4+55/1533/0+1.9 ms cpu, 2612->3226->1628 MB, 3264 MB goal, 16 P
gc 28 @22.037s 5%: 0.42+294+0.13 ms clock, 6.8+228/1173/0+2.2 ms cpu, 2667->3109->1435 MB, 3257 MB goal, 16 P
gc 29 @22.695s 5%: 0.28+217+0.13 ms clock, 4.5+224/869/0+2.1 ms cpu, 2417->2875->1372 MB, 2871 MB goal, 16 P
gc 30 @23.222s 6%: 0.34+334+0.13 ms clock, 5.4+213/1335/13+2.1 ms cpu, 2298->2750->1494 MB, 2744 MB goal, 16 P
gc 31 @23.824s 6%: 0.26+233+0.14 ms clock, 4.3+257/934/0+2.3 ms cpu, 2507->3039->1473 MB, 2988 MB goal, 16 P
gc 32 @24.357s 6%: 0.20+301+0.28 ms clock, 3.2+544/1203/76+4.4 ms cpu, 2431->3040->1665 MB, 2947 MB goal, 16 P
gc 33 @24.909s 6%: 0.28+298+0.19 ms clock, 4.6+67/1189/12+3.1 ms cpu, 2664->3339->1700 MB, 3330 MB goal, 16 P
gc 34 @25.538s 6%: 0.23+263+0.12 ms clock, 3.8+11/1030/0+2.0 ms cpu, 2757->3273->1416 MB, 3400 MB goal, 16 P
gc 35 @26.115s 6%: 0.27+305+0.16 ms clock, 4.4+151/1158/0+2.6 ms cpu, 2384->2850->1433 MB, 2833 MB goal, 16 P
gc 36 @26.649s 7%: 0.16+288+0.051 ms clock, 2.6+436/1149/0.41+0.81 ms cpu, 2418->2977->1570 MB, 2866 MB goal, 16 P
gc 37 @27.190s 7%: 0.27+411+0.14 ms clock, 4.4+151/1545/0+2.3 ms cpu, 2544->3152->1644 MB, 3141 MB goal, 16 P
gc 38 @27.899s 7%: 0.29+333+0.14 ms clock, 4.6+651/1328/0+2.3 ms cpu, 2686->3387->1766 MB, 3288 MB goal, 16 P
gc 39 @28.566s 7%: 0.25+291+0.019 ms clock, 4.0+4.1/1143/0+0.31 ms cpu, 2827->3425->1520 MB, 3533 MB goal, 16 P
gc 40 @29.145s 7%: 0.29+410+0.16 ms clock, 4.6+181/1615/0+2.5 ms cpu, 2521->3045->1576 MB, 3040 MB goal, 16 P
gc 41 @29.944s 8%: 0.27+253+0.18 ms clock, 4.3+278/1012/0+2.9 ms cpu, 2634->3160->1562 MB, 3152 MB goal, 16 P
gc 42 @30.588s 8%: 0.27+321+0.070 ms clock, 4.4+381/1283/0+1.1 ms cpu, 2587->3158->1599 MB, 3124 MB goal, 16 P
gc 43 @31.238s 8%: 0.27+361+0.17 ms clock, 4.4+158/1443/35+2.8 ms cpu, 2608->3163->1609 MB, 3198 MB goal, 16 P
gc 44 @31.898s 8%: 0.28+282+0.046 ms clock, 4.6+105/1100/0+0.73 ms cpu, 2663->3262->1559 MB, 3218 MB goal, 16 P
gc 45 @32.523s 8%: 0.32+233+0.071 ms clock, 5.1+306/930/0+1.1 ms cpu, 2584->3192->1584 MB, 3118 MB goal, 16 P
gc 46 @32.994s 8%: 0.22+383+0.10 ms clock, 3.5+48/1249/0+1.7 ms cpu, 2556->3181->1616 MB, 3169 MB goal, 16 P
gc 47 @33.707s 8%: 0.21+278+0.12 ms clock, 3.4+144/1112/0.58+2.0 ms cpu, 2647->3276->1571 MB, 3233 MB goal, 16 P
gc 48 @34.296s 8%: 0.26+308+0.095 ms clock, 4.2+424/1233/38+1.5 ms cpu, 2569->3225->1738 MB, 3142 MB goal, 16 P
gc 49 @34.918s 8%: 0.31+308+0.15 ms clock, 5.0+144/1202/0+2.4 ms cpu, 2781->3511->1778 MB, 3476 MB goal, 16 P
gc 50 @35.564s 8%: 0.34+300+0.14 ms clock, 5.4+33/1195/0+2.3 ms cpu, 2854->3526->1636 MB, 3557 MB goal, 16 P
gc 51 @36.145s 9%: 0.28+388+0.18 ms clock, 4.5+229/1483/0+2.9 ms cpu, 2684->3231->1571 MB, 3272 MB goal, 16 P
gc 52 @36.905s 9%: 0.31+260+0.18 ms clock, 5.0+61/1040/0+2.9 ms cpu, 2609->3085->1454 MB, 3142 MB goal, 16 P
gc 53 @37.555s 9%: 0.26+293+0.022 ms clock, 4.2+646/1172/23+0.36 ms cpu, 2467->2988->1594 MB, 2908 MB goal, 16 P
gc 54 @38.141s 9%: 0.33+423+0.17 ms clock, 5.3+16/1693/0+2.8 ms cpu, 2577->2951->1461 MB, 3188 MB goal, 16 P
gc 55 @38.922s 9%: 0.24+246+0.080 ms clock, 3.9+268/982/0+1.2 ms cpu, 2497->2944->1406 MB, 2922 MB goal, 16 P
gc 56 @39.456s 9%: 0.27+313+0.13 ms clock, 4.4+501/1251/0+2.1 ms cpu, 2381->2920->1620 MB, 2813 MB goal, 16 P
gc 57 @40.017s 9%: 0.31+297+0.11 ms clock, 4.9+253/1189/0+1.7 ms cpu, 2630->3241->1696 MB, 3241 MB goal, 16 P
gc 58 @40.652s 9%: 0.37+263+0.056 ms clock, 5.9+148/1051/0+0.91 ms cpu, 2751->3401->1624 MB, 3393 MB goal, 16 P
gc 59 @41.259s 9%: 0.31+332+0.12 ms clock, 4.9+301/1325/0+2.0 ms cpu, 2644->3320->1782 MB, 3249 MB goal, 16 P
gc 60 @41.854s 9%: 0.26+326+0.044 ms clock, 4.3+11/1257/10+0.71 ms cpu, 2854->3589->1709 MB, 3565 MB goal, 16 P
gc 61 @42.466s 9%: 0.26+367+0.078 ms clock, 4.1+346/1469/0+1.2 ms cpu, 2782->3535->1857 MB, 3419 MB goal, 16 P
gc 62 @43.205s 10%: 0.36+396+0.12 ms clock, 5.8+179/1583/0+2.0 ms cpu, 2971->3635->1727 MB, 3714 MB goal, 16 P
gc 63 @43.902s 10%: 0.35+300+0.14 ms clock, 5.6+46/1197/0+2.2 ms cpu, 2822->3467->1636 MB, 3454 MB goal, 16 P
gc 64 @44.544s 10%: 0.15+207+0.025 ms clock, 2.4+292/829/492+0.41 ms cpu, 2709->3115->1385 MB, 3273 MB goal, 16 P

gc日志表明,并发标记的总时间消耗:15227.59 ms, 进程STW总和:261.73 ms。

从以上两份日志可以看出,1.3版本gc频率更高,因此在 gc mark上的CPU消耗更多。(虽然STW更少,因为如gc日志里所体现的,none-pool一次gc释放的内存更多)

GC机制说明:Golang 执行GC有一个前置条件 -- 需要当前内存达到一个阈值,而这个阈值是上一次执行gc时内存大小的两倍。

对比两份gc日志,可以看出 none-pool 版本的gc goal(阈值)更高,因为它不使用sync.pool内存重用导致内存占用更高,从而gc goal 值相比1.3版本的更高。在海东青的写入测试中,其内存消耗主要发生在read HTTP body,所以none-pool 版本在QPS比较低(比如55 req/s)的情况下,更不容易达到gc阈值。

所以none-pool版本gc次数更少,gc mark的CPU开销占用更低。

总结

至此,我们得出Golang的GC机制引发gc次数不同,导致CPU花在gc处理的时间不同,从而可能导致性能出现差异。

那么内存占用低反而有坏处么?

当然不是,事情不能如此简单的看待,虽然降低了内存之后出现了纯写场景下的性能下降,但当整个系统同时存在查询请求时,那么系统就可以让查询获得更多的内存,最终从读写整体上看,或许性能又是上升的。

参考资料

1. Golang gc goal阈值可参考:

https://golang.design/under-the-hood/zh-cn/part2runtime/ch08gc/pacing/

2. golang gc源码可参考:

https://github.com/golang/go/blob/7ec7a3cf33930e346e5f53fd41d2601b7c520056/src/runtime/mgcpacer.go#L650

最后

感谢大家的阅读,如果你有关于本文技术点的任何想法或意见,或者你有任何关于时序数据库的疑问或意见,欢迎加入微信群沟通探讨。

您也可以添加海东青客服微信加群:

图片

关注海东青数据库公众号:

海东青数据库官网:https://fctsdb.rockontrol.com/

佳华科技官网:https://www.rockontrol.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值