в заключении
Когда GO работает, даже если сборка мусора завершена, память кучи уменьшается, и память, примененная к системе, не будет освобождена через определенный период времени.
This process of returning memory to the system is called scavenging.
Если вы хотите освободить немедленно, вы можете попробовать позвонитьruntime/debug
внутреннийFreeOSMemory()
(Впрочем, я лично не думаю, что это необходимо
В этой статье не рассказывается, как настроить использование GC и pprof, но环境变量GODEBUG
Кроме того, это хороший инструмент отладки.Правильно печатать состояние памяти в журналеилиИспользуйте пакет expvar для просмотра работоспособности сервера
бредовое начало
окрестности
- go 1.9.2
- os osx/ubuntu
В последнее время сервер, написанный на go, может иметь проблему с высоким использованием памяти, поэтому я воспользовался возможностью, чтобы изучить механизм gc go на выходных.
сервер реализованВременно хранить сгенерированные аудиофайлы и удалять их по истечении срока действия.Для такой функции, поскольку наблюдается, что использование памяти сервера слишком высока, предполагается, что объект не используется GC (но это просто недоразумение
Поскольку тестовая программа реализует только простую логику, использование pprof не дает желаемых результатов наблюдений.После того, как в go 1.10 будет построен пламенный граф, я напишу туториал по pprof.
htop
При наблюдении за памятью, занимаемой системой, лично я предпочитаю htop, который, кстати, немного мощнее, чем top.Используйте учебник
в состоянии пройтиhtop -pid xxx
, или в хтопfilter
Имя процесса, указывающее процесс для наблюдения
Так как память подлежит проверке, больше беспокоят следующие 2 значения
- VILT: виртуальная память, занятая значением процесса
- Res: физическая стоимость памяти, занятая процессом
Способ, которым Go управляет памятью, заключается в резервировании большого куска VIRT в начале, а RES близок к фактическому использованию памяти.
Переменная среды GODEBUG
Наконец, установив переменную окруженияGODEBUG=gctrace=1
помогите мне развеять мои сомнения
После настройки информация, связанная с gc, будет распечатана, переведена здесь, можно увидеть больше контента.runtime package
Информация о сборе мусора
gc 1 @2.104s 0%: 0.018+1.3+0.076 ms clock, 0.054+0.35/1.0/3.0+0.23 ms cpu, 4->4->3 MB, 5 MB goal, 4 P。
1
Указывает на первое выполнение
@2.104s
Указывает общее время выполнения программы
0%
процент времени сборки мусора
0.018+1.3+0.076 ms clock
Время сбора мусора, соответственно время очистки STW (stop-the-world), время одновременной маркировки и сканирования, время маркировки STW
0.054+0.35/1.0/3.0+0.23 ms cpu
Сборка мусора занимает процессорное время
4->4->3 MB
Размер кучи, размер кучи после gc, размер живой кучи
5 MB goal
общий размер кучи
4 P
Количество используемых процессоров
Информация о высвобождении системной памяти
Число после scvg начинается с 0, что указывает на количество раз
scvg0: inuse: 426, idle: 0, sys: 427, released: 0, consumed: 427 (MB)
inuse
Сколько M памяти используется
idle
осталось очистить память
sys
Память памяти системы сопоставления системы
released
освобожденная системная память
consumed
Выделенная системная память
беговая запись
# 开始运行程序,疯狂的向内存写入
gc 1 @0.008s 3%: 0.10+0.48+0.050 ms clock, 0.20+0.14/0.30/0.37+0.10 ms cpu, 4->4->3 MB, 5 MB goal, 2 P
gc 2 @0.059s 1%: 0.029+0.80+0.026 ms clock, 0.059+0.17/0.58/0.72+0.052 ms cpu, 6->6->6 MB, 7 MB goal, 2 P
gc 3 @0.214s 1%: 1.9+0.71+0.045 ms clock, 3.8+0.39/0/2.6+0.091 ms cpu, 12->13->11 MB, 13 MB goal, 2 P
gc 4 @0.525s 0%: 0.014+0.50+0.025 ms clock, 0.028+0/0.49/0.48+0.051 ms cpu, 21->21->17 MB, 22 MB goal, 2 P
gc 5 @0.936s 0%: 0.005+0.52+0.007 ms clock, 0.010+0.13/0.35/0.42+0.015 ms cpu, 33->33->33 MB, 34 MB goal, 2 P
gc 6 @1.811s 0%: 0.051+0.72+0.12 ms clock, 0.10+0.38/0.17/0.71+0.25 ms cpu, 66->66->58 MB, 67 MB goal, 2 P
gc 7 @3.147s 0%: 0.023+0.87+0.050 ms clock, 0.047+0.70/0.050/0.79+0.10 ms cpu, 114->117->108 MB, 117 MB goal, 2 P
gc 8 @5.771s 0%: 0.017+0.74+0.080 ms clock, 0.035+0.29/0.30/0.72+0.16 ms cpu, 206->207->178 MB, 216 MB goal, 2 P
gc 9 @9.786s 0%: 0.006+0.55+0.017 ms clock, 0.013+0.18/0.34/0.54+0.034 ms cpu, 348->348->311 MB, 357 MB goal, 2 P
gc 10 @16.736s 0%: 0.026+1.0+0.031 ms clock, 0.053+0.33/0.62/0.97+0.063 ms cpu, 607->607->524 MB, 622 MB goal, 2 P
gc 11 @29.045s 0%: 0.039+1.3+0.034 ms clock, 0.078+0.52/0.46/1.2+0.069 ms cpu, 1022->1025->913 MB, 1048 MB goal, 2 P
gc 12 @50.471s 0%: 0.056+2.0+0.023 ms clock, 0.11+0.68/1.0/1.9+0.047 ms cpu, 1782->1783->1536 MB, 1827 MB goal, 2 P
scvg0: inuse: 1642, idle: 142, sys: 1784, released: 0, consumed: 1784 (MB)
# 写入一段时间后,GC,堆内存减小,但是仍未向系统释放内存
GC forced
gc 13 @170.610s 0%: 0.031+2.4+0.091 ms clock, 0.062+0/2.3/0+0.18 ms cpu, 1650->1650->381 MB, 3072 MB goal, 2 P
# 再次GC
GC forced
gc 14 @290.810s 0%: 0.020+1.7+0.039 ms clock, 0.041+0/1.6/0+0.078 ms cpu, 464->464->1 MB, 762 MB goal, 2 P
gc 15 @292.210s 0%: 0.036+0.98+0.14 ms clock, 0.073+0.21/0.51/0.91+0.28 ms cpu, 4->4->3 MB, 5 MB goal, 2 P
gc 16 @297.784s 0%: 0.029+0.64+0.043 ms clock, 0.058+0.20/0.17/0.62+0.086 ms cpu, 7->7->2 MB, 8 MB goal, 2 P
# 仍未释放内存
scvg1: inuse: 3, idle: 1781, sys: 1784, released: 0, consumed: 1784 (MB)
gc 17 @309.790s 0%: 0.034+1.4+0.045 ms clock, 0.068+1.2/0/0+0.090 ms cpu, 5->5->3 MB, 6 MB goal, 2 P
gc 18 @315.795s 0%: 0.027+0.79+0.052 ms clock, 0.055+0.34/0.29/0.78+0.10 ms cpu, 5->6->2 MB, 7 MB goal, 2 P
gc 19 @321.799s 0%: 0.027+0.81+0.076 ms clock, 0.055+0.18/0.35/0.85+0.15 ms cpu, 4->4->3 MB, 5 MB goal, 2 P
gc 20 @324.802s 0%: 0.023+1.2+0.062 ms clock, 0.047+0.76/0.31/0.36+0.12 ms cpu, 4->6->2 MB, 6 MB goal, 2 P
gc 21 @324.804s 0%: 0.016+0.67+0.034 ms clock, 0.033+0.46/0.048/0.66+0.068 ms cpu, 4->5->5 MB, 5 MB goal, 2 P
gc 22 @330.808s 0%: 0.028+0.85+0.036 ms clock, 0.056+0.36/0.27/0.82+0.072 ms cpu, 6->7->2 MB, 10 MB goal, 2 P
gc 23 @333.810s 0%: 0.020+0.89+0.085 ms clock, 0.041+0.65/0/0.76+0.17 ms cpu, 4->5->4 MB, 5 MB goal, 2 P
gc 24 @336.812s 0%: 0.079+0.84+0.12 ms clock, 0.15+0/0.82/0.65+0.24 ms cpu, 5->5->1 MB, 8 MB goal, 2 P
gc 25 @339.814s 0%: 0.11+1.2+0.040 ms clock, 0.22+0.14/0.97/0+0.081 ms cpu, 4->4->3 MB, 5 MB goal, 2 P
gc 26 @348.817s 0%: 0.048+1.4+0.062 ms clock, 0.097+1.2/0/0+0.12 ms cpu, 6->7->3 MB, 7 MB goal, 2 P
gc 27 @348.819s 0%: 0.019+0.63+0.046 ms clock, 0.039+0.26/0.31/0.58+0.092 ms cpu, 4->4->4 MB, 6 MB goal, 2 P
gc 28 @357.825s 0%: 0.027+1.2+0.11 ms clock, 0.054+0.25/0.12/1.0+0.22 ms cpu, 8->9->3 MB, 9 MB goal, 2 P
gc 29 @363.829s 0%: 0.020+0.71+0.010 ms clock, 0.040+0.53/0/0.70+0.021 ms cpu, 5->6->3 MB, 6 MB goal, 2 P
gc 30 @363.830s 0%: 0.007+0.50+0.070 ms clock, 0.014+0.16/0.21/0.48+0.14 ms cpu, 4->4->4 MB, 6 MB goal, 2 P
gc 31 @366.832s 0%: 0.019+0.89+0.026 ms clock, 0.038+0.15/0.46/0.77+0.052 ms cpu, 7->8->5 MB, 9 MB goal, 2 P
gc 32 @372.837s 0%: 0.026+0.79+0.061 ms clock, 0.052+0.16/0.52/0.71+0.12 ms cpu, 8->8->1 MB, 10 MB goal, 2 P
gc 33 @378.841s 0%: 0.029+0.87+0.062 ms clock, 0.059+0.68/0.053/0.76+0.12 ms cpu, 4->5->3 MB, 5 MB goal, 2 P
gc 34 @378.842s 0%: 0.075+0.73+0.077 ms clock, 0.15+0.37/0.15/0.64+0.15 ms cpu, 4->5->5 MB, 6 MB goal, 2 P
gc 35 @385.210s 0%: 0.079+0.90+0.11 ms clock, 0.15+0.35/0.47/0.79+0.23 ms cpu, 6->6->1 MB, 10 MB goal, 2 P
gc 36 @387.847s 0%: 0.021+0.67+0.046 ms clock, 0.042+0.53/0/0.64+0.092 ms cpu, 4->4->4 MB, 5 MB goal, 2 P
gc 37 @390.849s 0%: 0.10+0.68+0.043 ms clock, 0.21+0.23/0.32/0.66+0.087 ms cpu, 5->6->3 MB, 9 MB goal, 2 P
gc 38 @396.853s 0%: 0.071+0.95+0.031 ms clock, 0.14+0.50/0.70/0.40+0.062 ms cpu, 4->6->2 MB, 6 MB goal, 2 P
gc 39 @396.854s 0%: 0.011+1.2+0.033 ms clock, 0.022+0.53/0.58/0+0.067 ms cpu, 4->4->4 MB, 6 MB goal, 2 P
gc 40 @399.856s 0%: 0.017+0.89+0.024 ms clock, 0.035+0.29/0.28/0.86+0.048 ms cpu, 6->7->4 MB, 9 MB goal, 2 P
gc 41 @402.857s 0%: 0.038+0.57+0.050 ms clock, 0.077+0.22/0.12/0.51+0.10 ms cpu, 6->6->3 MB, 8 MB goal, 2 P
gc 42 @408.860s 0%: 0.091+0.86+0.10 ms clock, 0.18+0.63/0.005/0.77+0.21 ms cpu, 6->7->3 MB, 7 MB goal, 2 P
gc 43 @409.210s 0%: 0.028+1.0+0.093 ms clock, 0.057+0.23/0.70/0.88+0.18 ms cpu, 4->4->4 MB, 6 MB goal, 2 P
gc 44 @417.866s 0%: 0.019+0.69+0.018 ms clock, 0.039+0.50/0/0.67+0.037 ms cpu, 8->9->2 MB, 9 MB goal, 2 P
gc 45 @417.867s 0%: 0.018+0.68+0.079 ms clock, 0.037+0.37/0.049/0.66+0.15 ms cpu, 4->5->5 MB, 5 MB goal, 2 P
gc 46 @423.871s 0%: 0.077+0.75+0.059 ms clock, 0.15+0.24/0.21/0.72+0.11 ms cpu, 7->7->2 MB, 10 MB goal, 2 P
gc 47 @429.872s 0%: 0.065+0.54+0.091 ms clock, 0.13+0.17/0.32/0.50+0.18 ms cpu, 4->4->2 MB, 5 MB goal, 2 P
gc 48 @435.874s 0%: 0.017+0.68+0.11 ms clock, 0.035+0.13/0.43/0.60+0.22 ms cpu, 4->4->3 MB, 5 MB goal, 2 P
gc 49 @438.876s 0%: 0.012+0.54+0.050 ms clock, 0.024+0.093/0.39/0.51+0.10 ms cpu, 5->5->1 MB, 6 MB goal, 2 P
gc 50 @444.880s 0%: 0.027+0.79+0.065 ms clock, 0.055+0.18/0.50/0.71+0.13 ms cpu, 4->4->2 MB, 5 MB goal, 2 P
gc 51 @447.882s 0%: 0.023+0.70+0.052 ms clock, 0.047+0.37/0.53/0.29+0.10 ms cpu, 4->5->4 MB, 5 MB goal, 2 P
# 仍未释放内存
scvg2: inuse: 5, idle: 1778, sys: 1784, released: 0, consumed: 1784 (MB)
gc 52 @450.884s 0%: 0.019+0.73+0.13 ms clock, 0.038+0.23/0.23/0.71+0.26 ms cpu, 6->6->2 MB, 8 MB goal, 2 P
gc 53 @453.887s 0%: 0.034+0.79+0.024 ms clock, 0.069+0.61/0/0.77+0.048 ms cpu, 4->5->3 MB, 5 MB goal, 2 P
gc 54 @453.888s 0%: 0.13+0.79+0.093 ms clock, 0.26+0.15/0.77/0.31+0.18 ms cpu, 5->5->5 MB, 7 MB goal, 2 P
gc 55 @456.889s 0%: 0.051+0.76+0.10 ms clock, 0.10+0.20/0.18/0.74+0.21 ms cpu, 8->9->5 MB, 10 MB goal, 2 P
gc 56 @462.892s 0%: 0.019+0.55+0.12 ms clock, 0.038+0.24/0.12/0.51+0.24 ms cpu, 8->8->2 MB, 10 MB goal, 2 P
gc 57 @465.893s 0%: 0.015+0.54+0.052 ms clock, 0.031+0.11/0.33/0.49+0.10 ms cpu, 4->4->4 MB, 5 MB goal, 2 P
gc 58 @468.896s 0%: 0.059+0.68+0.050 ms clock, 0.11+0.44/0.054/0.65+0.10 ms cpu, 6->7->4 MB, 8 MB goal, 2 P
gc 59 @471.897s 0%: 0.019+0.71+0.15 ms clock, 0.038+0.29/0.24/0.63+0.30 ms cpu, 7->8->4 MB, 9 MB goal, 2 P
gc 60 @474.899s 0%: 0.026+0.83+0.046 ms clock, 0.052+0.37/0.27/0.79+0.093 ms cpu, 6->8->4 MB, 9 MB goal, 2 P
gc 61 @480.903s 0%: 0.12+0.90+0.021 ms clock, 0.25+0.31/0.68/0.56+0.043 ms cpu, 6->8->4 MB, 9 MB goal, 2 P
gc 62 @489.908s 0%: 0.026+0.85+0.097 ms clock, 0.052+0.42/0.30/0.77+0.19 ms cpu, 6->6->2 MB, 8 MB goal, 2 P
gc 63 @492.910s 0%: 0.030+0.75+0.10 ms clock, 0.061+0.57/0/0.69+0.20 ms cpu, 4->5->3 MB, 5 MB goal, 2 P
gc 64 @495.913s 0%: 0.036+0.61+0.11 ms clock, 0.073+0.27/0/0.49+0.22 ms cpu, 4->8->4 MB, 7 MB goal, 2 P
gc 65 @498.915s 0%: 0.018+0.84+0.051 ms clock, 0.037+0.41/0.085/0.68+0.10 ms cpu, 5->9->5 MB, 9 MB goal, 2 P
gc 66 @501.917s 0%: 0.079+0.65+0.10 ms clock, 0.15+0.18/0.16/0.62+0.21 ms cpu, 6->8->4 MB, 10 MB goal, 2 P
gc 67 @504.918s 0%: 0.026+0.94+0.10 ms clock, 0.052+0.29/0.14/0.93+0.20 ms cpu, 5->7->4 MB, 9 MB goal, 2 P
gc 68 @507.920s 0%: 0.12+1.7+0.040 ms clock, 0.25+1.1/0.17/0+0.080 ms cpu, 5->7->4 MB, 8 MB goal, 2 P
gc 69 @516.926s 0%: 0.027+0.89+0.039 ms clock, 0.054+0.36/0.24/0.81+0.078 ms cpu, 5->7->3 MB, 9 MB goal, 2 P
gc 70 @519.929s 0%: 0.018+0.85+0.010 ms clock, 0.037+0.48/0.036/0.81+0.020 ms cpu, 4->6->4 MB, 6 MB goal, 2 P
gc 71 @522.930s 0%: 0.015+0.66+0.069 ms clock, 0.030+0.33/0.033/0.62+0.13 ms cpu, 5->7->4 MB, 8 MB goal, 2 P
gc 72 @525.933s 0%: 0.031+0.99+0.048 ms clock, 0.063+0.44/0.37/0.93+0.097 ms cpu, 5->5->2 MB, 8 MB goal, 2 P
gc 73 @528.934s 0%: 0.024+1.1+0.079 ms clock, 0.049+0.12/0.96/0+0.15 ms cpu, 4->4->2 MB, 6 MB goal, 2 P
gc 74 @531.936s 0%: 0.095+0.82+0.026 ms clock, 0.19+0.16/0.41/0.80+0.053 ms cpu, 4->5->3 MB, 5 MB goal, 2 P
gc 75 @537.938s 0%: 0.15+1.0+0.038 ms clock, 0.30+0.60/0.006/1.0+0.076 ms cpu, 5->7->3 MB, 7 MB goal, 2 P
gc 76 @537.940s 0%: 0.14+1.2+0.041 ms clock, 0.29+0.41/0.77/0+0.083 ms cpu, 5->5->5 MB, 7 MB goal, 2 P
gc 77 @543.944s 0%: 0.094+1.0+0.15 ms clock, 0.094+0.54/0.010/0.90+0.15 ms cpu, 8->10->4 MB, 10 MB goal, 2 P
gc 78 @549.948s 0%: 0.026+0.87+0.029 ms clock, 0.053+0.55/0.010/0.82+0.058 ms cpu, 6->8->3 MB, 8 MB goal, 2 P
gc 79 @555.952s 0%: 0.13+0.89+0.055 ms clock, 0.26+0.50/0.028/0.79+0.11 ms cpu, 4->6->3 MB, 6 MB goal, 2 P
gc 80 @555.954s 0%: 0.017+0.67+0.13 ms clock, 0.035+0.14/0.34/0.65+0.26 ms cpu, 5->5->5 MB, 7 MB goal, 2 P
gc 81 @558.955s 0%: 0.013+0.78+0.044 ms clock, 0.026+0.27/0.29/0.74+0.089 ms cpu, 6->7->3 MB, 10 MB goal, 2 P
gc 82 @561.957s 0%: 0.13+1.5+0.012 ms clock, 0.26+1.1/0.17/0+0.025 ms cpu, 5->6->4 MB, 6 MB goal, 2 P
gc 83 @564.961s 0%: 0.029+0.80+0.12 ms clock, 0.058+0.18/0.56/0.65+0.25 ms cpu, 5->5->2 MB, 8 MB goal, 2 P
gc 84 @567.963s 0%: 0.030+0.78+0.067 ms clock, 0.061+0.16/0.35/0.89+0.13 ms cpu, 4->4->3 MB, 5 MB goal, 2 P
gc 85 @570.965s 0%: 0.028+0.78+0.015 ms clock, 0.057+0.48/0.53/0.16+0.030 ms cpu, 5->6->3 MB, 6 MB goal, 2 P
gc 86 @574.210s 0%: 0.11+0.84+0.059 ms clock, 0.23+0.14/0.60/0.77+0.11 ms cpu, 5->5->2 MB, 6 MB goal, 2 P
gc 87 @576.968s 0%: 0.057+0.68+0.089 ms clock, 0.11+0.49/0.018/0.62+0.17 ms cpu, 4->5->3 MB, 5 MB goal, 2 P
gc 88 @576.969s 0%: 0.039+0.99+0.043 ms clock, 0.079+0.13/0.80/0+0.086 ms cpu, 5->5->5 MB, 7 MB goal, 2 P
gc 89 @591.974s 0%: 0.025+1.0+0.043 ms clock, 0.050+0.65/0/0.76+0.087 ms cpu, 8->10->3 MB, 10 MB goal, 2 P
gc 90 @594.976s 0%: 0.066+1.8+0.033 ms clock, 0.13+1.0/0/0+0.067 ms cpu, 4->6->3 MB, 6 MB goal, 2 P
gc 91 @594.979s 0%: 0.014+0.58+0.070 ms clock, 0.029+0.17/0.19/0.56+0.14 ms cpu, 4->4->4 MB, 6 MB goal, 2 P
# 释放了!!!!!!!!!!!!!!!!!!
scvg3: 1767 MB released
scvg3: inuse: 5, idle: 1778, sys: 1784, released: 1767, consumed: 17 (MB)
gc 92 @603.984s 0%: 0.022+0.81+0.12 ms clock, 0.044+0.42/0.086/0.66+0.24 ms cpu, 6->9->4 MB, 9 MB goal, 2 P
gc 93 @606.986s 0%: 0.11+1.0+0.024 ms clock, 0.22+0.53/0.038/0.96+0.048 ms cpu, 5->8->5 MB, 9 MB goal, 2 P
gc 94 @609.988s 0%: 0.029+0.88+0.070 ms clock, 0.058+0.26/0.43/0.73+0.14 ms cpu, 6->6->2 MB, 10 MB goal, 2 P
gc 95 @612.989s 0%: 0.019+0.59+0.026 ms clock, 0.038+0.28/0.12/0.55+0.053 ms cpu, 4->5->3 MB, 6 MB goal, 2 P
gc 96 @615.991s 0%: 0.081+0.91+0.034 ms clock, 0.16+0.50/0.022/0.88+0.069 ms cpu, 4->7->4 MB, 7 MB goal, 2 P
gc 97 @618.994s 0%: 0.027+0.76+0.048 ms clock, 0.054+0/0.18/1.3+0.097 ms cpu, 5->5->2 MB, 9 MB goal, 2 P
gc 98 @627.999s 0%: 0.023+0.81+0.075 ms clock, 0.046+0.40/0.23/0.73+0.15 ms cpu, 4->4->2 MB, 5 MB goal, 2 P
gc 99 @634.003s 0%: 0.032+1.3+0.057 ms clock, 0.064+0.60/0.43/0.96+0.11 ms cpu, 4->4->3 MB, 5 MB goal, 2 P
gc 100 @640.006s 0%: 0.018+0.63+0.12 ms clock, 0.036+0.10/0.45/0.60+0.24 ms cpu, 5->5->1 MB, 7 MB goal, 2 P
gc 101 @649.007s 0%: 1.0+0.76+0.047 ms clock, 2.1+0.22/1.8/0+0.094 ms cpu, 4->5->3 MB, 5 MB goal, 2 P
gc 102 @652.010s 0%: 0.017+0.64+0.068 ms clock, 0.035+0.11/0.46/0.63+0.13 ms cpu, 4->4->2 MB, 6 MB goal, 2 P
gc 103 @661.014s 0%: 0.10+0.78+0.071 ms clock, 0.21+0.61/0/0.76+0.14 ms cpu, 4->5->2 MB, 5 MB goal, 2 P
gc 104 @664.016s 0%: 0.027+0.94+0.10 ms clock, 0.055+0.62/0.001/0.81+0.20 ms cpu, 4->6->3 MB, 6 MB goal, 2 P
gc 105 @667.019s 0%: 0.024+0.76+0.060 ms clock, 0.048+0.15/0.52/0.69+0.12 ms cpu, 4->4->2 MB, 7 MB goal, 2 P
gc 106 @673.022s 0%: 0.023+0.91+0.064 ms clock, 0.047+0.50/0.056/0.83+0.12 ms cpu, 4->5->3 MB, 6 MB goal, 2 P
gc 107 @676.025s 0%: 0.020+1.5+0.038 ms clock, 0.040+1.0/0.17/0+0.077 ms cpu, 4->5->3 MB, 6 MB goal, 2 P
gc 108 @679.028s 0%: 0.031+1.6+0.047 ms clock, 0.063+0.98/0.26/0+0.095 ms cpu, 5->7->4 MB, 7 MB goal, 2 P
gc 109 @682.031s 0%: 0.018+0.93+0.032 ms clock, 0.036+0.40/0.19/0.78+0.064 ms cpu, 5->6->3 MB, 8 MB goal, 2 P
gc 110 @685.033s 0%: 0.086+0.84+0.12 ms clock, 0.17+0.46/0.11/0.79+0.25 ms cpu, 4->6->3 MB, 7 MB goal, 2 P
gc 111 @688.036s 0%: 0.051+1.7+0.040 ms clock, 0.10+1.1/0.18/0+0.080 ms cpu, 4->6->4 MB, 7 MB goal, 2 P
gc 112 @691.038s 0%: 0.10+1.1+0.044 ms clock, 0.21+0.45/0.20/1.1+0.089 ms cpu, 5->7->4 MB, 8 MB goal, 2 P
gc 113 @694.040s 0%: 0.013+0.60+0.12 ms clock, 0.026+0.086/0.47/0.54+0.25 ms cpu, 5->5->2 MB, 9 MB goal, 2 P
gc 114 @700.043s 0%: 0.027+0.92+0.061 ms clock, 0.054+0.26/0.50/0.62+0.12 ms cpu, 4->5->3 MB, 5 MB goal, 2 P
Прочитать состояние памяти в программе
runtime package
import "runtime"
var m runtime.MemStats
func(){
runtime.ReadMemStats(&m)
# m.Alloc 堆内存
}()
Используйте стандартную библиотеку expvar
Вы можете обратиться к этомуреальный бой, вы можете прочитать статус программы, открыв http-интерфейс