{"id":337749,"date":"2022-09-01T03:00:18","date_gmt":"2022-09-01T03:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=337749"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=337749","title":{"rendered":"<span>\u0421\u0440\u0435\u0434\u043d\u0438\u0435 highload \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043d\u0430 Go<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u0433\u0430\u0434\u0436\u0430\u043d\u044f\u043d \u0414\u0430\u0432\u0438\u0434 \u0438 \u0440\u0430\u043d\u0435\u0435 \u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/post\/682618\/\" rel=\"noopener noreferrer nofollow\">\u00ab\u043f\u0440\u043e\u0441\u0442\u044b\u0435 highload \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043d\u0430 Go\u00bb<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0445\u0430\u0440\u0434\u043a\u043e\u0440\u0430. \u041c\u043d\u0435 \u0438\u043c\u043f\u043e\u043d\u0438\u0440\u0443\u044e\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0442\u0430\u043a \u043a\u0430\u043a <strong>over engineering<\/strong> \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u0438 \u0442\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u044b\u0445 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u0432\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438 <strong>\u043b\u0443\u0447\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438<\/strong>. \u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438. \u041f\u043e\u0434\u0445\u043e\u0434\u044b \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b, \u043f\u0440\u0438\u043f\u0438\u0441\u043a\u0430 \u044f\u0437\u044b\u043a\u0430 <strong>Go<\/strong> \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043d\u0435\u043c. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u044b, \u0430 \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0437\u0430\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0432\u0437\u044f\u0442\u044c \u043d\u0430 \u0437\u0430\u043c\u0435\u0442\u043a\u0443.<\/p>\n<blockquote>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043c\u0435\u0440 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0443\u043a\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u0443 \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u043d\u044b\u0435 \u0441 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432<\/p>\n<\/blockquote>\n<h2>Stateless horizontal scaling<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/362\/86c\/3c4\/36286c3c49dd4cee5bf97c58f3a6dd25.png\" alt=\"one instance\" title=\"one instance\" width=\"1764\" height=\"695\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/362\/86c\/3c4\/36286c3c49dd4cee5bf97c58f3a6dd25.png\"\/><figcaption>one instance<\/figcaption><\/figure>\n<p>\u0415\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0432 \u0431\u043e\u044e \u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u041f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0442\u0440\u0430\u0444\u0438\u043a \u0440\u0430\u0441\u0442\u0435\u0442, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435\u043d\u0430\u0441\u044b\u0442\u043d\u0435\u0435 \u0438 \u0432\u0441\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u0418 \u0432\u043e\u0442 \u043d\u0430\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u043f\u0438\u043a, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <strong>CPU\/RAM<\/strong> \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0436\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u043c\u0435\u0440\u044b. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u043e\u0447\u0435\u043d\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 &#8212; \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 <strong>CPU<\/strong> \u0440\u0430\u0441\u0447\u0435\u0442\u044b. \u0422\u0440\u0430\u0444\u0438\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0442\u0435\u0442, <strong>CPU<\/strong> \u0436\u0435\u043b\u0435\u0437\u043a\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043f\u0440\u0435\u0434\u0435\u043b\u0443, \u0430 \u0441\u0430\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0442\u0430\u043a \u0443\u0436\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u0432\u0430\u0442\u0438\u043b\u043e \u043a\u043e\u043c\u043f\u0435\u0442\u0435\u043d\u0446\u0438\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0420\u0430\u0441\u0442\u0438 \u0438 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0434\u043e\u0440\u043e\u0433\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u043e\u0431\u043e\u0440\u0443\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0436\u0435 \u043d\u0435 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e<\/p>\n<p><strong>\u041a\u043e\u043d\u0446\u0435\u043f\u0442<\/strong>: \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0436\u0435\u043b\u0435\u0437\u043e\u043a \u0438 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c\u0438 <strong>load balancer<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/534\/b57\/320\/534b57320207a1516ced1e2dc1dafd0a.png\" alt=\"multiple instances with load balancer\" title=\"multiple instances with load balancer\" width=\"2141\" height=\"1546\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/534\/b57\/320\/534b57320207a1516ced1e2dc1dafd0a.png\"\/><figcaption>multiple instances with load balancer<\/figcaption><\/figure>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>: \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u043d\u0438\u0436\u0435, \u043d\u043e \u043e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 <a href=\"https:\/\/github.com\/agadzhanyan\/highload-patterns\/tree\/main\/scale-stateless\" rel=\"noopener noreferrer nofollow\">github<\/a><\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u0437\u0430\u0442\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0441 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c\u0438<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0436\u0435\u043b\u0435\u0437\u043a\u0438 \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c <a href=\"https:\/\/www.docker.com\/\" rel=\"noopener noreferrer nofollow\">docker<\/a> \u0438 <a href=\"https:\/\/docs.docker.com\/compose\/\" rel=\"noopener noreferrer nofollow\">docker-compose<\/a><\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e <strong>CPU<\/strong> \u0432 <strong>docker-compose <\/strong>\u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 <a href=\"https:\/\/docs.docker.com\/compose\/compose-file\/compose-file-v2\/#cpu-and-other-resources\" rel=\"noopener noreferrer nofollow\">&#171;2.2&#187;<\/a>. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/docs.docker.com\/compose\/compose-file\/compose-file-v3\/#resources\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439<\/a> \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<pre><code class=\"yaml\">version: \"3.9\" services:   redis:     image: redis:alpine     deploy:       resources:         limits:           cpus: '0.50' &lt;- \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e           memory: 50M         reservations:           cpus: '0.25'           memory: 20M<\/code><\/pre>\n<blockquote>\n<p>In this general example, the\u00a0<code>redis<\/code>\u00a0service is constrained to use no more than 50M of memory and\u00a0<code>0.50<\/code>\u00a0(50% of a single core) of available processing time (CPU), and has\u00a0<code>20M<\/code>\u00a0of memory and\u00a0<code>0.25<\/code>\u00a0CPU time reserved (as always available to it).<\/p>\n<\/blockquote>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e <strong>0.5 <\/strong>\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 <strong>50%<\/strong> \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u044f\u0434\u0440\u0430. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <strong>20%<\/strong><\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 <strong>Go<\/strong>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c <strong>Dockerfile<\/strong>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440<\/p>\n<pre><code class=\"powershell\"># \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0441\u0432\u0435\u0436\u0438\u0445 \u043e\u0431\u0440\u0430\u0437\u043e\u0432 Go FROM golang:1.19.0-alpine3.16  # alpine \u043e\u0431\u0440\u0430\u0437 \u0431\u0435\u0434\u0435\u043d \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 RUN apk update &amp;&amp; apk upgrade &amp;&amp; \\     apk add --no-cache bash git openssh  # \u0437\u0430\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 WORKDIR \/app  # \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f COPY go.mod .\/ RUN go mod download  # \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b\u044b \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 COPY . .  # \u0431\u0438\u043b\u0434\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 RUN go build -o main .  # \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0438\u0442\u0430\u0435\u0442 8890 \u043f\u043e\u0440\u0442, \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0435\u0433\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u043c\u0438\u0440\u0443 EXPOSE 8890  # \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 CMD [\".\/main\"]<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 CPU \u0440\u0430\u0431\u043e\u0442\u0443 <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"encoding\/json\" \"math\/rand\" \"net\/http\" )  func main() { http.HandleFunc(\"\/handle\", func(writer http.ResponseWriter, request *http.Request) { \/\/ cpu intensive work for i := 0; i &lt;= 1000; i++ { _, _ = json.Marshal(randSeq(10)) }  writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"done!\")) })  _ = http.ListenAndServe(\":8890\", nil) }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c docker-compose<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">version: '3.9'  services:   app:     build:       context: ..\/       dockerfile: Dockerfile     ports:       - \"8870:8890\"     restart: unless-stopped     networks:       - backend     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M  networks:   backend:<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a <strong>docker-compose.yml <\/strong>\u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u043f\u0443\u0442\u0438 <strong>.\/one-instance\/docker-compose.yml<\/strong>, \u0430 <strong>Dockerfile <\/strong>\u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u044b\u0448\u0435, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 <strong>..\/<\/strong><\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439<\/p>\n<pre><code class=\"bash\">docker-compose up --build --force-recreate<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0412 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u043e\u0433<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"bash\">davidagadzhanyan@MacBook-Pro one-instance % docker-compose up --build --force-recreate WARNING: Found orphan containers (one-instance_app1_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up. Building app [+] Building 2.6s (12\/12) FINISHED                                                                                                                                                                          => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s  => => transferring dockerfile: 37B                                                                                                                                                                  0.0s  => [internal] load .dockerignore                                                                                                                                                                    0.0s  => => transferring context: 2B                                                                                                                                                                      0.0s  => [internal] load metadata for docker.io\/library\/golang:1.19.0-alpine3.16                                                                                                                          1.5s  => [1\/7] FROM docker.io\/library\/golang:1.19.0-alpine3.16@sha256:0eb08c89ab1b0c638a9fe2780f7ae3ab18f6ecda2c76b908e09eb8073912045d                                                                    0.0s  => [internal] load build context                                                                                                                                                                    0.0s  => => transferring context: 1.38kB                                                                                                                                                                  0.0s  => CACHED [2\/7] RUN apk update &amp;&amp; apk upgrade &amp;&amp;     apk add --no-cache bash git openssh                                                                                                            0.0s  => CACHED [3\/7] WORKDIR \/app                                                                                                                                                                        0.0s  => CACHED [4\/7] COPY go.mod .\/                                                                                                                                                                      0.0s  => CACHED [5\/7] RUN go mod download                                                                                                                                                                 0.0s  => [6\/7] COPY . .                                                                                                                                                                                   0.0s  => [7\/7] RUN go build -o main .                                                                                                                                                                     0.8s  => exporting to image                                                                                                                                                                               0.1s  => => exporting layers                                                                                                                                                                              0.1s  => => writing image sha256:0166bc8bb315e491a69964bc68ff7a125dc0a8dd9c5865c3970fb2bc428a5ba0                                                                                                         0.0s  => => naming to docker.io\/library\/one-instance_app                                                                                                                                                  0.0s  Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them Recreating one-instance_app_1 ... done Attaching to one-instance_app_1<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0434\u0432\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u044b <a href=\"https:\/\/github.com\/wg\/wrk\" rel=\"noopener noreferrer nofollow\">wrk<\/a>.<strong> <\/strong>\u0414\u043b\u044f \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0435\u0433\u043e \u0432 \u0441\u0440\u0435\u0434\u0435 \u0434\u043e\u043a\u0435\u0440\u0430. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043e\u0431\u0440\u0430\u0437 \u0441 \u044d\u0442\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 \u0432 <a href=\"https:\/\/hub.docker.com\/r\/skandyla\/wrk\" rel=\"noopener noreferrer nofollow\">\u0445\u0430\u0431\u0435<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 <strong>wrk <\/strong>\u0441\u043c\u043e\u0433 \u0434\u043e\u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043c \u0435\u0433\u043e \u043a \u0441\u0435\u0442\u0438 <strong>backend.<\/strong><\/p>\n<p>\u0414\u043e\u043a\u0435\u0440 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0442\u0438. \u041d\u0430\u0439\u0442\u0438 \u0442\u043e\u0447\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code class=\"bash\">docker network ls<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0435\u0440\u043e\u043c \u0441\u0435\u0442\u0435\u0439.<\/p>\n<pre><code class=\"bash\">NETWORK ID     NAME                            DRIVER    SCOPE 657a365c5cdd   one-instance_backend            bridge    local<\/code><\/pre>\n<p>\u0412\u0438\u0434\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0442\u0438 <strong>one-instance_backend<\/strong><\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0438 \u043e\u0434\u043d\u043e\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c \u043f\u0440\u0438 \u0442\u0440\u0435\u0445.<\/p>\n<pre><code class=\"bash\">docker run --network=one-instance_backend \\ --rm skandyla\/wrk -t1 -c1 -d5s http:\/\/app:8890\/handle    docker run --network=one-instance_backend \\ --rm skandyla\/wrk -t3 -c3 -d5s http:\/\/app:8890\/handle <\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/p>\n<pre><code class=\"bash\">Running 5s test @ http:\/\/app:8890\/handle   1 threads and 1 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    22.55ms   28.32ms  91.44ms   78.73%     Req\/Sec   169.56     47.70   410.00     78.00%   854 requests in 5.05s, 93.41KB read Requests\/sec:    169.08 Transfer\/sec:     18.49KB  Running 5s test @ http:\/\/app:8890\/handle   3 threads and 3 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    45.85ms   42.16ms 195.06ms   31.70%     Req\/Sec    25.06     15.04    99.00     70.75%   377 requests in 5.06s, 41.23KB read Requests\/sec:     74.56 Transfer\/sec:      8.16KB<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <strong>\u0442\u0440\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/strong>, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c\u0438 <strong>nginx<\/strong> \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\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433 <strong>nginx <\/strong>\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 <strong>round robin <\/strong>(\u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c).<\/p>\n<blockquote>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a><\/p>\n<\/blockquote>\n<pre><code class=\"nginx\">upstream app {     server app1:8890;     server app2:8890;     server app3:8890; }  server {     listen 8891;     location \/ {         proxy_pass http:\/\/app;     } }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 docker-compose.yml<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">version: '3.9'  services:   app1:     build:       context: ..       dockerfile: Dockerfile     ports:       - \"8881:8890\"     restart: unless-stopped     networks:       - backend     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M    app2:     build:       context: ..       dockerfile: Dockerfile     ports:       - \"8882:8890\"     restart: unless-stopped     networks:       - backend     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M    app3:     build:       context: ..       dockerfile: Dockerfile     ports:       - \"8883:8890\"     restart: unless-stopped     networks:       - backend     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M    ngnix-server:     image: nginx:latest     ports:       - \"8891:8891\"     volumes:       - \/Users\/davidagadzhanyan\/go\/src\/highload-patterns\/scale-stateless\/multiple-with-lb\/nginx.conf:\/etc\/nginx\/conf.d\/default.conf     networks:       - backend  networks:   backend:  networks:   backend:<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<blockquote>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u043d\u0435\u043c\u0443<\/p>\n<\/blockquote>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438<\/p>\n<pre><code class=\"bash\">docker run --network=multiple-with-lb_backend  \\ --rm skandyla\/wrk -t1 -c1 -d5s http:\/\/ngnix-server:8891\/handle    docker run --network=multiple-with-lb_backend  \\ --rm skandyla\/wrk -t3 -c3 -d5s http:\/\/ngnix-server:8891\/handle<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u043e\u0433<\/p>\n<pre><code class=\"bash\">Running 5s test @ http:\/\/ngnix-server:8891\/handle   1 threads and 1 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency     9.09ms   13.99ms  68.66ms   82.25%     Req\/Sec   451.82     93.72     1.02k    92.00%   2251 requests in 5.00s, 347.31KB read Requests\/sec:    450.16 Transfer\/sec:     69.46KB  Running 5s test @ http:\/\/ngnix-server:8891\/handle   3 threads and 3 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    22.41ms   26.86ms  95.08ms   78.73%     Req\/Sec   109.03     33.69   250.00     76.00%   1631 requests in 5.01s, 251.66KB read Requests\/sec:    325.80 Transfer\/sec:     50.27KB<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"291\" width=\"291\">\n<p align=\"left\">\n<\/td>\n<td data-colwidth=\"259\" width=\"259\">\n<p align=\"center\"><strong>RPS<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Latency<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"291\" width=\"291\">\n<p align=\"left\">one instance (1t, 1c)<\/p>\n<\/td>\n<td data-colwidth=\"259\" width=\"259\">\n<p align=\"center\">169<\/p>\n<\/td>\n<td>\n<p align=\"center\">22.55ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"291\" width=\"291\">\n<p align=\"left\">one instance (3t, 3c)<\/p>\n<\/td>\n<td data-colwidth=\"259\" width=\"259\">\n<p align=\"center\">74<\/p>\n<\/td>\n<td>\n<p align=\"center\">45.85ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"291\" width=\"291\">\n<p align=\"left\">three instances + lb (1t, 1c)<\/p>\n<\/td>\n<td data-colwidth=\"259\" width=\"259\">\n<p align=\"center\">450<\/p>\n<\/td>\n<td>\n<p align=\"center\">9.09ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"291\" width=\"291\">\n<p align=\"left\">three instances + lb (3t, 3c)<\/p>\n<\/td>\n<td data-colwidth=\"259\" width=\"259\">\n<p align=\"center\">325<\/p>\n<\/td>\n<td>\n<p align=\"center\">22.41ms<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043f\u0443\u0442\u0435\u043c \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043a\u0440\u0430\u0442\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0443\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c <strong>RPS<\/strong>, \u0442\u0430\u043a \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c <strong>latency.<\/strong><\/p>\n<blockquote>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/github.com\/donnemartin\/system-design-primer#load-balancer\" rel=\"noopener noreferrer nofollow\">system-design-primer<\/a><\/p>\n<\/blockquote>\n<p><strong>\u041f\u043b\u044e\u0441\u044b<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u043b\u044e\u0441\u043e\u0432, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0434\u0435\u0436\u043d\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0440\u0435\u043f\u043b\u0438\u043a, \u0435\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043e\u0442\u043a\u0430\u0437\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0442\u043e\u0440\u044b\u043c \u043f\u043b\u044e\u0441\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u0432\u0435\u0440\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0433 \u0431\u044b \u0441\u0430\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\/\u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u042d\u0442\u0438\u043c \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430\u043c\u0438 \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f <strong>kubernetes <\/strong>\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0435\u0433\u043e \u0441\u043e\u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0438\u043a\u0438 \u0432\u0440\u043e\u0434\u0435 <strong>Docker Swarm <\/strong>\u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041c\u0438\u043d\u0443\u0441\u044b<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f <strong>stateless<\/strong> \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u044f\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u043b\u044e\u0431\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u0431\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u0435\u0434\u0438\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u043a\u0430\u0437\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043e\u0442\u043a\u0430\u0437\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 <strong>nginx<\/strong>,<strong> <\/strong>\u043d\u043e \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0438 \u0435\u0433\u043e \u043e\u0442\u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u0443\u044e \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0443.<\/p>\n<\/li>\n<\/ul>\n<h2>Sync to async<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d6d\/bd4\/f8c\/d6dbd4f8c4dc0c2c17cf14f9215e4416.png\" alt=\"sync processing\" title=\"sync processing\" width=\"2025\" height=\"1251\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d6d\/bd4\/f8c\/d6dbd4f8c4dc0c2c17cf14f9215e4416.png\"\/><figcaption>sync processing<\/figcaption><\/figure>\n<p>\u0415\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0441\u0442\u0435\u0442 \u0442\u0440\u0430\u0444\u0438\u043a \u0438 \u043f\u043e\u043c\u0438\u043c\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445, \u043e\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0435\u0449\u0435 \u0438 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0442\u0440\u0430\u0444\u0438\u043a\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442. \u0422\u0430\u043a \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e?<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043a\u043b\u0438\u043a\u043e\u0432 \u0438 \u043b\u044e\u0431\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0440\u0430\u0441\u0442\u0435\u0442, \u043a\u0430\u043a \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u044d\u0442\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<p><strong>\u041a\u043e\u043d\u0446\u0435\u043f\u0442<\/strong>: \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0444\u0438\u043a\u0441\u0430\u0446\u0438\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u0448\u0438\u043d\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u044d\u0442\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/75e\/8cb\/d43\/75e8cbd4373345255ea248353bac2336.png\" alt=\"async processing\" title=\"async processing\" width=\"2611\" height=\"937\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/75e\/8cb\/d43\/75e8cbd4373345255ea248353bac2336.png\"\/><figcaption>async processing<\/figcaption><\/figure>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>: \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u043d\u0438\u0436\u0435, \u043d\u043e \u043e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 <a href=\"https:\/\/github.com\/agadzhanyan\/highload-patterns\/tree\/main\/sync-to-async\" rel=\"noopener noreferrer nofollow\">github<\/a><\/p>\n<p>\u0421\u044b\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u044f\u043c\u043e\u0439 \u043f\u043e\u0445\u043e\u0434 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441 \u043b\u043e\u0433\u043e\u0432, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0448\u0438\u043d\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c CPU \u0440\u0430\u0431\u043e\u0442\u0443 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441 \u043b\u043e\u0433\u043e\u0432<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"bytes\" \"encoding\/json\" \"io\" \"math\/rand\" \"net\/http\" )  func main() { http.HandleFunc(\"\/handle\", func(writer http.ResponseWriter, request *http.Request) { \/\/ cpu intensive work for i := 0; i &lt;= 1000; i++ { _, _ = json.Marshal(randSeq(10)) }  \/\/ send log resp, err := http.DefaultClient.Post( \"http:\/\/logs:8890\/sendEvent\", \"application\/json\", bytes.NewReader([]byte(randSeq(100))), ) if err != nil { writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"failed!\" + err.Error())) return }  body, err := io.ReadAll(resp.Body) if err != nil { writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"failed!\" + err.Error())) return }  writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"done!\" + string(body))) })  _ = http.ListenAndServe(\":8890\", nil) }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ Random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043b\u044f \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 CPU \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 json<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"encoding\/json\" \"math\/rand\" \"net\/http\" )  func main() { http.HandleFunc(\"\/sendEvent\", func(writer http.ResponseWriter, request *http.Request) { \/\/ cpu intensive work for i := 0; i &lt;= 1000; i++ { _, _ = json.Marshal(randSeq(50)) }  writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"event is saved!\")) })  _ = http.ListenAndServe(\":8890\", nil) }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ Random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0431\u0435\u0440\u0435\u043c docker-compose.yml<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">version: '3.9'  services:   app:     build:       context: .\/app       dockerfile: ..\/..\/Dockerfile     ports:       - \"8861:8890\"     restart: unless-stopped     networks:       - backend     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M    logs:     build:       context: .\/log       dockerfile: ..\/..\/Dockerfile     ports:       - \"8862:8890\"     restart: unless-stopped     networks:       - backend     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M  networks:   backend:<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439<\/p>\n<pre><code class=\"bash\">docker-compose up --build --force-recreate<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0423\u0432\u0438\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043b\u043e\u0433<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"bash\">davidagadzhanyan@MacBook-Pro sync % docker-compose up --build --force-recreate Building app [+] Building 2.8s (12\/12) FINISHED                                                                                                                                                                          => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s  => => transferring dockerfile: 37B                                                                                                                                                                  0.0s  => [internal] load .dockerignore                                                                                                                                                                    0.0s  => => transferring context: 2B                                                                                                                                                                      0.0s  => [internal] load metadata for docker.io\/library\/golang:1.19.0-alpine3.16                                                                                                                          1.6s  => [1\/7] FROM docker.io\/library\/golang:1.19.0-alpine3.16@sha256:0eb08c89ab1b0c638a9fe2780f7ae3ab18f6ecda2c76b908e09eb8073912045d                                                                    0.0s  => [internal] load build context                                                                                                                                                                    0.0s  => => transferring context: 1.86kB                                                                                                                                                                  0.0s  => CACHED [2\/7] RUN apk update &amp;&amp; apk upgrade &amp;&amp;     apk add --no-cache bash git openssh                                                                                                            0.0s  => CACHED [3\/7] WORKDIR \/app                                                                                                                                                                        0.0s  => [4\/7] COPY go.mod .\/                                                                                                                                                                             0.0s  => [5\/7] RUN go mod download                                                                                                                                                                        0.2s  => [6\/7] COPY . .                                                                                                                                                                                   0.0s  => [7\/7] RUN go build -o main .                                                                                                                                                                     0.7s  => exporting to image                                                                                                                                                                               0.1s  => => exporting layers                                                                                                                                                                              0.1s  => => writing image sha256:fc18d50b8af7c9775b9911c32d4c230fcd78025f0f5505e7ddab8d464d77fef9                                                                                                         0.0s  => => naming to docker.io\/library\/sync_app                                                                                                                                                          0.0s  Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them Building logs [+] Building 1.4s (12\/12) FINISHED                                                                                                                                                                          => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s  => => transferring dockerfile: 37B                                                                                                                                                                  0.0s  => [internal] load .dockerignore                                                                                                                                                                    0.0s  => => transferring context: 2B                                                                                                                                                                      0.0s  => [internal] load metadata for docker.io\/library\/golang:1.19.0-alpine3.16                                                                                                                          0.3s  => [internal] load build context                                                                                                                                                                    0.0s  => => transferring context: 140B                                                                                                                                                                    0.0s  => [1\/7] FROM docker.io\/library\/golang:1.19.0-alpine3.16@sha256:0eb08c89ab1b0c638a9fe2780f7ae3ab18f6ecda2c76b908e09eb8073912045d                                                                    0.0s  => CACHED [2\/7] RUN apk update &amp;&amp; apk upgrade &amp;&amp;     apk add --no-cache bash git openssh                                                                                                            0.0s  => CACHED [3\/7] WORKDIR \/app                                                                                                                                                                        0.0s  => [4\/7] COPY go.mod .\/                                                                                                                                                                             0.0s  => [5\/7] RUN go mod download                                                                                                                                                                        0.2s  => [6\/7] COPY . .                                                                                                                                                                                   0.0s  => [7\/7] RUN go build -o main .                                                                                                                                                                     0.7s  => exporting to image                                                                                                                                                                               0.1s  => => exporting layers                                                                                                                                                                              0.1s  => => writing image sha256:9e13068dcf77077505181c536b68b6e182e7df7f4abff2eb52f20f6e23981d8c                                                                                                         0.0s  => => naming to docker.io\/library\/sync_logs                                                                                                                                                         0.0s  Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them Recreating sync_logs_1 ... done Recreating sync_app_1  ... done Attaching to sync_logs_1, sync_app_1<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438<\/p>\n<pre><code class=\"bash\">docker run --network=sync_backend \\ --rm skandyla\/wrk -t1 -c1 -d5s http:\/\/app:8890\/handle    docker run --network=sync_backend \\ --rm skandyla\/wrk -t3 -c3 -d5s http:\/\/app:8890\/handle<\/code><\/pre>\n<p>\u0418 \u0443\u0432\u0438\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/p>\n<pre><code class=\"bash\">Running 5s test @ http:\/\/app:8890\/handle   1 threads and 1 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    28.20ms   29.85ms  90.45ms   77.06%     Req\/Sec    56.42     13.52   117.00     66.00%   283 requests in 5.02s, 35.38KB read Requests\/sec:     56.35 Transfer\/sec:      7.04KB  Running 5s test @ http:\/\/app:8890\/handle   3 threads and 3 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency   105.07ms   64.37ms 204.37ms   54.17%     Req\/Sec    10.07      4.48    20.00     65.49%   144 requests in 5.05s, 18.00KB read Requests\/sec:     28.53 Transfer\/sec:      3.57KB<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c <strong>56rps<\/strong> \u0438 <strong>28rps<\/strong> \u043f\u0440\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0435 <strong>28ms<\/strong> \u0438 <strong>105ms.<\/strong><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043b\u043e\u0433\u043e\u0432 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0448\u0438\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>Apache Kafka<\/strong>.<strong> <\/strong>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u0444\u043a\u0443, \u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u043b\u043e\u0433\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<blockquote>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 <strong>Apache Kafka<\/strong>, \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e \u043d\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0432 <a href=\"https:\/\/kafka.apache.org\/documentation\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a><\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <strong>Apache<\/strong> <strong>Kafka<\/strong> \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>Apache<\/strong> <strong>Zookeeper <\/strong>\u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430\/\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0440\u043e\u043a\u0435\u0440\u043e\u0432\/\u0442\u043e\u043f\u0438\u043a\u043e\u0432\/\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/p>\n<\/blockquote>\n<details class=\"spoiler\">\n<summary>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 docker-compose.yml<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">version: '3.9'  services:   app:     build:       context: .\/app       dockerfile: ..\/..\/Dockerfile     ports:       - \"8851:8890\"     restart: always     networks:       - backend     depends_on:       - zookeeper       - broker     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M    logs:     build:       context: .\/log       dockerfile: ..\/..\/Dockerfile     ports:       - \"8852:8890\"     restart: always     networks:       - backend     depends_on:       - zookeeper       - broker     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M    zookeeper:     image: confluentinc\/cp-zookeeper:7.0.1     container_name: zookeeper     restart: always     networks:       - backend     environment:       ZOOKEEPER_CLIENT_PORT: 2181       ZOOKEEPER_TICK_TIME: 2000    broker:     image: confluentinc\/cp-kafka:7.0.1     container_name: broker     restart: always     ports:       - \"9092:9092\"     networks:       - backend     depends_on:       - zookeeper     environment:       KAFKA_BROKER_ID: 1       KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'       KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT       KAFKA_ADVERTISED_LISTENERS: PLAINTEXT:\/\/localhost:9092,PLAINTEXT_INTERNAL:\/\/broker:29092       KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1       KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1       KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1  networks:   backend:<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043a\u0430\u0444\u043a\u0443<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"context\" \"encoding\/json\" \"log\" \"math\/rand\" \"net\/http\" \"os\"  \"github.com\/segmentio\/kafka-go\" )  func main() { log.SetOutput(os.Stdout)  \/\/ kafka topic topic := \"my-topic\" partition := 0  \/\/ create kafka connection conn, err := kafka.DialLeader(context.Background(), \"tcp\", \"broker:29092\", topic, partition) if err != nil { log.Fatal(\"failed to dial leader:\", err) }  http.HandleFunc(\"\/handle\", func(writer http.ResponseWriter, request *http.Request) { \/\/ cpu intensive work for i := 0; i &lt;= 1000; i++ { _, _ = json.Marshal(randSeq(10)) }  \/\/ produce event to kafka _, err := conn.WriteMessages( kafka.Message{Value: []byte(randSeq(100))}, ) if err != nil { log.Println(err) }  writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"done!\")) })  _ = http.ListenAndServe(\":8890\", nil) }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ Random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u0437 \u043a\u0430\u0444\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"context\" \"encoding\/json\" \"log\" \"math\/rand\" \"os\"  \"github.com\/segmentio\/kafka-go\" )  func main() { log.SetOutput(os.Stdout)  \/\/ kafka topic topic := \"my-topic\" partition := 0  \/\/ create kafka connection r := kafka.NewReader(kafka.ReaderConfig{ Brokers:   []string{\"broker:29092\"}, Topic:     topic, Partition: partition, })  for { \/\/ read message from kafka m, err := r.ReadMessage(context.Background()) if err != nil { log.Println(err) break }  \/\/ cpu intensive work for i := 0; i &lt;= 1000; i++ { _, _ = json.Marshal(randSeq(50)) }  log.Print(m.Offset, string(m.Key), string(m.Value)) } }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ Random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438<\/p>\n<pre><code class=\"bash\">docker run --network=async_backend \\ --rm skandyla\/wrk -t1 -c1 -d5s http:\/\/app:8890\/handle  docker run --network=async_backend \\ --rm skandyla\/wrk -t3 -c3 -d5s http:\/\/app:8890\/handle<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u043e\u0433<\/p>\n<pre><code class=\"bash\">Running 5s test @ http:\/\/app:8890\/handle   1 threads and 1 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    21.24ms   26.03ms  89.19ms   78.94%     Req\/Sec   121.16     36.59   316.00     86.00%   610 requests in 5.05s, 66.72KB read Requests\/sec:    120.80 Transfer\/sec:     13.21KB  Running 5s test @ http:\/\/app:8890\/handle   3 threads and 3 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    40.31ms   37.91ms 103.10ms   68.19%     Req\/Sec    29.21     13.37    90.00     83.33%   441 requests in 5.03s, 48.23KB read Requests\/sec:     87.66 Transfer\/sec:      9.59KB<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"252\" width=\"252\">\n<p align=\"left\">\n<\/td>\n<td data-colwidth=\"299\" width=\"299\">\n<p align=\"center\"><strong>RPS<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Latency<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"252\" width=\"252\">\n<p align=\"left\">sync (1t, 1c)<\/p>\n<\/td>\n<td data-colwidth=\"299\" width=\"299\">\n<p align=\"center\">56<\/p>\n<\/td>\n<td>\n<p align=\"center\">28.20ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"252\" width=\"252\">\n<p align=\"left\">sync (3t, 3c)<\/p>\n<\/td>\n<td data-colwidth=\"299\" width=\"299\">\n<p align=\"center\">28<\/p>\n<\/td>\n<td>\n<p align=\"center\">105.07ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"252\" width=\"252\">\n<p align=\"left\">async (1t, 1c)<\/p>\n<\/td>\n<td data-colwidth=\"299\" width=\"299\">\n<p align=\"center\">120<\/p>\n<\/td>\n<td>\n<p align=\"center\">21.24ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"252\" width=\"252\">\n<p align=\"left\">async (3t, 3c)<\/p>\n<\/td>\n<td data-colwidth=\"299\" width=\"299\">\n<p align=\"center\">87<\/p>\n<\/td>\n<td>\n<p align=\"center\">40.31ms<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430 <strong>RPS<\/strong> \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0430 <strong>latency<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0436\u0434\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c.<\/p>\n<blockquote>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/github.com\/donnemartin\/system-design-primer#asynchronism\" rel=\"noopener noreferrer nofollow\">system-design-primer<\/a><\/p>\n<\/blockquote>\n<p><strong>\u041f\u043b\u044e\u0441\u044b<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u043f\u043b\u044e\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\/\u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f-\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041c\u0438\u043d\u0443\u0441\u044b<\/strong><\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u0442\u044f\u0436\u0435\u043b\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0442\u043e\u0447\u043a\u0430 \u043e\u0442\u043a\u0430\u0437\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0448\u0438\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c<\/p>\n<\/li>\n<\/ul>\n<h2>SQL to NoSQL<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/67f\/f15\/f0a\/67ff15f0ab4c706cf64e84767b47bb8d.png\" alt=\"(no) sql\" title=\"(no) sql\" width=\"2054\" height=\"1206\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/67f\/f15\/f0a\/67ff15f0ab4c706cf64e84767b47bb8d.png\"\/><figcaption>(no) sql<\/figcaption><\/figure>\n<p>\u0415\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u043e\u0434 \u0432\u0441\u0435 \u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044d\u0442\u043e \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0423\u0435\u0437\u0436\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u043e\u0447\u0435\u043d\u044c \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0442\u0440\u0430\u0444\u0438\u043a \u0440\u0430\u0441\u0442\u0435\u0442 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e, \u0447\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043e\u0440\u043e\u0433\u043e. \u0427\u0442\u043e \u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>postgres<\/strong>. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439\/\u0434\u0430\u043d\u043d\u044b\u0445\/\u043b\u043e\u0433\u043e\u0432 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0442\u0435\u0442. \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u044d\u0442\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u0431\u0443\u0445\u0430\u0435\u0442 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043d\u0435\u0435 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u043d\u0435\u0435. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u0440\u043e\u0431\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u043c\u0435\u0441\u044f\u0446\u0430\u043c \u0432\u0440\u043e\u0434\u0435 <strong>activities_01072022<\/strong>, <strong>activities_01082022<\/strong>, \u043d\u043e \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0435\u0442 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0436\u043e\u0439\u043d\u043e\u0432 \u043f\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c. \u0412\u043f\u0435\u0440\u0435\u0434\u0438 \u0436\u0434\u0435\u0442 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e \u043f\u0440\u0430\u0432\u0443 \u0431\u0443\u0434\u0435\u0442 \u043a\u0430\u043a <strong>write-heavy<\/strong>, \u0442\u0430\u043a \u0438 <strong>read-heavy<\/strong>. \u0412\u044b\u043d\u0435\u0441\u0435\u043c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 <strong>nosql<\/strong> \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u041a\u043e\u043d\u0446\u0435\u043f\u0442<\/strong>: \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c, \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430. \u041f\u0435\u0440\u0432\u044b\u0435 &#8212; \u044d\u0442\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u043e \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438, \u043b\u044e\u0431\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u043d\u0438\u043c\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 <strong>ACID <\/strong>\u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438\/\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438\/\u0431\u043e\u043d\u0443\u0441\u043d\u044b\u0435 \u0441\u0447\u0435\u0442\u0430. \u041a \u0442\u0430\u043a\u0438\u043c \u0431\u0430\u0437\u0430\u043c \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f <strong>mysql<\/strong>, <strong>postgres<\/strong> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 <strong>nosql <\/strong>\u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430 \u0441\u0447\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0434\u0430\u044e\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0437\u0430\u0434\u0430\u0447. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>redis <\/strong>\u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 <strong>RAM <\/strong>\u0438 \u0437\u0430 \u0441\u0447\u0435\u0442 \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0443\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0441 \u043d\u0438\u0437\u043a\u0438\u043c <strong>latency<\/strong>. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u0446\u0438\u043a\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\u0445, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0446\u0435\u043b\u043e\u043c, \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u044e \u043a\u0443\u0445\u043d\u044e \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0431\u043b\u044e\u0434\u0430\u043c\u0438, \u0433\u0434\u0435 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>: \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u043d\u0438\u0436\u0435, \u043d\u043e \u043e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 <a href=\"https:\/\/github.com\/agadzhanyan\/highload-patterns\/tree\/main\/sql-to-nosql\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u0432 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043a\u043e\u0440\u043e\u0431\u043e\u0447\u043d\u044b\u0435 <strong>postgres <\/strong>\u0438<strong> cassandra.<\/strong><\/p>\n<details class=\"spoiler\">\n<summary>Go \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 postgres<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"database\/sql\" \"encoding\/json\" \"log\" \"math\/rand\" \"net\/http\" \"os\" \"time\"  \"github.com\/google\/uuid\" _ \"github.com\/lib\/pq\" )  func main() { log.SetOutput(os.Stdout)  connStr := \"host=postgres user=postgres password=postgres dbname=postgres sslmode=disable\" db, err := sql.Open(\"postgres\", connStr) if err != nil { log.Fatal(err) }  http.HandleFunc(\"\/handle\", func(writer http.ResponseWriter, request *http.Request) { uid := uuid.New().String() blob, _ := json.Marshal(randSeq(100))  err := db.QueryRowContext( request.Context(), `INSERT INTO activities(id, user_id, timestamp, data) VALUES($1, $2, $3, $4)`, uid, uuid.New().String(), time.Now(), string(blob), ).Err() if err != nil { writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"failed!\" + err.Error())) return }  writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"saved! \" + uid)) })  _ = http.ListenAndServe(\":8890\", nil) }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ Random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 docker-compose.yml<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">version: '3.9'  services:   app:     build:       context: .       dockerfile: ..\/Dockerfile     ports:       - \"8831:8890\"     restart: always     networks:       - backend     depends_on:       - postgres     deploy:       resources:         limits:           cpus: '1'           memory: 2000M    postgres:     image: postgres:14.0     volumes:       - \/Users\/davidagadzhanyan\/go\/src\/highload-patterns\/sql-to-nosql\/sql\/schema.sql:\/docker-entrypoint-initdb.d\/10-init.sql     networks:       - backend     environment:       POSTGRES_DB: \"postgres\"       POSTGRES_USER: \"postgres\"       POSTGRES_PASSWORD: \"postgres\"     ports:       - \"5432:5432\"     deploy:       resources:         limits:           cpus: '1'           memory: 2000M  networks:   backend:<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre><code class=\"pgsql\">create table if not exists activities (     id varchar primary key,     user_id varchar,     timestamp timestamp,     data jsonb );<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 cassandra<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"encoding\/json\" \"log\" \"math\/rand\" \"net\/http\" \"os\" \"time\"  \"github.com\/gocql\/gocql\" )  func main() { log.SetOutput(os.Stdout)  cluster := gocql.NewCluster(\"cassandra\") cluster.Keyspace = \"app\" cluster.Consistency = gocql.Quorum cluster.Authenticator = gocql.PasswordAuthenticator{ Username: \"cassandra\", Password: \"cassandra\", }  session, err := cluster.CreateSession() if err != nil { log.Fatal(err) } defer session.Close()  http.HandleFunc(\"\/handle\", func(writer http.ResponseWriter, request *http.Request) { uid := gocql.UUIDFromTime(time.Now()) blob, _ := json.Marshal(randSeq(100)) if err := session.Query( `INSERT INTO activities (id, user_id, timestamp, data) VALUES (?, ?, ?, ?)`, uid, gocql.UUIDFromTime(time.Now()), time.Now().Unix(), blob,  ).Exec(); err != nil { writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"failed!\" + err.Error())) return }  writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"saved! \" + uid.String())) })  _ = http.ListenAndServe(\":8890\", nil) }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ Random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 docker-compose.yml<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">version: '3.9'  services:   app:     build:       context: .       dockerfile: ..\/Dockerfile     ports:       - \"8841:8890\"     restart: always     networks:       - backend     depends_on:       - cassandra     deploy:       resources:         limits:           cpus: '1'           memory: 1000M    cassandra:     image: docker.io\/bitnami\/cassandra:4.0     networks:       - backend     environment:       - CASSANDRA_SEEDS=cassandra       - CASSANDRA_CLUSTER_NAME=cassandra-cluster       - MAX_HEAP_SIZE=1000M       - HEAP_NEWSIZE=1000M       - CASSANDRA_PASSWORD_SEEDER=yes       - CASSANDRA_PASSWORD=cassandra     ports:       - 9042:9042     volumes:       - cassandra_data:\/bitnami     deploy:       resources:         limits:           cpus: '1'           memory: 1000M    #from netflix repo: https:\/\/github.com\/Netflix\/osstracker\/blob\/master\/docker-compose.yml#L67   cassandra-load-keyspace:     container_name: cassandra-load-keyspace     image: cassandra:4.0     networks:       - backend     depends_on:       - cassandra     volumes:       - \/Users\/davidagadzhanyan\/go\/src\/highload-patterns\/sql-to-nosql\/nosql\/schema.cql:\/schema.cql     command: \/bin\/bash -c \"sleep 10 &amp;&amp; echo loading cassandra keyspace &amp;&amp; cqlsh cassandra -u cassandra -p cassandra -f \/schema.cql\"     deploy:       restart_policy:         condition: on-failure         delay: 5s         max_attempts: 3         window: 60s  networks:   backend:  volumes:   cassandra_data:     driver: local<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre><code class=\"pgsql\">DROP KEYSPACE IF EXISTS app;  CREATE KEYSPACE app WITH replication = {     'class': 'SimpleStrategy',     'replication_factor': 1     };  USE app;  CREATE TABLE IF NOT EXISTS activities (     id        uuid,     user_id   uuid,     timestamp timestamp,     data      blob,     PRIMARY KEY ((id)) ) WITH comment = 'Table with all activities';<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <strong>postgres <\/strong>\u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438<\/p>\n<pre><code class=\"bash\">docker run --network=sql_backend \\ --rm skandyla\/wrk -t1 -c1 -d5s http:\/\/app:8890\/handle    docker run --network=sql_backend \\  --rm skandyla\/wrk -t12 -c12 -d5s http:\/\/app:8890\/handle<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/p>\n<pre><code class=\"bash\">Running 5s test @ http:\/\/app:8890\/handle   1 threads and 1 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency     2.50ms    2.91ms  31.13ms   88.86%     Req\/Sec   524.24    143.19   760.00     80.00%   2611 requests in 5.01s, 385.02KB read Requests\/sec:    521.43 Transfer\/sec:     76.89KB  Running 5s test @ http:\/\/app:8890\/handle   12 threads and 12 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    42.74ms   40.28ms 199.19ms   78.80%     Req\/Sec    27.36     16.36    90.00     56.57%   1623 requests in 5.02s, 239.33KB read Requests\/sec:    323.08 Transfer\/sec:     47.64KB<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <strong>cassandra<\/strong> \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438<\/p>\n<pre><code class=\"bash\">docker run --network=nosql_backend \\ --rm skandyla\/wrk -t1 -c1 -d5s http:\/\/app:8890\/handle   docker run --network=nosql_backend \\ --rm skandyla\/wrk -t12 -c12 -d5s http:\/\/app:8890\/handle<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/p>\n<pre><code class=\"bash\">Running 5s test @ http:\/\/app:8890\/handle   1 threads and 1 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency     2.81ms  806.39us  14.13ms   91.44%     Req\/Sec   357.46     53.13   505.00     82.00%   1782 requests in 5.01s, 262.78KB read   Socket errors: connect 0, read 0, write 0, timeout 1 Requests\/sec:    355.75 Transfer\/sec:     52.46KB  Running 5s test @ http:\/\/app:8890\/handle   12 threads and 12 connections   Thread Stats   Avg      Stdev     Max   +\/- Stdev     Latency    18.74ms   22.30ms 177.19ms   80.58%     Req\/Sec   101.73     30.50   222.00     74.12%   6103 requests in 5.03s, 0.88MB read Requests\/sec:   1213.30 Transfer\/sec:    178.91KB<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0435\u0440\u0435\u043c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"294\" width=\"294\">\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"center\"><strong>RPS<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>Latency<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"294\" width=\"294\">\n<p align=\"left\">postgres (1t, 1c)<\/p>\n<\/td>\n<td>\n<p align=\"center\">521<\/p>\n<\/td>\n<td>\n<p align=\"center\">2.50ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"294\" width=\"294\">\n<p align=\"left\">postgres (12t, 12c)<\/p>\n<\/td>\n<td>\n<p align=\"center\">323<\/p>\n<\/td>\n<td>\n<p align=\"center\">42.74ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"294\" width=\"294\">\n<p align=\"left\">cassandra (1t, 1c)<\/p>\n<\/td>\n<td>\n<p align=\"center\">355<\/p>\n<\/td>\n<td>\n<p align=\"center\">2.81ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"294\" width=\"294\">\n<p align=\"left\">cassandra (12t, 12c)<\/p>\n<\/td>\n<td>\n<p align=\"center\">1213<\/p>\n<\/td>\n<td>\n<p align=\"center\">18.74ms<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0445\u043e\u0442\u044c \u0438 <strong>postgres <\/strong>\u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u0443 <strong>cassandra<\/strong> \u043d\u0430 1 \u043f\u043e\u0442\u043e\u043a\u0435 \u0438 1 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438, \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u0445 \u0443\u0436\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0443\u043f\u0430\u0435\u0442.<\/p>\n<blockquote>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u0438\u043c\u0435\u0440 \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438, \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0438 \u0438\u043c\u0435\u044e\u0442 \u0432 \u043a\u043e\u0440\u043d\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>postgres <\/strong>&#8212; \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0411\u0414 \u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a, \u0441 <strong>ACID<\/strong> \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438.<\/p>\n<p><strong>Cassandra<\/strong> \u0436\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u0443 \u043a\u043e\u043b\u043e\u043d\u043e\u0447\u043d\u044b\u0445, \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0441\u0436\u0438\u043c\u0430\u0435\u0442 \u0442\u043e\u043d\u043d\u044b \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043d\u0430 \u043e\u0442\u043b\u0438\u0447\u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435 \u0442\u043e\u043d\u043d\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/blog.knoldus.com\/apache-cassandra-reads-and-writes\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a> \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438). \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 C++ \u0430\u043d\u0430\u043b\u043e\u0433 <strong>ScyllaDB<\/strong>, <a href=\"https:\/\/www.scylladb.com\/2021\/08\/24\/apache-cassandra-4-0-vs-scylla-4-4-comparing-performance\/#:~:text=ScyllaDB%20has%202x%2D5x%20better,4x%20faster%20than%20Cassandra%204.0\" rel=\"noopener noreferrer nofollow\">\u0433\u043e\u0432\u043e\u0440\u044f\u0442<\/a> \u0447\u0442\u043e \u043e\u043d\u0430 \u0435\u0449\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p><strong>Postgres <\/strong>\u0438\u043c\u0435\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 <strong>master-master<\/strong> \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438, \u043d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0443\u0445\u043e\u0434\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0438 \u044d\u0442\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u041f\u043e \u0442\u0435\u043e\u0440\u0435\u043c\u0435 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A2%D0%B5%D0%BE%D1%80%D0%B5%D0%BC%D0%B0_CAP\" rel=\"noopener noreferrer nofollow\">CAP<\/a> \u0442\u0430\u043a\u0430\u044f \u0411\u0414 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a CA, \u0443 \u043d\u0435\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438 \u0440\u0430\u0441\u0449\u0435\u043f\u043b\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u043d\u043e\u0434\u0430\u043c.<\/p>\n<p><strong>Cassandra<\/strong> \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u0430 \u043f\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0437\u0430 \u0441\u0447\u0435\u0442 <a href=\"https:\/\/cassandra.apache.org\/doc\/latest\/cassandra\/architecture\/dynamo.html\" rel=\"noopener noreferrer nofollow\"><strong>consisting hashing<\/strong><\/a> + \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043d\u043e\u0434 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0434. \u041b\u044e\u0431\u0430\u044f \u0440\u0435\u043f\u043b\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c. \u041f\u043e \u0442\u0435\u043e\u0440\u0435\u043c\u0435 CAP \u0442\u0430\u043a\u0438\u0435 \u0411\u0414 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a AP, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043d\u043e\u0434\u0430\u0445 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u044b.<\/p>\n<\/blockquote>\n<h3>\u0418\u0442\u043e\u0433<\/h3>\n<p>\u041c\u044b \u043f\u043e \u0432\u0435\u0440\u0445\u0430\u043c \u043f\u0440\u043e\u0448\u043b\u0438\u0441\u044c \u043f\u043e \u0442\u0440\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c \u043a \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0442\u0435\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0433\u043b\u0443\u0431\u0436\u0435. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430\u043c \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430. \u0411\u0443\u0434\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u0435\u043b\u0435\u043d \u043b\u044e\u0431\u044b\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\u043c. \u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \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\/post\/684904\/\"> https:\/\/habr.com\/ru\/post\/684904\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u0433\u0430\u0434\u0436\u0430\u043d\u044f\u043d \u0414\u0430\u0432\u0438\u0434 \u0438 \u0440\u0430\u043d\u0435\u0435 \u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/post\/682618\/\" rel=\"noopener noreferrer nofollow\">\u00ab\u043f\u0440\u043e\u0441\u0442\u044b\u0435 highload \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043d\u0430 Go\u00bb<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0445\u0430\u0440\u0434\u043a\u043e\u0440\u0430. \u041c\u043d\u0435 \u0438\u043c\u043f\u043e\u043d\u0438\u0440\u0443\u044e\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0442\u0430\u043a \u043a\u0430\u043a <strong>over engineering<\/strong> \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u0438 \u0442\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u044b\u0445 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445, \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u0432\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438 <strong>\u043b\u0443\u0447\u0448\u0438\u043c\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438<\/strong>. \u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438. \u041f\u043e\u0434\u0445\u043e\u0434\u044b \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b, \u043f\u0440\u0438\u043f\u0438\u0441\u043a\u0430 \u044f\u0437\u044b\u043a\u0430 <strong>Go<\/strong> \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043d\u0435\u043c. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u044b, \u0430 \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0437\u0430\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0443 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0432\u0437\u044f\u0442\u044c \u043d\u0430 \u0437\u0430\u043c\u0435\u0442\u043a\u0443.<\/p>\n<blockquote>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043c\u0435\u0440 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0443\u043a\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u0443 \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0434\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u043d\u044b\u0435 \u0441 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432<\/p>\n<\/blockquote>\n<h2>Stateless horizontal scaling<\/h2>\n<figure class=\"full-width\"><figcaption>one instance<\/figcaption><\/figure>\n<p>\u0415\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0432 \u0431\u043e\u044e \u0438 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u041f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0442\u0440\u0430\u0444\u0438\u043a \u0440\u0430\u0441\u0442\u0435\u0442, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435\u043d\u0430\u0441\u044b\u0442\u043d\u0435\u0435 \u0438 \u0432\u0441\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u0418 \u0432\u043e\u0442 \u043d\u0430\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u043f\u0438\u043a, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <strong>CPU\/RAM<\/strong> \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0436\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u043c\u0435\u0440\u044b. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u043e\u0447\u0435\u043d\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 &#8212; \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 <strong>CPU<\/strong> \u0440\u0430\u0441\u0447\u0435\u0442\u044b. \u0422\u0440\u0430\u0444\u0438\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0442\u0435\u0442, <strong>CPU<\/strong> \u0436\u0435\u043b\u0435\u0437\u043a\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043f\u0440\u0435\u0434\u0435\u043b\u0443, \u0430 \u0441\u0430\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0442\u0430\u043a \u0443\u0436\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u0432\u0430\u0442\u0438\u043b\u043e \u043a\u043e\u043c\u043f\u0435\u0442\u0435\u043d\u0446\u0438\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0420\u0430\u0441\u0442\u0438 \u0438 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0434\u043e\u0440\u043e\u0433\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u043e\u0431\u043e\u0440\u0443\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0436\u0435 \u043d\u0435 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e<\/p>\n<p><strong>\u041a\u043e\u043d\u0446\u0435\u043f\u0442<\/strong>: \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0436\u0435\u043b\u0435\u0437\u043e\u043a \u0438 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c\u0438 <strong>load balancer<\/strong><\/p>\n<figure class=\"full-width\"><figcaption>multiple instances with load balancer<\/figcaption><\/figure>\n<p><strong>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>: \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u043d\u0438\u0436\u0435, \u043d\u043e \u043e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 <a href=\"https:\/\/github.com\/agadzhanyan\/highload-patterns\/tree\/main\/scale-stateless\" rel=\"noopener noreferrer nofollow\">github<\/a><\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u0437\u0430\u0442\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0441 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c\u0438<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0436\u0435\u043b\u0435\u0437\u043a\u0438 \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c <a href=\"https:\/\/www.docker.com\/\" rel=\"noopener noreferrer nofollow\">docker<\/a> \u0438 <a href=\"https:\/\/docs.docker.com\/compose\/\" rel=\"noopener noreferrer nofollow\">docker-compose<\/a><\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e <strong>CPU<\/strong> \u0432 <strong>docker-compose <\/strong>\u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 <a href=\"https:\/\/docs.docker.com\/compose\/compose-file\/compose-file-v2\/#cpu-and-other-resources\" rel=\"noopener noreferrer nofollow\">&#171;2.2&#187;<\/a>. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/docs.docker.com\/compose\/compose-file\/compose-file-v3\/#resources\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439<\/a> \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<pre><code class=\"yaml\">version: \"3.9\" services:   redis:     image: redis:alpine     deploy:       resources:         limits:           cpus: '0.50' &lt;- \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e           memory: 50M         reservations:           cpus: '0.25'           memory: 20M<\/code><\/pre>\n<blockquote>\n<p>In this general example, the\u00a0<code>redis<\/code>\u00a0service is constrained to use no more than 50M of memory and\u00a0<code>0.50<\/code>\u00a0(50% of a single core) of available processing time (CPU), and has\u00a0<code>20M<\/code>\u00a0of memory and\u00a0<code>0.25<\/code>\u00a0CPU time reserved (as always available to it).<\/p>\n<\/blockquote>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e <strong>0.5 <\/strong>\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 <strong>50%<\/strong> \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u044f\u0434\u0440\u0430. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <strong>20%<\/strong><\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 <strong>Go<\/strong>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c <strong>Dockerfile<\/strong>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440<\/p>\n<pre><code class=\"powershell\"># \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0441\u0432\u0435\u0436\u0438\u0445 \u043e\u0431\u0440\u0430\u0437\u043e\u0432 Go FROM golang:1.19.0-alpine3.16  # alpine \u043e\u0431\u0440\u0430\u0437 \u0431\u0435\u0434\u0435\u043d \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 RUN apk update &amp;&amp; apk upgrade &amp;&amp; \\     apk add --no-cache bash git openssh  # \u0437\u0430\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 WORKDIR \/app  # \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f COPY go.mod .\/ RUN go mod download  # \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b\u044b \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 COPY . .  # \u0431\u0438\u043b\u0434\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 RUN go build -o main .  # \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0438\u0442\u0430\u0435\u0442 8890 \u043f\u043e\u0440\u0442, \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0435\u0433\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u043c\u0443 \u043c\u0438\u0440\u0443 EXPOSE 8890  # \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 CMD [\".\/main\"]<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 CPU \u0440\u0430\u0431\u043e\u0442\u0443 <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">package main  import ( \"encoding\/json\" \"math\/rand\" \"net\/http\" )  func main() { http.HandleFunc(\"\/handle\", func(writer http.ResponseWriter, request *http.Request) { \/\/ cpu intensive work for i := 0; i &lt;= 1000; i++ { _, _ = json.Marshal(randSeq(10)) }  writer.Header().Add(\"Content-Type\", \"application\/json\") writer.Write([]byte(\"done!\")) })  _ = http.ListenAndServe(\":8890\", nil) }  var letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")  \/\/ random string generator func randSeq(n int) string { b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c docker-compose<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">version: '3.9'  services:   app:     build:       context: ..\/       dockerfile: Dockerfile     ports:       - \"8870:8890\"     restart: unless-stopped     networks:       - backend     deploy:       resources:         limits:           cpus: '0.2'           memory: 500M  networks:   backend:<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a <strong>docker-compose.yml <\/strong>\u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u043f\u0443\u0442\u0438 <strong>.\/one-instance\/docker-compose.yml<\/strong>, \u0430 <strong>Dockerfile <\/strong>\u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u044b\u0448\u0435, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 <strong>..\/<\/strong><\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439<\/p>\n<pre><code class=\"bash\">docker-compose up --build --force-recreate<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0412 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u043e\u0433<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"bash\">davidagadzhanyan@MacBook-Pro one-instance % docker-compose up --build --force-recreate WARNING: Found orphan containers (one-instance_app1_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up. Building app [+] Building 2.6s (12\/12) FINISHED                                                                                                                                                                          => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s  => => transferring dockerfile: 37B                                                                                                                                                                  0.0s  => [internal] load .dockerignore                                                                                                                                                                    0.0s  => => transferring context: 2B                                                                                                                                                                      0.0s  => [internal] load metadata for docker.io\/library\/golang:1.19.0-alpine3.16                                                                                                                          1.5s  => [1\/7] FROM docker.io\/library\/golang:1.19.0-alpine3.16@sha256:0eb08c89ab1b0c638a9fe2780f7ae3ab18f6ecda2c76b908e09eb8073912045d                                                                    0.0s  => [internal] load build context                                                                                                                                                                    0.0s  => => transferring context: 1.38kB                                                                                                                                                                  0.0s  => CACHED [2\/7] RUN apk update &amp;&amp; apk upgrade &amp;&amp;     apk add --no-cache bash git openssh                                                                                                            0.0s  => CACHED [3\/7] WORKDIR \/app                                                                                                                                                                        0.0s  => CACHED [4\/7] COPY go.mod .\/                                                                                                                                                                      0.0s  => CACHED [5\/7] RUN go mod download                                                                                                                                                                 0.0s  => [6\/7] COPY . .                                                                                                                                                                                   0.0s  => [7\/7] RUN go build -o main .                                                                                                                                                                     0.8s  => exporting to image                                                                                                                                                                               0.1s  => => exporting layers                                                                                                                                                                              0.1s  => => writing image sha256:0166bc8bb315e491a69964bc68ff7a125dc0a8dd9c5865c3970fb2bc428a5ba0                                                                                                         0.0s  => => naming to docker.io\/library\/one-instance_app                                                                                                                                                  0.0s  Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them Recreating one-instance_app_1 ... done Attaching to one-instance_app_1<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0434\u0432\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u044b <a href=\"https:\/\/github.com\/wg\/wrk\" rel=\"noopener noreferrer nofollow\">wrk<\/a>.<strong> <\/strong>\u0414\u043b\u044f \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0435\u0433\u043e \u0432 \u0441\u0440\u0435\u0434\u0435 \u0434\u043e\u043a\u0435\u0440\u0430. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043e\u0431\u0440\u0430\u0437 \u0441 \u044d\u0442\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 \u0432 <a href=\"https:\/\/hub.docker.com\/r\/skandyla\/wrk\" rel=\"noopener noreferrer nofollow\">\u0445\u0430\u0431\u0435<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 <strong>wrk <\/strong>\u0441\u043c\u043e\u0433 \u0434\u043e\u0441\u0442\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043c \u0435\u0433\u043e \u043a \u0441\u0435\u0442\u0438 <strong>backend.<\/strong><\/p>\n<p>\u0414\u043e\u043a\u0435\u0440 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0442\u0438. \u041d\u0430\u0439\u0442\u0438 \u0442\u043e\u0447\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<pre><code class=\"bash\">docker network ls<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0435\u0440\u043e\u043c \u0441\u0435\u0442\u0435\u0439.<\/p>\n<pre><code class=\"bash\">NETWORK ID     NAME                            DRIVER<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-337749","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337749","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=337749"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337749\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}