{"id":313690,"date":"2020-11-24T15:01:04","date_gmt":"2020-11-24T15:01:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=313690"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=313690","title":{"rendered":"\u0420\u0430\u0441\u0447\u0435\u0442 \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u0435\u0439 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/c-\/av\/1i\/c-av1iofjw6bnz3aunda0p-noya.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0433\u043e\u0440\u044c, \u0438 \u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0430 Tarantool \u0432 Mail.ru Group. \u042f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043d\u0430\u0434 \u0432\u0438\u0442\u0440\u0438\u043d\u0430\u043c\u0438 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0430 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u041c\u0435\u0433\u0430\u0444\u043e\u043d\u0430. \u041f\u0440\u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u0447\u0430\u0441\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u0438. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u00f3\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u044e \u0432\u044b\u0431\u0440\u043e\u0441\u043e\u0432. \u0415\u0441\u043b\u0438 9 \u0438\u0437 10 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u0430 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u0430 \u043e\u0434\u0438\u043d \u0437\u0430 10 \u0441\u0435\u043a\u0443\u043d\u0434, \u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 1,9 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0430 50-\u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c \u2014 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0430. \u042d\u0442\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 <a href=\"https:\/\/github.com\/tarantool\/metrics\">tarantool\/metrics<\/a> Summary-\u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c <a href=\"https:\/\/prometheus.io\/docs\/concepts\/metric_types\/#summary\">Summary-\u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440\u0430<\/a> \u2014 \u0440\u0430\u0441\u0447\u0435\u0442 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u0435\u0439 \u0434\u043b\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u043b\u044f \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u0435\u0439, \u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u044b \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b\u0438 \u0434\u043b\u044f tarantool\/metrics.<\/p>\n<p>  <\/p>\n<h2 id=\"summary-kollektor\">Summary-\u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440<\/h2>\n<p>  <\/p>\n<h3 id=\"algoritm\">\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h3>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/63e\/da8\/03c\/63eda803ce3c511b570836fcbe8ea9ab.svg\" alt=\"$\\phi$\" data-tex=\"inline\"><\/math>-\u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044c \u2014 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0441 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/63e\/da8\/03c\/63eda803ce3c511b570836fcbe8ea9ab.svg\" alt=\"$\\phi$\" data-tex=\"inline\"><\/math>. \u041f\u0440\u0438\u043c\u0435\u0440: 0,5-\u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044c (\u043e\u043d\u0430 \u0436\u0435 50-\u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c), \u0440\u0430\u0432\u043d\u0430\u044f 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0435, \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0433\u0430 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e 50% \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u044b\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0443. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/63e\/da8\/03c\/63eda803ce3c511b570836fcbe8ea9ab.svg\" alt=\"$\\phi$\" data-tex=\"inline\"><\/math> \u0434\u043b\u044f \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0437\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/cce\/663\/4bb\/cce6634bb5d8adbcc174d0b70d11a630.svg\" alt=\"$\\phi \\times n$\" data-tex=\"inline\"><\/math>. \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0432 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u0445 \u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e. \u0415\u0441\u043b\u0438 \u0431\u044b\u043b 1 \u043c\u043b\u0440\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 1 \u043c\u043b\u0440\u0434 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u2014 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 1 \u0413\u0431 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u0435\u0439 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u0432\u0437\u044f\u043b\u0438 <a href=\"https:\/\/ieeexplore.ieee.org\/document\/1410103\">\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Prometheus. \u041e\u043d \u00ab\u0441\u0436\u0438\u043c\u0430\u0435\u0442\u00bb \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0440\u0435\u0437\u043a\u0438 \u0438\u0437 \u0442\u0440\u0435\u0445 \u0447\u0438\u0441\u0435\u043b: \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043e\u0442\u0440\u0435\u0437\u043a\u0430 \u0434\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math>, \u0434\u043b\u0438\u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043e\u0442\u0440\u0435\u0437\u043a\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/38c\/ba4\/3f4\/38cba43f4c2a17e0c00e99dd21a0b811.svg\" alt=\"$\\Delta$\" data-tex=\"inline\"><\/math> \u0438 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u0438 \u043d\u0430 \u044d\u0442\u043e\u043c \u043e\u0442\u0440\u0435\u0437\u043a\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1c1\/778\/187\/1c1778187263268cc347012d16da61e2.svg\" alt=\"$v$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f04\/8c1\/157\/f048c115774c89791c0f8aec473cc45c.png\"><\/p>\n<p>  <\/p>\n<p>\u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u044b \u0437\u0435\u043b\u0435\u043d\u044b\u043c, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u00ab\u0441\u0436\u0430\u0442\u043e\u0433\u043e\u00bb \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u2014 \u043a\u0440\u0430\u0441\u043d\u044b\u043c. \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044c \u043d\u0430 \u0441\u0436\u0430\u0442\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0432\u0441\u0435\u043c \u043e\u0442\u0440\u0435\u0437\u043a\u0430\u043c, \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0438 \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/cce\/663\/4bb\/cce6634bb5d8adbcc174d0b70d11a630.svg\" alt=\"$\\phi \\times n$\" data-tex=\"inline\"><\/math>. \u0422\u043e\u0433\u0434\u0430 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 0,5-\u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0437\u0435\u043b\u0435\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0430 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u043a\u0440\u0430\u0441\u043d\u043e\u043c\u0443 \u043e\u0442\u0440\u0435\u0437\u043a\u0443.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"realizaciya\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u041c\u044b \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/bmizerany\/perks\/tree\/master\/quantile\">\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430 Go<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0432\u0435\u0434\u0435\u043c \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043e\u0434\u0438\u043d \u2014 \u0431\u0443\u0444\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u043b\u044f \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">typedef struct {int Delta, Width; double Value; } sample;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 500 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043a\u0430\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/cb4\/a1d\/e0c\/cb4a1de0c3dbc3bf2c7bfc70f20b9c73.svg\" alt=\"$2 \\times 500 + 2$\" data-tex=\"inline\"><\/math> \u2014 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0436\u0430\u0442\u0438\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443, \u0442\u0430\u043a \u0447\u0442\u043e \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f: 500 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435\u0441\u0436\u0430\u0442\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0448\u0430\u0433\u0430 + 500 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435 + 2 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b0b\/232\/f34\/b0b232f343595119559cf1186dd5f4a7.svg\" alt=\"$+\\infty$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d6d\/1e2\/ab7\/d6d1e2ab791a06785be738fe3a3a4f9d.svg\" alt=\"$-\\infty$\" data-tex=\"inline\"><\/math> \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435. <\/p>\n<p>  <\/p>\n<h3 id=\"hod-razrabotki\">\u0425\u043e\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/h3>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e: \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0441 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u043d\u0430 Go; \u0434\u0443\u043c\u0430\u0435\u043c, \u043a\u0430\u043a \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c. \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u043c: \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u043a\u0443 10<sup>8<\/sup> \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432, \u0434\u043b\u044f \u0433\u043e\u0448\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044d\u0442\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 8 \u0441. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435:<\/p>\n<p>  <\/p>\n<p>1) <strong>pure-Lua \u0432\u0435\u0440\u0441\u0438\u044f<\/strong> \u2014 \u043e\u0447\u0435\u043d\u044c \u043f\u043b\u043e\u0445\u043e, \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043e\u043a\u043e\u043b\u043e 100 \u0441.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0435 \u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/50f\/217\/349\/50f217349687530ac2b1a98765cad015.png\"><\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043f\u0440\u043e\u0441\u0435\u0434\u0430\u0435\u0442 \u043d\u0430 \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 (\u0432\u044b\u0437\u043e\u0432 <code>table.insert<\/code>) \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435 \u0431\u0443\u0444\u0435\u0440\u0430 (<code>table.sort<\/code>). \u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <a href=\"https:\/\/luajit.org\/ext_ffi.html\">ffi<\/a>, \u0438\u043b\u0438 foreign function interface. Ffi \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 C, \u0430 \u043f\u043e\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u0432 Lua, \u043a\u0430\u043a \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 Lua-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 (\u043d\u0443, \u043f\u043e\u0447\u0442\u0438; \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 Lua \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 1, \u0430 \u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0421, \u0432\u0441\u0451 \u0435\u0449\u0435 \u0441 0).<\/p>\n<p>  <\/p>\n<p>2) <strong>Lua + ffi<\/strong> \u2014 \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 double:<\/p>\n<p>  <\/p>\n<pre><code class=\"lua\">local ffi = require('ffi') \u2026 array = ffi.new('double[?]', max_samples) for i = 0, max_samples - 1 do     array[i] = math.huge end<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0443\u0434\u0435\u043c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0421:<\/p>\n<p>  <\/p>\n<pre><code class=\"lua\">ffi.cdef[[<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"cpp\">    void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*));     int cmpfunc (const void * a, const void * b);<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"lua\">]]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044e-\u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f <code>double<\/code> \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u0421 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u0430\u043a \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041f\u0438\u0448\u0435\u043c \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">int cmpfunc (const void * a, const void * b) {     if (*(double*)a &gt; *(double*)b)         return 1;     else if (*(double*)a &lt; *(double*)b)         return -1;     else         return 0; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0435\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">gcc -c -o metrics\/quantile.o metrics\/quantile.c gcc -shared -o metrics\/libquantile.so metrics\/quantile.o<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 Lua-\u043a\u043e\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"lua\">local dlib_path = package.search('libquantile', package.cpath) local dlib = ffi.load(dlib_path)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 <code>double<\/code> \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"lua\">local DOUBLE_SIZE = ffi.sizeof('double') ffi.C.qsort(array, len, DOUBLE_SIZE, dlib.cmpfunc)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0432 3 \u0440\u0430\u0437\u0430, \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u0434\u043e 30 \u0441. \u041f\u0440\u043e\u0441\u0435\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 Lua \u043d\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439, \u0442\u0438\u043f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u043e\u0436\u0435 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0433\u0438\u0431\u0447\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438, \u043d\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e Lua-\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/493642\/\">\u0437\u0434\u0435\u0441\u044c<\/a>). Ffi \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 Lua-\u0442\u0430\u0431\u043b\u0438\u0446 \u043a \u0421-\u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c \u0441 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/655\/b80\/5d6\/655b805d68b4b00a4e90f64eefbc6f1c.svg\" alt=\"$O(1)$\" data-tex=\"inline\"><\/math> \u0432\u043c\u0435\u0441\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/214\/875\/38a\/21487538a6dbcc06fa5704effedb4282.svg\" alt=\"$O(\\log n)$\" data-tex=\"inline\"><\/math>. \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0442\u043e\u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041d\u043e \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 gcc, \u0447\u0442\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 C-\u043a\u043e\u0434\u0430. <\/p>\n<p>  <\/p>\n<p>3) <strong>Lua + ffi + \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430<\/strong> \u2014 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430 Lua \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0430 \u043f\u0430\u0440\u0443 \u0441\u0435\u043a\u0443\u043d\u0434 \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0441\u0438\u0448\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c gcc \u043d\u0430\u0441 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u043b\u043e, \u0438 \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u043c.<\/p>\n<p>  <\/p>\n<h3 id=\"rashod-pamyati\">\u0420\u0430\u0441\u0445\u043e\u0434 \u043f\u0430\u043c\u044f\u0442\u0438<\/h3>\n<p>  <\/p>\n<p><code>metrics.quantile<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0411\u0443\u0444\u0435\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c <code>max_samples * sizeof(double)<\/code> = <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b4a\/704\/f40\/b4a704f400f80078a4a82f41c99a7ea7.svg\" alt=\"$500 \\times 8$\" data-tex=\"inline\"><\/math> \u0431\u0430\u0439\u0442.<\/li>\n<li>\u041c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c <code>(2 * max_samples + 2) * sizeof(struct sample)<\/code> = <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b03\/4fe\/53d\/b034fe53d796b1c94404fc23e46568c8.svg\" alt=\"$1002 \\times 16$\" data-tex=\"inline\"><\/math> \u0431\u0430\u0439\u0442. \u0420\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432.<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"vliyanie-na-proizvoditelnost\">\u0412\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u043b\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <strong>\u042f\u043d\u0434\u0435\u043a\u0441.\u0422\u0430\u043d\u043a\u043e\u043c<\/strong> (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 <a href=\"https:\/\/habr.com\/ru\/post\/517488\/\">\u0437\u0434\u0435\u0441\u044c<\/a>). \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b9a\/16f\/6fd\/b9a16f6fd9a2b68aee14b85cc3678a24.jpg\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Summary-\u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440\u0430:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/34d\/882\/ac7\/34d882ac7f78e678577fd9b7db01902c.jpg\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0441\u0435\u043b\u043e \u043d\u0430 ~10%, \u044d\u0442\u043e \u0442\u0430 \u0446\u0435\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0437\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0441\u0438\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0441\u0430\u0434\u043a\u0438, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043c\u0435\u0440\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<h3 id=\"ispolzovanie\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<pre><code class=\"bash\">tarantoolctl rocks install metrics 0.5.0<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"lua\">local metrics = require('metrics') -- \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043c\u0435\u0442\u0440\u0438\u043a\u0438  -- \u0421\u043e\u0437\u0434\u0430\u0435\u043c summary \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440 local http_requests_latency = metrics.summary(     'http_requests_latency', 'HTTP requests latency',     {[0.5]=0.01, [0.9]=0.01, [0.99]=0.01} )  -- \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435: local latency = math.random(1, 10) http_requests_latency:observe(latency)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0432 JSON, Prometheus \u0438 Graphite. \u0412\u043e\u0442 \u0442\u0430\u043a \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 Grafana: <\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1fe\/264\/8fb\/1fe2648fb8153dddae6c8b3ebf2260e7.png\"><\/p>\n<p>  <\/p>\n<h2 id=\"itogi\">\u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>  <\/p>\n<p>\u041c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 Summary-\u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f tarantool\/metrics. \u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0435\u0448\u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ffi. \u041d\u043e\u0432\u044b\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0432\u0435\u043b\u0438\u0447\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u044f\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. Summary \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u0445 \u043d\u0430 Tarantool, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043a\u043b\u0438\u043a\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0432\u044b\u0441\u043e\u043a\u043e\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0433\u0434\u0435 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043a \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0431\u044a\u0435\u043c\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u0437\u0430 \u044d\u0442\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u043e\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0443.<\/p>\n<p>  <\/p>\n<h2 id=\"ssylki\">\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li>\u0421\u043a\u0430\u0447\u0430\u0442\u044c Tarantool \u043c\u043e\u0436\u043d\u043e \u043d\u0430 <a href=\"https:\/\/www.tarantool.io\/ru\/download?utm_source=habr&amp;utm_medium=articles&amp;utm_campaign=2020\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435<\/a><\/li>\n<li>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u043c\u043e\u0449\u044c \u043c\u043e\u0436\u043d\u043e \u0432 <a href=\"https:\/\/t.me\/tarantoolru?utm_source=habr&amp;utm_medium=articles&amp;utm_campaign=2020\">Telegram-\u0447\u0430\u0442\u0435<\/a>.<\/li>\n<li><a href=\"https:\/\/www.tarantool.io\/ru\/doc\/latest\/book\/monitoring\/\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f tarantool\/metrics<\/a><\/li>\n<li><a href=\"https:\/\/prometheus.io\/docs\/concepts\/metric_types\/#summary\">Summary-\u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Prometheus<\/a><\/li>\n<li><a href=\"https:\/\/ieeexplore.ieee.org\/document\/1410103\">\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u043a\u0432\u0430\u043d\u0442\u0438\u043b\u0435\u0439<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/517488\/\">\u041d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 Tarantool<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/493642\/\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e Lua-\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445<\/a><\/li>\n<\/ul>\n<\/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\/mailru\/blog\/529456\/\"> https:\/\/habr.com\/ru\/company\/mailru\/blog\/529456\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/c-\/av\/1i\/c-av1iofjw6bnz3aunda0p-noya.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0433\u043e\u0440\u044c, \u0438 \u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0430 Tarantool \u0432 Mail.ru Group. \u042f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043d\u0430\u0434 \u0432\u0438\u0442\u0440\u0438\u043d\u0430\u043c\u0438 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u0430 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u041c\u0435\u0433\u0430\u0444\u043e\u043d\u0430. \u041f\u0440\u0438 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u0447\u0430\u0441\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u0438. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u00f3\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u044e \u0432\u044b\u0431\u0440\u043e\u0441\u043e\u0432. \u0415\u0441\u043b\u0438 9 \u0438\u0437 10 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u0430 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u0430 \u043e\u0434\u0438\u043d \u0437\u0430 10 \u0441\u0435\u043a\u0443\u043d\u0434, \u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 1,9 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0430 50-\u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c \u2014 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0430. \u042d\u0442\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430. \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 <a href=\"https:\/\/github.com\/tarantool\/metrics\">tarantool\/metrics<\/a> Summary-\u043a\u043e\u043b\u043b\u0435\u043a\u0442\u043e\u0440.<\/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-313690","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313690","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=313690"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313690\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}