{"id":298525,"date":"2020-02-11T15:00:16","date_gmt":"2020-02-11T15:00:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298525"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-02-11T15:00:16","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298525","title":{"rendered":"\u041a\u0430\u043a \u043c\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u0448 DNS-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 GO"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/487934\/\"><i>\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u043e \u043a\u0443\u0440\u0441\u0443 <a href=\"https:\/\/otus.pw\/MA66\/\">\u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a Golang\u00bb<\/a> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430.<\/i><\/p>\n<hr>\n<p>  \u041d\u0430\u0448 <a href=\"https:\/\/github.com\/hawell\/redins\">\u0430\u0432\u0442\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u0439 DNS-\u0441\u0435\u0440\u0432\u0435\u0440<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0442\u044b\u0441\u044f\u0447 \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u043e\u0432. \u041c\u044b \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u043c \u043d\u0430 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412 \u043d\u0430\u0448\u0438 \u0434\u043d\u0438 DNS-\u0430\u0442\u0430\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0431\u043e\u043b\u0435\u0435 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c\u0438, DNS \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u0434 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439.<\/p>\n<p>  <a href=\"https:\/\/github.com\/nickwinn\/dns-flood\">dnsflood<\/a> \u2014 \u044d\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e udp \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<pre><code class=\"go\"># timeout 20s .\/dnsflood example.com 127.0.0.1 -p 2053<\/code><\/pre>\n<p>  \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0438\u0441\u0442\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0448\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0440\u043e\u0441\u043b\u043e \u0442\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0435\u0433\u043e, \u0438\u043d\u0430\u0447\u0435 \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0431\u044b \u0441 OOM \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0443\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438; \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u00ab\u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u043d\u0430\u00bb \u0438 \u00ab\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445\u00bb \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 go:<a name=\"habracut\"><\/a><\/p>\n<ul>\n<li>\u0432\u0438\u0441\u044f\u0449\u0438\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b<\/li>\n<li>\u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 defer \u0438 finalizer<\/li>\n<li>\u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u043f\u043e\u0434\u0441\u0440\u0435\u0437\u044b<\/li>\n<li>\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/li>\n<\/ul>\n<p>  <a href=\"https:\/\/go101.org\/article\/memory-leaking.html\">\u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442<\/a> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0443\u0442\u0435\u0447\u0435\u043a.<\/p>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0432\u044b\u0432\u043e\u0434\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<h3>GODEBUG<\/h3>\n<p>  \u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u044b <code>GODEBUG<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u044f\u0442\u044b\u043c\u0438 \u043f\u0430\u0440 <code>name=value<\/code>.<\/p>\n<h4>\u0422\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430<\/h4>\n<p>  \u0422\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 (scheduler trace) \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 <code>GODEBUG=schedtrace=100<\/code>, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043c\u0441.<\/p>\n<pre><code class=\"go\">$ GODEBUG=schedtrace=100 .\/redins -c config.json SCHED 2952ms: ... runqueue=3 [26 11 7 18 13 30 6 3 24 25 11 0] SCHED 3053ms: ... runqueue=3 [0 0 0 0 0 0 0 0 4 0 21 0] SCHED 3154ms: ... runqueue=0 [0 6 2 4 0 30 0 5 0 11 2 5] SCHED 3255ms: ... runqueue=1 [0 0 0 0 0 0 0 0 0 0 0 0] SCHED 3355ms: ... runqueue=0 [1 0 0 0 0 0 0 0 0 0 0 0] SCHED 3456ms: ... runqueue=0 [0 0 0 0 0 0 0 0 0 0 0 0] SCHED 3557ms: ... runqueue=0 [13 0 3 0 3 33 2 0 10 8 10 14] SCHED 3657ms: ...runqueue=3 [14 1 0 5 19 54 9 1 0 1 29 0] SCHED 3758ms: ... runqueue=0 [67 1 5 0 0 1 0 0 87 4 0 0] SCHED 3859ms: ... runqueue=6 [0 0 3 6 0 0 0 0 3 2 2 19] SCHED 3960ms: ... runqueue=0 [0 0 1 0 1 0 0 1 0 1 0 0] SCHED 4060ms: ... runqueue=5 [4 0 5 0 1 0 0 0 0 0 0 0] SCHED 4161ms: ... runqueue=0 [0 0 0 0 0 0 0 1 0 0 0 0] SCHED 4262ms: ... runqueue=4 [0 128 21 172 1 19 8 2 43 5 139 37] SCHED 4362ms: ... runqueue=0 [0 0 0 0 0 0 0 0 0 0 0 0] SCHED 4463ms: ... runqueue=6 [0 28 23 39 4 11 4 11 25 0 25 0] SCHED 4564ms: ... runqueue=354 [51 45 33 32 15 20 8 7 5 42 6 0]<\/code><\/pre>\n<p>  <i>runqueue<\/i> \u2014 \u044d\u0442\u043e \u0434\u043b\u0438\u043d\u0430 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d. \u0427\u0438\u0441\u043b\u0430 \u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445 \u2014 \u044d\u0442\u043e \u0434\u043b\u0438\u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<p>  \u0418\u0434\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u2014 \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0437\u0430\u043d\u044f\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d, \u0438 \u0443\u043c\u0435\u0440\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438:<\/p>\n<pre><code class=\"go\">SCHED 2449ms: gomaxprocs=12 idleprocs=0 threads=40 spinningthreads=1 idlethreads=1 runqueue=20 [20 20 20 20 20 20 20 20 20 20 20]<\/code><\/pre>\n<p>  \u0413\u043b\u044f\u0434\u044f \u043d\u0430 \u0432\u044b\u0432\u043e\u0434 <i>schedtrace<\/i>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0435\u0440\u0438\u043e\u0434\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u044e\u0442. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043d\u0430 \u043f\u043e\u043b\u043d\u0443\u044e \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h4>\u0422\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u043c\u0443\u0441\u043e\u0440\u0430<\/h4>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u043c\u0443\u0441\u043e\u0440\u0430 (GC), \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u044b <code>GODEBUG=gctrace=1<\/code>:<\/p>\n<pre><code class=\"go\">GODEBUG=gctrace=1 .\/redins -c config1.json . . . gc 30 @3.727s 1%: 0.066+21+0.093 ms clock, 0.79+128\/59\/0+1.1 ms cpu, 67-&gt;71-&gt;45 MB, 76 MB goal, 12 P gc 31 @3.784s 2%: 0.030+27+0.053 ms clock, 0.36+177\/81\/7.8+0.63 ms cpu, 79-&gt;84-&gt;55 MB, 90 MB goal, 12 P gc 32 @3.858s 3%: 0.026+34+0.024 ms clock, 0.32+234\/104\/0+0.29 ms cpu, 96-&gt;100-&gt;65 MB, 110 MB goal, 12 P gc 33 @3.954s 3%: 0.026+44+0.13 ms clock, 0.32+191\/131\/57+1.6 ms cpu, 117-&gt;123-&gt;79 MB, 131 MB goal, 12 P gc 34 @4.077s 4%: 0.010+53+0.024 ms clock, 0.12+241\/159\/69+0.29 ms cpu, 142-&gt;147-&gt;91 MB, 158 MB goal, 12 P gc 35 @4.228s 5%: 0.017+61+0.12 ms clock, 0.20+296\/179\/94+1.5 ms cpu, 166-&gt;174-&gt;105 MB, 182 MB goal, 12 P gc 36 @4.391s 6%: 0.017+73+0.086 ms clock, 0.21+492\/216\/4.0+1.0 ms cpu, 191-&gt;198-&gt;122 MB, 210 MB goal, 12 P gc 37 @4.590s 7%: 0.049+85+0.095 ms clock, 0.59+618\/253\/0+1.1 ms cpu, 222-&gt;230-&gt;140 MB, 244 MB goal, 12 P . . .<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u0432\u0438\u0434\u0438\u043c, \u043e\u0431\u044a\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a\u0436\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 gc \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0435\u043c \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0435 \u043e <code>GODEBUG<\/code> \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u044b golang \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c <a href=\"https:\/\/dave.cheney.net\/tag\/godebug\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h4>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430<\/h4>\n<p>  <code>go tool pprof<\/code> \u2014 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c <code>pprof<\/code>: \u043b\u0438\u0431\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>runtime\/pprof<\/code> \u0432 \u0432\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>pprof.StartCPUProfile()<\/code>, \u043b\u0438\u0431\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c <code>net\/http\/pprof<\/code> http-\u043b\u0438\u0441\u0442\u043d\u0435\u0440 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043e\u0442\u0442\u0443\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u0423 <code>pprof<\/code> \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435, \u043d\u043e \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u044b \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u044d\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 <i>\u00abnet\/http\/pprof\u00bb<\/i>:<\/p>\n<pre><code class=\"go\">import (   _ &quot;net\/http\/pprof&quot; )<\/code><\/pre>\n<p>  \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c http-\u043b\u0438\u0441\u0442\u043d\u0435\u0440:<\/p>\n<pre><code class=\"go\">go func() {   log.Println(http.ListenAndServe(&quot;localhost:6060&quot;, nil)) }()<\/code><\/pre>\n<p>  \u0423 pprof \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e:<\/p>\n<ul>\n<li><b>allocs<\/b>: \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0448\u043b\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/li>\n<li><b>block<\/b>: \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u0435\u043b\u0430 \u043a \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438<\/li>\n<li><b>goroutine<\/b>: \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0435\u043a\u0430 \u0432\u0441\u0435\u0445 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/li>\n<li><b>heap<\/b>: \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0436\u0438\u0432\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/li>\n<li><b>mutex<\/b>: \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0435\u043a\u0430 \u0434\u0435\u0440\u0436\u0430\u0442\u0435\u043b\u0435\u0439 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0443\u044e\u0449\u0438\u0445 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432<\/li>\n<li><b>profile<\/b>: \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430.<\/li>\n<li><b>threadcreate<\/b>: \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u0435\u043b\u0430 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u041e\u0421<\/li>\n<li><b>trace<\/b>: \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/li>\n<\/ul>\n<p>  <\/p>\n<blockquote><p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u043c <i>\u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438<\/i>, \u0430 \u043d\u0435 <i>pprof<\/i>, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0433\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f go tool trace \u0432\u043c\u0435\u0441\u0442\u043e <code>go tool pprof<\/code>.<\/p><\/blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<h4>\u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/h4>\n<p>  <\/p>\n<pre><code class=\"go\">\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d\u200d$ go tool pprof http:\/\/localhost:6060\/debug\/pprof\/profile?seconds=10<\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 30 \u0441\u0435\u043a\u0443\u043d\u0434 (\u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e, \u0437\u0430\u0434\u0430\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>seconds<\/code>) \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a\u0430\u0436\u0434\u044b\u0435 100 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u043d \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c. \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <code>top<\/code>, <code>list<\/code>, <code>web<\/code>.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>top n<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0441\u0430\u043c\u044b\u0445 \u0433\u043e\u0440\u044f\u0447\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043e\u043f\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0432\u044b\u0432\u043e\u0434\u0430, <code>-cum<\/code> \u0434\u043b\u044f \u043a\u0443\u043c\u0443\u043b\u044f\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0438 <code>-flat<\/code>.<\/p>\n<pre><code class=\"go\">(pprof) top 10 -cum Showing nodes accounting for 1.50s, 6.19% of 24.23s total Dropped 347 nodes (cum &lt;= 0.12s) Showing top 10 nodes out of 186 flat  flat%   sum%  cum   cum% 0.03s 0.12% 0.12% 16.7s 69.13% (*Server).serveUDPPacket 0.05s 0.21% 0.33% 15.6s 64.51% (*Server).serveDNS 0     0%    0.33% 14.3s 59.10% (*ServeMux).ServeDNS 0     0%    0.33% 14.2s 58.73% HandlerFunc.ServeDNS 0.01s 0.04% 0.37% 14.2s 58.73% main.handleRequest 0.07s 0.29% 0.66% 13.5s 56.00% (*DnsRequestHandler).HandleRequest 0.99s 4.09% 4.75% 7.56s 31.20% runtime.gentraceback 0.02s 0.08% 4.83% 7.02s 28.97% runtime.systemstack 0.31s 1.28% 6.11% 6.62s 27.32% runtime.mallocgc 0.02s 0.08% 6.19% 6.35s 26.21% (*DnsRequestHandler).FindANAME (pprof)<\/code><\/pre>\n<p>  \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>list<\/code>, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"go\">(pprof) list handleRequest Total: 24.23s ROUTINE ======================== main.handleRequest in \/home\/arash\/go\/src\/arvancloud\/redins\/redins.go      10ms     14.23s (flat, cum) 58.73% of Total         .          .     35: l          *handler.RateLimiter         .          .     36: configFile string         .          .     37:)         .          .     38:         .          .     39:func handleRequest(w dns.ResponseWriter, r *dns.Msg) {      10ms      610ms     40: context := handler.NewRequestContext(w, r)         .       50ms     41: logger.Default.Debugf(&quot;handle request: [%d] %s %s&quot;, r.Id, context.RawName(), context.Type())         .          .     42:         .          .     43: if l.CanHandle(context.IP()) {         .     13.57s     44:  h.HandleRequest(context)         .          .     45: } else {         .          .     46:  context.Response(dns.RcodeRefused)         .          .     47: }         .          .     48:}         .          .     49: (pprof) <\/code><\/pre>\n<p>  \u041a\u043e\u043c\u0430\u043d\u0434\u0430 <code>web<\/code> \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 SVG-\u0433\u0440\u0430\u0444\u0438\u043a \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432 \u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435.<\/p>\n<p>  <code>(pprof)web handleReques<\/code><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bt\/hi\/di\/bthidimalsguoeg_obuzzmzy7ro.png\"><\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 GC, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <code>runtime.mallocgc<\/code>, \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430 \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u043d\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>runtime.chansend<\/code> \u0438\u043b\u0438 <code>runtime.lock<\/code>, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0430.<\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u043d\u0430 <code>syscall.Read\/Write<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<h4>\u041f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0430\u043c\u044f\u0442\u0438<\/h4>\n<p>  <\/p>\n<pre><code class=\"go\">$ go tool pprof http:\/\/localhost:6060\/debug\/pprof\/allocs<\/code><\/pre>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>-alloc_objects<\/code>, \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438: <code>-iuse_objects<\/code> \u0438 <code>-inuse_space<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 <i>\u0436\u0438\u0432\u043e\u0439 <\/i>\u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <code>-inuse_space<\/code>, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 <code>-alloc_objects<\/code> \u043f\u043e\u0441\u043b\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f\/\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/p>\n<h4>\u0412\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u0437\u043a\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430<\/h4>\n<p>  \u0412\u0430\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f \u0443\u0437\u043a\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 (\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440, \u0432\u0432\u043e\u0434\/\u0432\u044b\u0432\u043e\u0434, \u043f\u0430\u043c\u044f\u0442\u044c), \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e. \u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432, \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0432\u0438\u0434 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  <code>go tool trace<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0434\u0435\u043b\u0430\u044e\u0442 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445. \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c http \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<pre><code class=\"go\">$ curl http:\/\/localhost:6060\/debug\/pprof\/trace?seconds=5 --output trace.out<\/code><\/pre>\n<p>  \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<pre><code class=\"go\">$ go tool trace trace.out 2019\/12\/25 15:30:50 Parsing trace... 2019\/12\/25 15:30:59 Splitting trace... 2019\/12\/25 15:31:10 Opening browser. Trace viewer is listening on http:\/\/127.0.0.1:42703<\/code><\/pre>\n<p>  Go tool trace \u2014 \u044d\u0442\u043e \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b Chrome DevTools \u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438 Chrome. \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=0&amp;end=1002182\">View trace (0s-409.575266ms)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=1002182&amp;end=2000009\">View trace (411.075559ms-747.252311ms)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=2000009&amp;end=2994454\">View trace (747.252311ms-1.234968945s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=2994454&amp;end=3990349\">View trace (1.234968945s-1.774245108s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=3990349&amp;end=4998414\">View trace (1.774245484s-2.111339514s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=4998414&amp;end=5994557\">View trace (2.111339514s-2.674030898s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=5994557&amp;end=6980207\">View trace (2.674031362s-3.044145798s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=6980207&amp;end=7955112\">View trace (3.044145798s-3.458795252s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=7955112&amp;end=8917871\">View trace (3.43953778s-4.075080634s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=8917871&amp;end=9878421\">View trace (4.075081098s-4.439271287s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=9878421&amp;end=10847838\">View trace (4.439271635s-4.814869651s)<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/trace?start=10847838&amp;end=11181263\">View trace (4.814869651s-5.253597835s)<\/a><\/p>\n<p>  <a href=\"http:\/\/127.0.0.1:42703\/goroutines\">Goroutine analysis<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/io\">Network blocking profile ()<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/block\">Synchronization blocking profile ()<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/syscall\">Syscall blocking profile ()<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/sched\">Scheduler latency profile ()<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/usertasks\">User-defined tasks<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/userregions\">User-defined regions<\/a><br \/>  <a href=\"http:\/\/127.0.0.1:42703\/mmu\">Minimum mutator utilization<\/a><\/p>\n<p>  \u0422\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043c\u043e\u0433 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xx\/xa\/pf\/xxxapfdolkivu1jce6axclwsmqg.png\"><\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c\u0438, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u043c \u0447\u0442\u043e \u0438\u0449\u0435\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u044d\u0442\u043e.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u2014 <i>\u00abgoroutine analysis\u00bb<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 <i>\u0432\u0438\u0434\u044b <\/i>\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<pre><code class=\"go\">Goroutines: github.com\/miekg\/dns.(*Server).serveUDPPacket N=441703 runtime.gcBgMarkWorker N=12 github.com\/karlseguin\/ccache.(*Cache).worker N=2 main.Start.func1 N=1 runtime.bgsweep N=1 arvancloud\/redins\/handler.NewHandler.func2 N=1 runtime\/trace.Start.func1 N=1 net\/http.(*conn).serve N=1 runtime.timerproc N=3 net\/http.(*connReader).backgroundRead N=1 N=40<\/code><\/pre>\n<p>  \u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 <b>N = 441703<\/b>, \u0432\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dh\/lt\/qy\/dhltqyepbyyuk_i7tcadrdyx_gs.png\"><br \/>  <i>\u0430\u043d\u0430\u043b\u0438\u0437 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/i><\/p>\n<p>  \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0442\u0440\u0430\u0442\u044f\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0430 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442 \u0432 \u0431\u043b\u043e\u043a\u0435 Sync. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0434\u043d\u0443 \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tu\/bs\/vt\/tubsvt8trkqhgjrfpjijolibof4.png\"><br \/>  <i>\u0441\u0445\u0435\u043c\u0430 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/i><\/p>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0435, \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u0430. \u041e\u0442\u0441\u044e\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0443 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438; \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435:<\/p>\n<pre><code class=\"go\">runtime.SetBlockProfileRate(1)<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a:<\/p>\n<pre><code class=\"go\">$ go tool pprof http:\/\/localhost:6060\/debug\/pprof\/block (pprof) top Showing nodes accounting for 16.03wks, 99.75% of 16.07wks total Dropped 87 nodes (cum &lt;= 0.08wks) Showing top 10 nodes out of 27      flat  flat%   sum%        cum   cum%  10.78wks 67.08% 67.08%   10.78wks 67.08%  internal\/poll.(*fdMutex).rwlock   5.25wks 32.67% 99.75%    5.25wks 32.67%  sync.(*Mutex).Lock         0     0% 99.75%    5.25wks 32.67%  arvancloud\/redins\/handler.(*DnsRequestHandler).Filter         0     0% 99.75%    5.25wks 32.68%  arvancloud\/redins\/handler.(*DnsRequestHandler).FindANAME         0     0% 99.75%   16.04wks 99.81%  arvancloud\/redins\/handler.(*DnsRequestHandler).HandleRequest         0     0% 99.75%   10.78wks 67.08%  arvancloud\/redins\/handler.(*DnsRequestHandler).Response         0     0% 99.75%   10.78wks 67.08%  arvancloud\/redins\/handler.(*RequestContext).Response         0     0% 99.75%    5.25wks 32.67%  arvancloud\/redins\/handler.ChooseIp         0     0% 99.75%   16.04wks 99.81%  github.com\/miekg\/dns.(*ServeMux).ServeDNS         0     0% 99.75%   16.04wks 99.81%  github.com\/miekg\/dns.(*Server).serveDNS (pprof)<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 (<i>poll.fdMutex \u0438 sync.Mutex<\/i>), \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0447\u0442\u0438 \u0437\u0430 100% \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a. \u042d\u0442\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0439\u0442\u0438, \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<pre><code class=\"go\">(pprof) svg lock<\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u044b, \u0441 \u0443\u043f\u043e\u0440\u043e\u043c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/in\/m4\/zu\/inm4zuykw5uum0vydotfudr48d0.png\"><br \/>  <i>svg-\u0433\u0440\u0430\u0444\u0438\u043a \u044d\u043d\u0434\u043f\u043e\u043d\u0442\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438<\/i><\/p>\n<p>  \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u0442 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b:<\/p>\n<pre><code class=\"go\">$ go tool pprof http:\/\/localhost:6060\/debug\/pprof\/goroutine<\/code><\/pre>\n<p>  \u0438 \u0437\u0430\u0442\u0435\u043c:<\/p>\n<pre><code class=\"go\">(pprof) top Showing nodes accounting for 294412, 100% of 294424 total Dropped 84 nodes (cum &lt;= 1472) Showing top 10 nodes out of 32      flat  flat%   sum%        cum   cum%    294404   100%   100%     294404   100%  runtime.gopark         8 0.0027%   100%     294405   100%  github.com\/miekg\/dns.(*Server).serveUDPPacket         0     0%   100%      58257 19.79%  arvancloud\/redins\/handler.(*DnsRequestHandler).Filter         0     0%   100%      58259 19.79%  arvancloud\/redins\/handler.(*DnsRequestHandler).FindANAME         0     0%   100%     293852 99.81%  arvancloud\/redins\/handler.(*DnsRequestHandler).HandleRequest         0     0%   100%     235406 79.95%  arvancloud\/redins\/handler.(*DnsRequestHandler).Response         0     0%   100%     235406 79.95%  arvancloud\/redins\/handler.(*RequestContext).Response         0     0%   100%      58140 19.75%  arvancloud\/redins\/handler.ChooseIp         0     0%   100%     293852 99.81%  github.com\/miekg\/dns.(*ServeMux).ServeDNS         0     0%   100%     293900 99.82%  github.com\/miekg\/dns.(*Server).serveDNS (pprof)<\/code><\/pre>\n<p>  \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 runtime.gopark, \u044d\u0442\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a go, \u0443\u0441\u044b\u043f\u043b\u044f\u044e\u0449\u0438\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b; \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u044d\u0442\u043e\u0433\u043e \u2014 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a<\/p>\n<pre><code class=\"go\">(pprof) svg gopark<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-r\/r6\/pe\/-rr6peofee7fshmvot6rb3usrjs.png\"><br \/>  <i>svg-\u0433\u0440\u0430\u0444\u0438\u043a \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/i><\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0434\u0432\u0430 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432:<\/p>\n<h2>UDPConn.WriteMsg()<\/h2>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u0432\u0441\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 FD (\u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430), \u044d\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0430\u0434\u0440\u0435\u0441 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.<\/p>\n<p>  \u041c\u044b \u043f\u0440\u043e\u0432\u0435\u043b\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438, \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0435\u0448\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0441\u0442\u043d\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u041e\u0421 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u044b.<\/p>\n<h2>Rand()<\/h2>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u0432 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 math\/rand \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u0435\u0441\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c <a href=\"https:\/\/blog.sgmansfield.com\/2016\/01\/the-hidden-dangers-of-default-rand\/\">\u0437\u0434\u0435\u0441\u044c<\/a>). \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Rand.New()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u0439 \u043e\u0431\u0435\u0440\u0442\u043a\u0438<\/p>\n<pre><code class=\"go\">rg := rand.New(rand.NewSource(int64(time.Now().Nanosecond())))<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0434\u043e\u0440\u043e\u0433\u043e. \u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435? \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e. \u041d\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e <code>Time.Nanoseconds()<\/code> \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u0434\u043e\u0439\u0442\u0438.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u043b\u0438 \u0432\u0441\u0435 \u043b\u0438\u0448\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/oq\/aw\/76\/oqaw76gy7k0jxwro9moeo8e374s.png\"><br \/>  <i>\u0430\u043d\u0430\u043b\u0438\u0437 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/i><\/p>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0432\u0441\u0435 \u0436\u0435 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0443\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/k4\/1y\/ky\/k41yky-okraevi6-huriop7-g2i.png\"><br \/>  <i>\u0433\u0440\u0430\u0444\u0438\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438<\/i><\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f <code>ccache<\/code> \u0441 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 <code>pprof<\/code>:<\/p>\n<pre><code class=\"go\">(pprof) list promote ROUTINE ======================== github.com\/karlseguin\/ccache.(*Cache).promote in ...         0   9.66days (flat, cum) 99.70% of Total         .          .    155: h.Write([]byte(key))         .          .    156: return c.buckets[h.Sum32()&amp;c.bucketMask]         .          .    157:}         .          .    158:         .          .    159:func (c *Cache) promote(item *Item) {         .   9.66days    160: c.promotables &lt;- item         .          .    161:}         .          .    162:         .          .    163:func (c *Cache) worker() {         .          .    164: defer close(c.donec)         .          .    165:<\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b <code>ccache.Get()<\/code> \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043d\u0430 \u043e\u0434\u0438\u043d \u043a\u0430\u043d\u0430\u043b <code>c.promotables<\/code>. \u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b; \u0423 <a href=\"https:\/\/github.com\/dgraph-io\/dgraph\">Dgraph<\/a> \u0435\u0441\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e <a href=\"https:\/\/blog.dgraph.io\/post\/caching-in-go\/\">\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u044d\u0448\u0430 \u0432 go<\/a>, \u0443 \u043d\u0438\u0445 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/github.com\/dgraph-io\/ristretto\">ristretto<\/a>. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, ristretto \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Ttl, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 <code>MaxCost<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u0439\u043c-\u0430\u0443\u0442\u0430 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043a\u044d\u0448\u0430 (\u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u044d\u0448\u0435). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 ristretto:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ho\/k2\/ay\/hok2ay6emv_agqfuv-y65sxkius.png\"><br \/>  <i>\u0430\u043d\u0430\u043b\u0438\u0437 \u0433\u043e\u0440\u0443\u0442\u0438\u043d<\/i><\/p>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e!<\/p>\n<p>  \u041d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0441 5000 \u043c\u0441 \u0434\u043e 22 \u043c\u0441. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u00ab\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438\u00bb \u0438 \u00ab\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430\u00bb. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441 \u044d\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/s3\/8u\/qh\/s38uqh-knc7gmandd1erhgelmrs.png\"><br \/>  <i>\u0433\u0440\u0430\u0444\u0438\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438<\/i><\/p>\n<p>  \u041c\u044b \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 <code>fdMutex.rwlock<\/code>, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c: gcMarkDone, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 53% \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u043b\u043e\u043a\u0430. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441\u0431\u043e\u0440\u0430 \u043c\u0443\u0441\u043e\u0440\u0430. \u0418\u0445 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u0435 \u0447\u0430\u0441\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u043c gc.<\/p>\n<h3>\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 <\/h3>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0431\u043e\u0440\u043a\u0430 \u043c\u0443\u0441\u043e\u0440\u0430; Go \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 mark-and-sweep \u0441\u0431\u043e\u0440\u0449\u0438\u043a. \u041e\u043d \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435, \u0447\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e, \u0438 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043d \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e (\u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e GOGC) \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0430 GC. \u041e\u0446\u0435\u043d\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0440\u0438 \u044d\u0442\u0430\u043f\u0430:<\/p>\n<ul>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u0430\u0440\u043a\u0435\u0440\u0430 (STW)<\/li>\n<li>\u041c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0430 (\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e)<\/li>\n<li>\u041e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0438 (STW)<\/li>\n<\/ul>\n<p>  \u0424\u0430\u0437\u044b \u00ab\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u0438\u0440\u00bb (Stop The World, STW) \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442 \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0445\u043e\u0442\u044f \u043e\u043d\u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435, \u0441\u043f\u043b\u043e\u0448\u043d\u044b\u0435 \u0446\u0438\u043a\u043b\u044b \u043c\u043e\u0433\u0443\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u042d\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f (go v1.13) \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u044b\u0442\u0435\u0441\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u0447\u043a\u0430\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0441\u043f\u043b\u043e\u0448\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0430\u0443\u0437\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 GC \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u0441\u0435\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<p>  \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0438 gc \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u043a\u043e\u043b\u043e 25% <code>GOMAXPROCS<\/code>, \u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 <b>mark assist<\/b>, \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f\u0441\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u043e\u043f\u0435\u0440\u0435\u0436\u0430\u0435\u0442 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0440\u043a\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u0443\u044e gc, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0447\u0438.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0434\u0432\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<ul>\n<li>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0447\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 1000 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u0437 20-\u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u043a\u0443\u0447\u0443, \u0447\u0435\u043c \u043e\u0434\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 20000 \u0431\u0430\u0439\u0442\u043e\u0432);<\/li>\n<li>\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0442\u0430\u043a\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u043a\u0430\u043a C\/C++, \u043d\u0435 \u0432\u0441\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0435. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 go \u0440\u0435\u0448\u0430\u0435\u0442, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0443\u0447\u0443 \u0438\u043b\u0438 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0440\u0435\u0439\u043c\u0430 \u0441\u0442\u0435\u043a\u0430. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c\u044b\u0445 \u0432 \u043a\u0443\u0447\u0435, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0435\u043a\u0435, \u043d\u0435 \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442 gc.<\/li>\n<\/ul>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 Go \u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b GC \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u044d\u0442\u0443 <a href=\"https:\/\/www.youtube.com\/watch?v=M0HER1G5BRw\">\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a>.<\/p>\n<p>  \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 go:<\/p>\n<ul>\n<li>\u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0433\u043e\u0440\u044f\u0447\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f;<\/li>\n<li>\u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439;<\/li>\n<li>\u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0434\u043b\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432; GC<\/li>\n<li>escape-\u0430\u043d\u0430\u043b\u0438\u0437, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u044f.<\/li>\n<\/ul>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430:<\/p>\n<pre><code class=\"go\">$ go tool pprof http:\/\/localhost:6060\/debug\/pprof\/profile?seconds=20 (pprof) top 20 -cum Showing nodes accounting for 7.27s, 29.10% of 24.98s total Dropped 315 nodes (cum &lt;= 0.12s) Showing top 20 nodes out of 201      flat  flat%   sum%        cum   cum%         0     0%     0%     16.42s 65.73%  github.com\/miekg\/dns.(*Server).serveUDPPacket     0.02s  0.08%  0.08%     16.02s 64.13%  github.com\/miekg\/dns.(*Server).serveDNS     0.02s  0.08%  0.16%     13.69s 54.80%  github.com\/miekg\/dns.(*ServeMux).ServeDNS     0.01s  0.04%   0.2%     13.48s 53.96%  github.com\/miekg\/dns.HandlerFunc.ServeDNS     0.02s  0.08%  0.28%     13.47s 53.92%  main.handleRequest     0.24s  0.96%  1.24%     12.50s 50.04%  arvancloud\/redins\/handler.(*DnsRequestHandler).HandleRequest     0.81s  3.24%  4.48%      6.91s 27.66%  runtime.gentraceback     3.82s 15.29% 19.78%      5.48s 21.94%  syscall.Syscall     0.02s  0.08% 19.86%      5.44s 21.78%  arvancloud\/redins\/handler.(*DnsRequestHandler).Response     0.06s  0.24% 20.10%      5.25s 21.02%  arvancloud\/redins\/handler.(*RequestContext).Response     0.03s  0.12% 20.22%      4.97s 19.90%  arvancloud\/redins\/handler.(*DnsRequestHandler).FindANAME     0.56s  2.24% 22.46%      4.92s 19.70%  runtime.mallocgc     0.07s  0.28% 22.74%      4.90s 19.62%  github.com\/miekg\/dns.(*response).WriteMsg     0.04s  0.16% 22.90%      4.40s 17.61%  github.com\/miekg\/dns.(*response).Write     0.01s  0.04% 22.94%      4.36s 17.45%  github.com\/miekg\/dns.WriteToSessionUDP     1.43s  5.72% 28.66%      4.30s 17.21%  runtime.pcvalue     0.01s  0.04% 28.70%      4.15s 16.61%  runtime.newstack     0.06s  0.24% 28.94%      4.09s 16.37%  runtime.copystack     0.01s  0.04% 28.98%      4.05s 16.21%  net.(*UDPConn).WriteMsgUDP     0.03s  0.12% 29.10%      4.04s 16.17%  net.(*UDPConn).writeMsg<\/code><\/pre>\n<p>  \u041d\u0430\u0441 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 <code>mallocgc<\/code>, \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043c\u043e\u0449\u044c \u0441 \u043c\u0435\u0442\u043a\u0430\u043c\u0438<\/p>\n<pre><code class=\"go\">(pprof) svg mallocgc<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/kz\/yw\/mb\/kzywmb1pzaiw3x2h4aprdtzvl9c.png\"><\/p>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 <code>alloc<\/code>, \u043e\u043f\u0446\u0438\u044f <code>alloc_object<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439, \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"go\">$ go tool pprof -alloc_objects http:\/\/localhost:6060\/debug\/pprof\/allocs (pprof) top -cum Active filters:   show=handler Showing nodes accounting for 58464353, 59.78% of 97803168 total Dropped 1 node (cum &lt;= 489015) Showing top 10 nodes out of 19      flat  flat%   sum%        cum   cum%  15401215 15.75% 15.75%   70279955 71.86%  arvancloud\/redins\/handler.(*DnsRequestHandler).HandleRequest   2392100  2.45% 18.19%   27198697 27.81%  arvancloud\/redins\/handler.(*DnsRequestHandler).FindANAME    711174  0.73% 18.92%   14936976 15.27%  arvancloud\/redins\/handler.(*DnsRequestHandler).Filter         0     0% 18.92%   14161410 14.48%  arvancloud\/redins\/handler.(*DnsRequestHandler).Response  14161410 14.48% 33.40%   14161410 14.48%  arvancloud\/redins\/handler.(*RequestContext).Response   7284487  7.45% 40.85%   11118401 11.37%  arvancloud\/redins\/handler.NewRequestContext  10439697 10.67% 51.52%   10439697 10.67%  arvancloud\/redins\/handler.reverseZone         0     0% 51.52%   10371430 10.60%  arvancloud\/redins\/handler.(*DnsRequestHandler).FindZone   2680723  2.74% 54.26%    8022046  8.20%  arvancloud\/redins\/handler.(*GeoIp).GetSameCountry   5393547  5.51% 59.78%    5393547  5.51%  arvancloud\/redins\/handler.(*DnsRequestHandler).LoadLocation<\/code><\/pre>\n<p>  \u0421 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c list \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c:<\/p>\n<p>  <b>printf-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/b><\/p>\n<pre><code class=\"go\">(pprof) list handleRequest Total: 97803168 ROUTINE ======================== main.handleRequest in \/home\/arash\/go\/src\/arvancloud\/redins\/redins.go   2555943   83954299 (flat, cum) 85.84% of Total         .          .     35: l          *handler.RateLimiter         .          .     36: configFile string         .          .     37:)         .          .     38:         .          .     39:func handleRequest(w dns.ResponseWriter, r *dns.Msg) {         .   11118401     40: context := handler.NewRequestContext(w, r)   2555943    2555943     41: logger.Default.Debugf(&quot;handle request: [%d] %s %s&quot;, r.Id, context.RawName(), context.Type())         .          .     42:         .          .     43: if l.CanHandle(context.IP()) {         .   70279955     44:  h.HandleRequest(context)         .          .     45: } else {         .          .     46:  context.Response(dns.RcodeRefused)         .          .     47: }         .          .     48:}         .          .     49:<\/code><\/pre>\n<p>  \u0421\u0442\u0440\u043e\u043a\u0430 41 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430, \u0434\u0430\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0430 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0442\u0430\u043c \u0432\u0441\u0435 \u0435\u0449\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c escape-\u0430\u043d\u0430\u043b\u0438\u0437, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435.<\/p>\n<p>  \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 Escape-\u0430\u043d\u0430\u043b\u0438\u0437\u0430 Go \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0444\u043b\u0430\u0433 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430<\/p>\n<pre><code class=\"go\">$ go build -gcflags '-m'<\/code><\/pre>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 -m \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438<\/p>\n<pre><code class=\"go\">$ go build -gcflags '-m '<\/code><\/pre>\n<p>  \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <a href=\"https:\/\/github.com\/loov\/view-annotated-file\">view-annotated-file<\/a>.<\/p>\n<pre><code class=\"go\">$ go build -gcflags '-m' . . . ..\/redins.go:39:20: leaking param: w .\/redins.go:39:42: leaking param: r .\/redins.go:41:55: r.MsgHdr.Id escapes to heap .\/redins.go:41:75: context.RawName() escapes to heap .\/redins.go:41:91: context.Request.Type() escapes to heap .\/redins.go:41:23: handleRequest []interface {} literal does not escape .\/redins.go:219:17: leaking param: path . . .<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>Debugf<\/code> \u0443\u0445\u043e\u0434\u044f\u0442 \u0432 \u043a\u0443\u0447\u0443. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437-\u0437\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <code>Debugf<\/code>:<\/p>\n<pre><code class=\"go\">func (l *EventLogger) Debugf(format string, args ...interface{})<\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>args<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0442\u0438\u043f <code>interface{}<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0443. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0438\u0431\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0436\u0443\u0440\u043d\u0430\u043b\u044b \u043e\u0442\u043b\u0430\u0434\u043a\u0438, \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0436\u0443\u0440\u043d\u0430\u043b\u043e\u0432 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/rs\/zerolog\">zerolog<\/a>.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 escape- \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0441\u043c. <a href=\"https:\/\/segment.com\/blog\/allocation-efficiency-in-high-performance-go-services\/\">\u00aballocation eficiency in golang\u00bb<\/a>.<\/p>\n<p>  <b>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438<\/b><\/p>\n<pre><code class=\"go\">(pprof) list reverseZone Total: 100817064 ROUTINE ======================== arvancloud\/redins\/handler.reverseZone in \/home\/arash\/go\/src\/arvancloud\/redins\/handler\/handler.go   6127746   10379086 (flat, cum) 10.29% of Total         .          .    396:  logger.Default.Warning(&quot;log queue is full&quot;)         .          .    397: }         .          .    398:}         .          .    399:         .          .    400:func reverseZone(zone string) string {         .    4251340    401: x := strings.Split(zone, &quot;.&quot;)         .          .    402: var y string         .          .    403: for i := len(x) - 1; i &gt;= 0; i-- {   6127746    6127746    404:  y += x[i] + &quot;.&quot;         .          .    405: }         .          .    406: return y         .          .    407:}         .          .    408:         .          .    409:func (h *DnsRequestHandler) LoadZones() { (pprof)<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 Go \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0439, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Go 1.10, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>strings.Builder<\/code> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<pre><code class=\"go\">(pprof) list reverseZone Total: 93437002 ROUTINE ======================== arvancloud\/redins\/handler.reverseZone in \/home\/arash\/go\/src\/arvancloud\/redins\/handler\/handler.go         0    7580611 (flat, cum)  8.11% of Total         .          .    396:  logger.Default.Warning(&quot;log queue is full&quot;)         .          .    397: }         .          .    398:}         .          .    399:         .          .    400:func reverseZone(zone string) string {         .    3681140    401: x := strings.Split(zone, &quot;.&quot;)         .          .    402: var sb strings.Builder         .    3899471    403: sb.Grow(len(zone)+1)         .          .    404: for i := len(x) - 1; i &gt;= 0; i-- {         .          .    405:  sb.WriteString(x[i])         .          .    406:  sb.WriteByte('.')         .          .    407: }         .          .    408: return sb.String()<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0441 \u043d\u0435 \u0432\u043e\u043b\u043d\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c <code>Split()<\/code>, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0432 \u0432\u0441\u044e \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<pre><code class=\"go\">(pprof) list reverseZone Total: 89094296 ROUTINE ======================== arvancloud\/redins\/handler.reverseZone in \/home\/arash\/go\/src\/arvancloud\/redins\/handler\/handler.go   3801168    3801168 (flat, cum)  4.27% of Total         .          .    400:func reverseZone(zone string) []byte {         .          .    401: runes := []rune(&quot;.&quot; + zone)         .          .    402: for i, j := 0, len(runes)-1; i &lt; j; i, j = i+1, j-1 {         .          .    403:  runes[i], runes[j] = runes[j], runes[i]         .          .    404: }   3801168    3801168    405: return []byte(string(runes))         .          .    406:}         .          .    407:         .          .    408:func (h *DnsRequestHandler) LoadZones() {         .          .    409: h.LastZoneUpdate = time.Now()         .          .    410: zones, err := h.Redis.SMembers(&quot;redins:zones&quot;)<\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/go101.org\/article\/string.html\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>sync.Pool<\/h3>\n<p>  <\/p>\n<pre><code class=\"go\">(pprof) list GetASN Total: 69005282 ROUTINE ======================== arvancloud\/redins\/handler.(*GeoIp).GetASN in \/home\/arash\/go\/src\/arvancloud\/redins\/handler\/geoip.go   1146897    1146897 (flat, cum)  1.66% of Total         .          .    231:func (g *GeoIp) GetASN(ip net.IP) (uint, error) {   1146897    1146897    232: var record struct {         .          .    233:  AutonomousSystemNumber uint `maxminddb:&quot;autonomous_system_number&quot;`         .          .    234: }         .          .    235: err := g.ASNDB.Lookup(ip, &amp;record)         .          .    236: if err != nil {         .          .    237:  logger.Default.Errorf(&quot;lookup failed : %s&quot;, err) (pprof) list GetGeoLocation Total: 69005282 ROUTINE ======================== arvancloud\/redins\/handler.(*GeoIp).GetGeoLocation in \/home\/arash\/go\/src\/arvancloud\/redins\/handler\/geoip.go   1376298    3604572 (flat, cum)  5.22% of Total         .          .    207:         .          .    208:func (g *GeoIp) GetGeoLocation(ip net.IP) (latitude float64, longitude float64, country string, err error) {         .          .    209: if !g.Enable || g.CountryDB == nil {         .          .    210:  return         .          .    211: }   1376298    1376298    212: var record struct {         .          .    213:  Location struct {         .          .    214:   Latitude        float64 `maxminddb:&quot;latitude&quot;`         .          .    215:   LongitudeOffset uintptr `maxminddb:&quot;longitude&quot;`         .          .    216:  } `maxminddb:&quot;location&quot;`         .          .    217:  Country struct {         .          .    218:   ISOCode string `maxminddb:&quot;iso_code&quot;`         .          .    219:  } `maxminddb:&quot;country&quot;`         .          .    220: }         .          .    221: \/\/ logger.Default.Debugf(&quot;ip : %s&quot;, ip)         .          .    222: if err := g.CountryDB.Lookup(ip, &amp;record); err != nil {         .          .    223:  logger.Default.Errorf(&quot;lookup failed : %s&quot;, err)         .          .    224:  return 0, 0, &quot;&quot;, err         .          .    225: }         .    2228274    226: _ = g.CountryDB.Decode(record.Location.LongitudeOffset, &amp;longitude)         .          .    227: \/\/ logger.Default.Debug(&quot;lat = &quot;, record.Location.Latitude, &quot; lang = &quot;, longitude, &quot; country = &quot;, record.Country.ISOCode)         .          .    228: return record.Location.Latitude, longitude, record.Country.ISOCode, nil         .          .    229:}         .          .    230:         .          .    231:func (g *GeoIp) GetASN(ip net.IP) (uint, error) {<\/code><\/pre>\n<p>  \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"http:\/\/github.com\/oschwald\/maxminddb-golang\">maxmiddb<\/a> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0433\u0435\u043e\u043b\u043e\u043a\u0430\u0446\u0438\u0438. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 <code>interface{}<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0431\u0435\u0433\u0438 \u043a\u0443\u0447\u0438.<\/p>\n<p>  \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>sync.Pool<\/code> \u0434\u043b\u044f \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445, \u043d\u043e \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"go\">type MMDBGeoLocation struct {   Coordinations struct {      Latitude        float64 `maxminddb:&quot;latitude&quot;`      Longitude       float64      LongitudeOffset uintptr `maxminddb:&quot;longitude&quot;`   } `maxminddb:&quot;location&quot;`   Country struct {      ISOCode string `maxminddb:&quot;iso_code&quot;`   } `maxminddb:&quot;country&quot;` }  type MMDBASN struct {   AutonomousSystemNumber uint `maxminddb:&quot;autonomous_system_number&quot;` } func (g *GeoIp) GetGeoLocation(ip net.IP) (*MMDBGeoLocation, error) {   if !g.Enable || g.CountryDB == nil {      return nil, EMMDBNotAvailable   }   var record *MMDBGeoLocation = g.LocationPool.Get().(*MMDBGeoLocation)   logger.Default.Debugf(&quot;ip : %s&quot;, ip)   if err := g.CountryDB.Lookup(ip, &amp;record); err != nil {      logger.Default.Errorf(&quot;lookup failed : %s&quot;, err)      return nil, err   }   _ = g.CountryDB.Decode(record.Coordinations.LongitudeOffset, &amp;record.Coordinations.Longitude)   logger.Default.Debug(&quot;lat = &quot;, record.Coordinations.Latitude, &quot; lang = &quot;, record.Coordinations.Longitude, &quot; country = &quot;, record.Country.ISOCode)   return record, nil }  func (g *GeoIp) GetASN(ip net.IP) (uint, error) {   var record *MMDBASN = g.AsnPool.Get().(*MMDBASN)   err := g.ASNDB.Lookup(ip, record)   if err != nil {      logger.Default.Errorf(&quot;lookup failed : %s&quot;, err)      return 0, err   }   logger.Default.Debug(&quot;asn = &quot;, record.AutonomousSystemNumber)   return record.AutonomousSystemNumber, nil }<\/code><\/pre>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0435 \u043e sync.Pool <a href=\"https:\/\/medium.com\/a-journey-with-go\/go-understand-the-design-of-sync-pool-2dde3024e277\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439, \u043d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043c\u044b \u0443\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/segment.com\/blog\/allocation-efficiency-in-high-performance-go-services\/\">Allocation efficiency in high-performance Go services<\/a>.<\/p>\n<h3>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h3>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 <code>go tool trace<\/code> \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u00abMinimum Mutator Utilization\u00bb, \u0437\u0434\u0435\u0441\u044c Mutator \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043d\u0435 gc.<\/p>\n<p>  \u0414\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/k5\/og\/yd\/k5ogydpov-6tpkxmulro0f8tkic.png\"><\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u043a\u043d\u043e \u043e\u043a\u043e\u043b\u043e 500 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434 \u0431\u0435\u0437 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f (gc \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b), \u0438 \u043c\u044b \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c 80% \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0434\u043e\u043b\u0433\u043e\u0441\u0440\u043e\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u0435. \u041c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043a\u043d\u043e \u043d\u0443\u043b\u0435\u0432\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u044b\u043b\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435, \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0442\u044c 100% \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<p>  \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/6e\/bt\/5k\/6ebt5k70pm7ufao23uln7b5dcgq.png\"><\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434<\/h3>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 go \u043d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430\u0448 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 <a href=\"https:\/\/github.com\/hawell\/redins\">GitHub<\/a>. <a href=\"https:\/\/github.com\/hawell\/redins\/tree\/e35a797e51b7a9e27683d2cde1fbd80f6381f89e\">\u0412\u043e\u0442<\/a> \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0438 <a href=\"https:\/\/github.com\/hawell\/redins\/tree\/17682bfca4b5eb2469db342fa2512f335dee15a8\">\u0432\u043e\u0442 <\/a>\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f.<\/p>\n<h3>\u0422\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e<\/h3>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/dgryski\/go-perfbook\">go perfbook<\/a><\/li>\n<li><a href=\"https:\/\/golang.org\/doc\/effective_go.html\">effective go<\/a><\/li>\n<li><a href=\"https:\/\/bravenewgeek.com\/so-you-wanna-go-fast\/\">so you wanna go fast<\/a><\/li>\n<li><a href=\"https:\/\/go-talks.appspot.com\/github.com\/davecheney\/presentations\/writing-high-performance-go.slide\">writing high performace go<\/a><\/li>\n<\/ul>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u0414\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0438 \u043d\u0430 <a href=\"https:\/\/otus.pw\/MA66\/\">\u043a\u0443\u0440\u0441\u0435<\/a>!<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/487934\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/487934\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/487934\/\"><i>\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u043e \u043a\u0443\u0440\u0441\u0443 <a href=\"https:\/\/otus.pw\/MA66\/\">\u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a Golang\u00bb<\/a> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430.<\/i><\/p>\n<hr>\n<p>  \u041d\u0430\u0448 <a href=\"https:\/\/github.com\/hawell\/redins\">\u0430\u0432\u0442\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u0439 DNS-\u0441\u0435\u0440\u0432\u0435\u0440<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0442\u044b\u0441\u044f\u0447 \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u043e\u0432. \u041c\u044b \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u043c \u043d\u0430 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412 \u043d\u0430\u0448\u0438 \u0434\u043d\u0438 DNS-\u0430\u0442\u0430\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0431\u043e\u043b\u0435\u0435 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c\u0438, DNS \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u0434 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439.<\/p>\n<p>  <a href=\"https:\/\/github.com\/nickwinn\/dns-flood\">dnsflood<\/a> \u2014 \u044d\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e udp \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<pre><code class=\"go\"># timeout 20s .\/dnsflood example.com 127.0.0.1 -p 2053<\/code><\/pre>\n<p>  \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0438\u0441\u0442\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0448\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0440\u043e\u0441\u043b\u043e \u0442\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0435\u0433\u043e, \u0438\u043d\u0430\u0447\u0435 \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0431\u044b \u0441 OOM \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0443\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438; \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u00ab\u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u043d\u0430\u00bb \u0438 \u00ab\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445\u00bb \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 go:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-298525","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=298525"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298525\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}