{"id":352380,"date":"2024-05-20T22:07:32","date_gmt":"2024-05-20T22:07:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=352380"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=352380","title":{"rendered":"<span>\u0423\u0447\u0438\u043c\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c Semaphore \u0438 Worker Pool \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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/61f\/a97\/ce9\/61fa97ce98beaf08ab5182a64643aa25.png\" width=\"1560\" height=\"875\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/61f\/a97\/ce9\/61fa97ce98beaf08ab5182a64643aa25.png\"\/><\/figure>\n<h2>\u0423\u0447\u0438\u043c\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c Semaphore \u0438 Worker Pool \u043d\u0430 Go<\/h2>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u042f \u0410\u0440\u0442\u0451\u043c \u0427\u0430\u0430\u0434\u0430\u0435\u0432 \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0430\u0441\u0441\u043e\u0440\u0442\u0438\u043c\u0435\u043d\u0442\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u0422\u0443\u0442\u0443 \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Go.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Go, \u043e\u0434\u043d\u0430\u043a\u043e \u0431\u0435\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u044e\u0442 \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0435\u0448\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u0443\u044e \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0434\u0435\u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u043c API (\u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438). \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0432\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Go: \u0441\u0435\u043c\u0430\u0444\u043e\u0440 (Semaphore) \u0438 \u043f\u0443\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Worker pool).<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b\u044f\u0441\u043d\u0438\u043c \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043e\u0431\u043e\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a-\u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<h3>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 1 \u0434\u043e 100 000, \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e Deactivate. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0443\u0442\u0451\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 API (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u0447\u043a\u0430\u043c\u0438) \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441 \u0435\u0433\u043e ID \u0438 \u043a\u0430\u043a\u0438\u043c\u0438-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u0430\u0451\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b. \u041f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0430\u0439\u043c-\u0430\u0443\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 * \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u042d\u0442\u043e \u0434\u0430\u0441\u0442 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0439 \u0440\u043e\u0441\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u044f\u0437\u044b\u043a\u0430 Go, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u044b \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438: \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438, \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438, WaitGroup, \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438. \u0426\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u0441 \u0441 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u0441\u0435\u043c\u0430\u0444\u043e\u0440 (Semaphore);<\/p>\n<\/li>\n<li>\n<p>\u043f\u0443\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Worker pool).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043d\u0435 \u0443\u0447\u0442\u0435\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043f\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445.<\/p>\n<p>\u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 (\u0432 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u0441 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438 \u0432 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u044d\u0442\u043e \u043c\u0435\u043d\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u043e) \u044f \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<h3>\u0421\u0435\u043c\u0430\u0444\u043e\u0440 (Semaphore)<\/h3>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f, \u043f\u043e \u0441\u0443\u0442\u0438, \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d. \u0418\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Semaphore, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0431\u0443\u0444\u0435\u0440 \u043a\u0430\u043d\u0430\u043b\u0430 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d, \u0442\u043e \u043f\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 Acquire \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0431\u0443\u0444\u0435\u0440 \u043d\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 Release.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043d\u0430\u043b, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 (\u0437\u0434\u0435\u0441\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0442\u043e\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f main).<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"go\">type Semaphore struct { C chan struct{} }  func (s *Semaphore) Acquire() { s.C &lt;- struct{}{} }  func (s *Semaphore) Release() { &lt;-s.C }  type resultWithError struct { User users.User Err  error }  func DeactivateUsers(usrs []users.User, gCount int) ([]users.User, error) { \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u043a\u0430\u043d\u0430\u043b \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0431\u0443\u0444\u0435\u0440\u0430 \u0440\u0430\u0432\u043d\u044b\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044e \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d sem := Semaphore{ C: make(chan struct{}, gCount), }  \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 outputCh := make(chan resultWithError, len(usrs)) \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d, \u0447\u0442\u043e \u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0436\u0434\u0435\u043c \u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f sgnlCh := make(chan struct{})  output := make([]users.User, 0, len(usrs))  for _, v := range usrs { go func(usr users.User) { sem.Acquire() defer sem.Release()  err := usr.Deactivate()  \/\/ \u0435\u0441\u043b\u0438 \u043b\u043e\u0432\u0438\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430, \u0442\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e select { case outputCh &lt;- resultWithError{ User: usr, Err:  err, }: case &lt;-sgnlCh: return } }(v) }  \/\/ \u0436\u0434\u0435\u043c \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \/\/ \u043b\u0438\u0431\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u0441\u0435, \u043b\u0438\u0431\u043e \u0432\u044b\u0439\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c for i := len(usrs); i > 0; i-- { res := &lt;-outputCh if res.Err != nil { close(sgnlCh) return nil, fmt.Errorf(\"an error occurred: %w\", res.Err) }  output = append(output, res.User) }  return output, nil }  <\/code><\/pre>\n<h3>\u041f\u0443\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Worker pool)<\/h3>\n<p>\u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0442\u043d\u0438 \u0442\u044b\u0441\u044f\u0447 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043f\u0440\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0447\u0438\u0442\u0430\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u043a\u0430\u043d\u0430\u043b \u0441 \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u0443\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u0437\u0430\u043a\u0440\u043e\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 (\u0437\u0434\u0435\u0441\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0442\u043e\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f) \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"go\"> type resultWithError struct { User users.User Err  error }  func deactivateUser(wg *sync.WaitGroup, inCh &lt;-chan users.User, outCh chan&lt;- resultWithError) { defer wg.Done()  for usr := range inCh { err := usr.Deactivate() outCh &lt;- resultWithError{ User: usr, Err:  err, } } }  func DeactivateUsers(usrs []users.User, wgCount int) ([]users.User, error) { \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c inputCh := make(chan users.User) \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 outputCh := make(chan resultWithError) \/\/ \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d wg := &amp;sync.WaitGroup{}  output := make([]users.User, 0, len(usrs))  go func() { defer close(inputCh)  for i := range usrs { inputCh &lt;- usrs[i] } }()  go func() { for i := 0; i &lt; wgCount; i++ { wg.Add(1)  go deactivateUser(wg, inputCh, outputCh) } wg.Wait() close(outputCh) }()  \/\/ \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b for res := range outputCh { if res.Err != nil { return nil, fmt.Errorf(\"an error occurred: %w\", res.Err) }  output = append(output, res.User) }  return output, nil } <\/code><\/pre>\n<h3>\u0411\u0435\u043d\u0447\u0438\u043c<\/h3>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u0441\u0442\u0430\u0442\u044c\u0451\u0439 \u043c\u043d\u0435 \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u0432.<\/p>\n<p> \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438\u043d\u0433\u0430 \u0431\u044b\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u2014 \u043e\u0442 1 \u0434\u043e 100 000;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u2014 \u043e\u0442 10 \u0434\u043e 1000;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 \u043a\u0430\u0436\u0434\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432 \u201410.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u0430 benchstat. \u041e\u043d\u0430 \u0435\u0441\u0442\u044c \u0442\u0443\u0442: <a href=\"https:\/\/cs.opensource.google\/go\/x\/perf\">https:\/\/cs.opensource.google\/go\/x\/perf<\/a>.<\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438\u043d\u0433\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (sec\/op \u2014 \u0441\u0435\u043a\u0443\u043d\u0434 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e);<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 (B\/op \u2014 \u0431\u0430\u0439\u0442 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e);<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 (allocs\/op \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e).<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/h4>\n<pre><code>                                                           \u2502 semaphore.txt \u2502               workerpool.txt               \u2502                                                            \u2502    sec\/op     \u2502     sec\/op       vs base                   \u2502 DeactivateUsers\/input_size_1_goroutines_count_10-10           713.2n \u00b1  0%     4030.5n \u00b1  1%    +465.09% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_10-10          5.752\u00b5 \u00b1  1%      7.236\u00b5 \u00b1  0%     +25.80% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_10-10         47.49\u00b5 \u00b1  4%      41.69\u00b5 \u00b1  0%     -12.21% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_10-10        496.2\u00b5 \u00b1 20%      386.6\u00b5 \u00b1  1%     -22.09% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_10-10       4.567m \u00b1 17%      3.979m \u00b1  1%     -12.86% (p=0.023 n=10) DeactivateUsers\/input_size_100000_goroutines_count_10-10      67.03m \u00b1  2%      39.95m \u00b1  1%     -40.41% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_100-10          708.9n \u00b1  0%    19625.0n \u00b1  2%   +2668.18% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_100-10         5.763\u00b5 \u00b1  1%     20.340\u00b5 \u00b1  2%    +252.96% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_100-10        47.32\u00b5 \u00b1  2%      58.72\u00b5 \u00b1  1%     +24.10% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_100-10       490.4\u00b5 \u00b1  8%      466.2\u00b5 \u00b1 26%           ~ (p=0.436 n=10) DeactivateUsers\/input_size_10000_goroutines_count_100-10      4.998m \u00b1 19%      4.812m \u00b1  6%           ~ (p=0.218 n=10) DeactivateUsers\/input_size_100000_goroutines_count_100-10     66.58m \u00b1  2%      58.71m \u00b1  5%     -11.81% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_1000-10         707.2n \u00b1  0%   317225.0n \u00b1  4%  +44756.48% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_1000-10        5.760\u00b5 \u00b1  1%    309.622\u00b5 \u00b1  4%   +5275.85% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_1000-10       48.93\u00b5 \u00b1  4%     324.29\u00b5 \u00b1 14%    +562.82% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_1000-10      518.3\u00b5 \u00b1 12%      636.7\u00b5 \u00b1 14%     +22.84% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_1000-10     4.301m \u00b1 14%      4.728m \u00b1 16%           ~ (p=0.529 n=10) DeactivateUsers\/input_size_100000_goroutines_count_1000-10    67.48m \u00b1  3%      69.69m \u00b1 19%           ~ (p=1.000 n=10) <\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0434\u0430\u0447, \u0442\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0443 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0430 1\u20133 \u043f\u043e\u0440\u044f\u0434\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0434\u0430\u0447, \u0442\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0432 \u0442\u0435\u0445 \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430\u0445, \u0445\u043e\u0442\u044f \u0438 Worker pool \u0431\u044b\u0441\u0442\u0440\u0435\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043e\u0442 100 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0442\u0443\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0443 Worker pool, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0443 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438<\/h4>\n<pre><code>                                                           \u2502 semaphore.txt \u2502             workerpool.txt              \u2502                                                            \u2502     B\/op      \u2502     B\/op       vs base                  \u2502 DeactivateUsers\/input_size_1_goroutines_count_10-10             552.0 \u00b1 0%      688.0 \u00b1 0%    +24.64% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_10-10          2.695Ki \u00b1 0%    1.172Ki \u00b1 0%    -56.52% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_10-10        25.227Ki \u00b1 0%    6.609Ki \u00b1 0%    -73.80% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_10-10       237.66Ki \u00b1 0%    56.61Ki \u00b1 0%    -76.18% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_10-10      2350.1Ki \u00b1 0%    552.6Ki \u00b1 0%    -76.48% (p=0.000 n=10) DeactivateUsers\/input_size_100000_goroutines_count_10-10     22.892Mi \u00b1 0%    5.344Mi \u00b1 0%    -76.65% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_100-10            552.0 \u00b1 0%     3568.0 \u00b1 0%   +546.38% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_100-10         2.695Ki \u00b1 0%    3.984Ki \u00b1 0%    +47.83% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_100-10       25.227Ki \u00b1 0%    9.424Ki \u00b1 0%    -62.64% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_100-10      237.66Ki \u00b1 0%    59.43Ki \u00b1 0%    -74.99% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_100-10     2350.0Ki \u00b1 0%    555.5Ki \u00b1 0%    -76.36% (p=0.000 n=10) DeactivateUsers\/input_size_100000_goroutines_count_100-10    22.892Mi \u00b1 0%    5.347Mi \u00b1 0%    -76.64% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_1000-10           552.0 \u00b1 0%    32371.5 \u00b1 0%  +5764.40% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_1000-10        2.695Ki \u00b1 0%   32.115Ki \u00b1 0%  +1091.52% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_1000-10       25.23Ki \u00b1 0%    37.58Ki \u00b1 0%    +48.95% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_1000-10     237.66Ki \u00b1 0%    87.60Ki \u00b1 0%    -63.14% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_1000-10    2350.0Ki \u00b1 0%    583.9Ki \u00b1 0%    -75.15% (p=0.000 n=10) DeactivateUsers\/input_size_100000_goroutines_count_1000-10   22.892Mi \u00b1 0%    5.378Mi \u00b1 0%    -76.51% (p=0.000 n=10) <\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0434\u0430\u0447, \u0442\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0443 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u043c\u0435\u043d\u044c\u0448\u0435, \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432\u044b\u0448\u043b\u0430 \u043d\u0430 1\u20132 \u043f\u043e\u0440\u044f\u0434\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0434\u0430\u0447, \u0442\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0443 Worker pool \u043c\u0435\u043d\u044c\u0448\u0435, \u043d\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 1 \u043f\u043e\u0440\u044f\u0434\u043e\u043a.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439<\/h4>\n<pre><code>                                                           \u2502 semaphore.txt  \u2502              workerpool.txt              \u2502                                                            \u2502   allocs\/op    \u2502   allocs\/op    vs base                   \u2502 DeactivateUsers\/input_size_1_goroutines_count_10-10              8.000 \u00b1 0%     16.000 \u00b1 0%    +100.00% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_10-10             26.00 \u00b1 0%      16.00 \u00b1 0%     -38.46% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_10-10           206.00 \u00b1 0%      16.00 \u00b1 0%     -92.23% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_10-10         2006.00 \u00b1 0%      16.00 \u00b1 0%     -99.20% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_10-10       20006.00 \u00b1 0%      16.00 \u00b1 0%     -99.92% (p=0.000 n=10) DeactivateUsers\/input_size_100000_goroutines_count_10-10     200006.00 \u00b1 0%      16.00 \u00b1 0%     -99.99% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_100-10             8.000 \u00b1 0%    106.000 \u00b1 0%   +1225.00% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_100-10            26.00 \u00b1 0%     106.00 \u00b1 0%    +307.69% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_100-10           206.0 \u00b1 0%      106.0 \u00b1 0%     -48.54% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_100-10         2006.0 \u00b1 0%      106.0 \u00b1 0%     -94.72% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_100-10       20006.0 \u00b1 0%      106.0 \u00b1 1%     -99.47% (p=0.000 n=10) DeactivateUsers\/input_size_100000_goroutines_count_100-10     200006.0 \u00b1 0%      108.5 \u00b1 2%     -99.95% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_1000-10            8.000 \u00b1 0%   1006.000 \u00b1 0%  +12475.00% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_1000-10           26.00 \u00b1 0%    1006.00 \u00b1 0%   +3769.23% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_1000-10          206.0 \u00b1 0%     1006.0 \u00b1 0%    +388.35% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_1000-10        2.006k \u00b1 0%     1.006k \u00b1 0%     -49.85% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_1000-10      20.006k \u00b1 0%     1.010k \u00b1 0%     -94.95% (p=0.000 n=10) DeactivateUsers\/input_size_100000_goroutines_count_1000-10    200.006k \u00b1 0%     1.040k \u00b1 1%     -99.48% (p=0.000 n=10) <\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0440\u0430\u0441\u0442\u0451\u0442 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0437\u0430\u0434\u0430\u0447 (\u0438 \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0443) \u0432 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e \u0434\u043b\u044f Worker pool \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0412\u044b\u0432\u043e\u0434\u044b<\/h3>\n<p>\u041f\u043e \u0445\u043e\u0434\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438: \u0441\u0435\u043c\u0430\u0444\u043e\u0440 (Semaphore) \u0438 \u043f\u0443\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Worker pool).<\/p>\n<p>\u041f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043d\u0430 \u0432\u044b\u0431\u043e\u0440. \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438\u043d\u0433\u0430, \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0442\u0440\u0430\u0442\u0430\u0445 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 (\u0432 \u0440\u0430\u0439\u043e\u043d\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430). \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043e\u0449\u0443\u0442\u0438\u043c\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447 \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0435\u043c \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0443 \u043a\u043e\u0433\u043e-\u0442\u043e \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0447\u0451\u0442\u043a\u043e \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0438 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/github.com\/perfectgentlemande\/go-semaphore-vs-worker-pool\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/755072\/\"> https:\/\/habr.com\/ru\/articles\/755072\/<\/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<figure class=\"full-width\"><\/figure>\n<h2>\u0423\u0447\u0438\u043c\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c Semaphore \u0438 Worker Pool \u043d\u0430 Go<\/h2>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u042f \u0410\u0440\u0442\u0451\u043c \u0427\u0430\u0430\u0434\u0430\u0435\u0432 \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0430\u0441\u0441\u043e\u0440\u0442\u0438\u043c\u0435\u043d\u0442\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u0422\u0443\u0442\u0443 \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Go.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Go, \u043e\u0434\u043d\u0430\u043a\u043e \u0431\u0435\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u044e\u0442 \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0435\u0448\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u0443\u044e \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0434\u0435\u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u043c API (\u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438). \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0432\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Go: \u0441\u0435\u043c\u0430\u0444\u043e\u0440 (Semaphore) \u0438 \u043f\u0443\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Worker pool).<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b\u044f\u0441\u043d\u0438\u043c \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043e\u0431\u043e\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a-\u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<h3>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 1 \u0434\u043e 100 000, \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e Deactivate. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0443\u0442\u0451\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 API (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u0447\u043a\u0430\u043c\u0438) \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441 \u0435\u0433\u043e ID \u0438 \u043a\u0430\u043a\u0438\u043c\u0438-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u0430\u0451\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b. \u041f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0430\u0439\u043c-\u0430\u0443\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 * \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u042d\u0442\u043e \u0434\u0430\u0441\u0442 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0439 \u0440\u043e\u0441\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u044f\u0437\u044b\u043a\u0430 Go, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u044b \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438: \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438, \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c\u0438, WaitGroup, \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438. \u0426\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u0441 \u0441 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u0441\u0435\u043c\u0430\u0444\u043e\u0440 (Semaphore);<\/p>\n<\/li>\n<li>\n<p>\u043f\u0443\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Worker pool).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043d\u0435 \u0443\u0447\u0442\u0435\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043f\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445.<\/p>\n<p>\u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 (\u0432 \u0441\u0432\u043e\u0451 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u0441 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438 \u0432 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u044d\u0442\u043e \u043c\u0435\u043d\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u043e) \u044f \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<h3>\u0421\u0435\u043c\u0430\u0444\u043e\u0440 (Semaphore)<\/h3>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f, \u043f\u043e \u0441\u0443\u0442\u0438, \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d. \u0418\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Semaphore, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0431\u0443\u0444\u0435\u0440 \u043a\u0430\u043d\u0430\u043b\u0430 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d, \u0442\u043e \u043f\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 Acquire \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0431\u0443\u0444\u0435\u0440 \u043d\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 Release.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043d\u0430\u043b, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 (\u0437\u0434\u0435\u0441\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0442\u043e\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f main).<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"go\">type Semaphore struct { C chan struct{} }  func (s *Semaphore) Acquire() { s.C &lt;- struct{}{} }  func (s *Semaphore) Release() { &lt;-s.C }  type resultWithError struct { User users.User Err  error }  func DeactivateUsers(usrs []users.User, gCount int) ([]users.User, error) { \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u043a\u0430\u043d\u0430\u043b \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0431\u0443\u0444\u0435\u0440\u0430 \u0440\u0430\u0432\u043d\u044b\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044e \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d sem := Semaphore{ C: make(chan struct{}, gCount), }  \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 outputCh := make(chan resultWithError, len(usrs)) \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u0433\u043e\u0440\u0443\u0442\u0438\u043d, \u0447\u0442\u043e \u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0436\u0434\u0435\u043c \u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f sgnlCh := make(chan struct{})  output := make([]users.User, 0, len(usrs))  for _, v := range usrs { go func(usr users.User) { sem.Acquire() defer sem.Release()  err := usr.Deactivate()  \/\/ \u0435\u0441\u043b\u0438 \u043b\u043e\u0432\u0438\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430, \u0442\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e select { case outputCh &lt;- resultWithError{ User: usr, Err:  err, }: case &lt;-sgnlCh: return } }(v) }  \/\/ \u0436\u0434\u0435\u043c \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \/\/ \u043b\u0438\u0431\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u0441\u0435, \u043b\u0438\u0431\u043e \u0432\u044b\u0439\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c for i := len(usrs); i > 0; i-- { res := &lt;-outputCh if res.Err != nil { close(sgnlCh) return nil, fmt.Errorf(\"an error occurred: %w\", res.Err) }  output = append(output, res.User) }  return output, nil }  <\/code><\/pre>\n<h3>\u041f\u0443\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (Worker pool)<\/h3>\n<p>\u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0442\u043d\u0438 \u0442\u044b\u0441\u044f\u0447 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043f\u0440\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0447\u0438\u0442\u0430\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u043a\u0430\u043d\u0430\u043b \u0441 \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u0443\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u0437\u0430\u043a\u0440\u043e\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0435 (\u0437\u0434\u0435\u0441\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0442\u043e\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f) \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"go\"> type resultWithError struct { User users.User Err  error }  func deactivateUser(wg *sync.WaitGroup, inCh &lt;-chan users.User, outCh chan&lt;- resultWithError) { defer wg.Done()  for usr := range inCh { err := usr.Deactivate() outCh &lt;- resultWithError{ User: usr, Err:  err, } } }  func DeactivateUsers(usrs []users.User, wgCount int) ([]users.User, error) { \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d\u0430\u043c inputCh := make(chan users.User) \/\/ \u043a\u0430\u043d\u0430\u043b \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 outputCh := make(chan resultWithError) \/\/ \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d wg := &amp;sync.WaitGroup{}  output := make([]users.User, 0, len(usrs))  go func() { defer close(inputCh)  for i := range usrs { inputCh &lt;- usrs[i] } }()  go func() { for i := 0; i &lt; wgCount; i++ { wg.Add(1)  go deactivateUser(wg, inputCh, outputCh) } wg.Wait() close(outputCh) }()  \/\/ \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b for res := range outputCh { if res.Err != nil { return nil, fmt.Errorf(\"an error occurred: %w\", res.Err) }  output = append(output, res.User) }  return output, nil } <\/code><\/pre>\n<h3>\u0411\u0435\u043d\u0447\u0438\u043c<\/h3>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u0441\u0442\u0430\u0442\u044c\u0451\u0439 \u043c\u043d\u0435 \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u0432.<\/p>\n<p> \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438\u043d\u0433\u0430 \u0431\u044b\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u2014 \u043e\u0442 1 \u0434\u043e 100 000;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u2014 \u043e\u0442 10 \u0434\u043e 1000;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 \u043a\u0430\u0436\u0434\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432 \u201410.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u0430 benchstat. \u041e\u043d\u0430 \u0435\u0441\u0442\u044c \u0442\u0443\u0442: <a href=\"https:\/\/cs.opensource.google\/go\/x\/perf\">https:\/\/cs.opensource.google\/go\/x\/perf<\/a>.<\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438\u043d\u0433\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (sec\/op \u2014 \u0441\u0435\u043a\u0443\u043d\u0434 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e);<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 (B\/op \u2014 \u0431\u0430\u0439\u0442 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e);<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 (allocs\/op \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e).<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/h4>\n<pre><code>                                                           \u2502 semaphore.txt \u2502               workerpool.txt               \u2502                                                            \u2502    sec\/op     \u2502     sec\/op       vs base                   \u2502 DeactivateUsers\/input_size_1_goroutines_count_10-10           713.2n \u00b1  0%     4030.5n \u00b1  1%    +465.09% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_10-10          5.752\u00b5 \u00b1  1%      7.236\u00b5 \u00b1  0%     +25.80% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_10-10         47.49\u00b5 \u00b1  4%      41.69\u00b5 \u00b1  0%     -12.21% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_10-10        496.2\u00b5 \u00b1 20%      386.6\u00b5 \u00b1  1%     -22.09% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_10-10       4.567m \u00b1 17%      3.979m \u00b1  1%     -12.86% (p=0.023 n=10) DeactivateUsers\/input_size_100000_goroutines_count_10-10      67.03m \u00b1  2%      39.95m \u00b1  1%     -40.41% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_100-10          708.9n \u00b1  0%    19625.0n \u00b1  2%   +2668.18% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_100-10         5.763\u00b5 \u00b1  1%     20.340\u00b5 \u00b1  2%    +252.96% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_100-10        47.32\u00b5 \u00b1  2%      58.72\u00b5 \u00b1  1%     +24.10% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_100-10       490.4\u00b5 \u00b1  8%      466.2\u00b5 \u00b1 26%           ~ (p=0.436 n=10) DeactivateUsers\/input_size_10000_goroutines_count_100-10      4.998m \u00b1 19%      4.812m \u00b1  6%           ~ (p=0.218 n=10) DeactivateUsers\/input_size_100000_goroutines_count_100-10     66.58m \u00b1  2%      58.71m \u00b1  5%     -11.81% (p=0.000 n=10) DeactivateUsers\/input_size_1_goroutines_count_1000-10         707.2n \u00b1  0%   317225.0n \u00b1  4%  +44756.48% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_1000-10        5.760\u00b5 \u00b1  1%    309.622\u00b5 \u00b1  4%   +5275.85% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_1000-10       48.93\u00b5 \u00b1  4%     324.29\u00b5 \u00b1 14%    +562.82% (p=0.000 n=10) DeactivateUsers\/input_size_1000_goroutines_count_1000-10      518.3\u00b5 \u00b1 12%      636.7\u00b5 \u00b1 14%     +22.84% (p=0.000 n=10) DeactivateUsers\/input_size_10000_goroutines_count_1000-10     4.301m \u00b1 14%      4.728m \u00b1 16%           ~ (p=0.529 n=10) DeactivateUsers\/input_size_100000_goroutines_count_1000-10    67.48m \u00b1  3%      69.69m \u00b1 19%           ~ (p=1.000 n=10) <\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0434\u0430\u0447, \u0442\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0443 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0430 1\u20133 \u043f\u043e\u0440\u044f\u0434\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0433\u0434\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0434\u0430\u0447, \u0442\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0432 \u0442\u0435\u0445 \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0430\u0445, \u0445\u043e\u0442\u044f \u0438 Worker pool \u0431\u044b\u0441\u0442\u0440\u0435\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0433\u043e\u0440\u0443\u0442\u0438\u043d \u043e\u0442 100 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0442\u0443\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0443 Worker pool, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0443 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0442\u0440\u0430\u0442 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438<\/h4>\n<pre><code>                                                           \u2502 semaphore.txt \u2502             workerpool.txt              \u2502                                                            \u2502     B\/op      \u2502     B\/op       vs base                  \u2502 DeactivateUsers\/input_size_1_goroutines_count_10-10             552.0 \u00b1 0%      688.0 \u00b1 0%    +24.64% (p=0.000 n=10) DeactivateUsers\/input_size_10_goroutines_count_10-10          2.695Ki \u00b1 0%    1.172Ki \u00b1 0%    -56.52% (p=0.000 n=10) DeactivateUsers\/input_size_100_goroutines_count_10-10        25.227Ki \u00b1 0%    6.609Ki \u00b1 0%    -73.80% (p=0.000 n=10)<\/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-352380","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352380","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=352380"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/352380\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}