{"id":296756,"date":"2020-01-04T21:00:23","date_gmt":"2020-01-04T21:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=296756"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=296756","title":{"rendered":"Multiprocessing \u0438 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/480076\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! <\/p>\n<p>  \u0412 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043c\u043d\u043e\u0433\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432\u044b\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u044b\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u043c \u043d\u0435\u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0432\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043c\u0430\u043b\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0438 \u043c\u0435\u0442\u043e\u0434\u0438\u043a, \u0430 \u043c\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u0438, \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u0438 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b <a href=\"https:\/\/habr.com\/ru\/post\/428443\/\">\u0432\u043e\u0442 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/a> \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u0434 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u044a\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u0435\u0439\u0441 \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u043c-\u0434\u043e\u0431\u0440\u043e\u043c Python \u2014 \u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c! \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ic\/zx\/hg\/iczxhgu9zvlumwggetuoblxm1ra.jpeg\"><\/div>\n<p>  <a href=\"https:\/\/www.megapixl.com\/alexdobysh-stock-images-videos-portfolio\">(\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438)<\/a><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u0430\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u0438 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0432 \u044d\u0442\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. <\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 PostgreSQL. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u044d\u0442\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u0445, \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0432\u0435\u0440\u0438\u0442\u044c \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u044b\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430.<\/p>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u0439 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u043e\u0434 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u044a\u0435\u043c, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0432 multiprocessing.<\/p>\n<p>  \u041c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/docs.python.org\/dev\/library\/multiprocessing.html\">multiprocessing <\/a>\u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 Python \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 GIL. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u0435\u0435.<\/p>\n<h2>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/h2>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/zl\/-t\/pu\/zl-tpusgp5fzypzmuonycvloghi.png\"><\/div>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li><b>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/b> \u2013 Python-\u0441\u043a\u0440\u0438\u043f\u0442, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0438\u0439 CSV \u0444\u0430\u0439\u043b \u0438 \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445;<\/li>\n<li><b>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/b> \u2013 CSV-\u0444\u0430\u0439\u043b \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432 \u0411\u0414 PostgreSQL;<\/li>\n<li><b>\u0410\u0434\u0430\u043f\u0442\u0435\u0440\u044b<\/b> \u2013 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0432\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 (CSV \u0438\u043b\u0438 \u0411\u0414) \u0438 \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u0443\u044e \u0411\u0414;<\/li>\n<li><b>\u0411\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/b> \u2013 \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0435\u0445 \u0448\u0442\u0443\u043a: \u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u0430\u044f \u0411\u0414, \u0445\u0440\u0430\u043d\u044f\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441\u043d\u044f\u0442\u0443\u044e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430\u043c\u0438, \u0438 \u00ab\u0447\u0438\u0441\u0442\u0430\u044f\u00bb \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0432 \u0441\u0435\u0431\u0435 \u0441\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438\u0437 \u043e\u0431\u043e\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432.<\/li>\n<\/ul>\n<p>  <\/p>\n<h2>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/hub.docker.com\/_\/postgres\">\u0411\u0414 PostgreSQL \u0432 Docker-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435<\/a> \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/hub.docker.com\/r\/dpage\/pgadmin4\/\">pgAdmin, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435<\/a>:<\/p>\n<pre><code class=\"bash\">docker run --name pg -d -e \"POSTGRES_USER=my_user\" -e \"POSTGRES_PASSWORD=my_password\" postgres<\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a pgAdmin:<\/p>\n<pre><code class=\"bash\">docker run -p 80:80 -e \"PGADMIN_DEFAULT_EMAIL=user@domain.com\" -e \"PGADMIN_DEFAULT_PASSWORD=12345\" -d dpage\/pgadmin4<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u0441\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u043e\u0441\u044c, \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 (conf\/db.ini) \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414 (\u0434\u043b\u044f \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e!):<\/p>\n<pre><code class=\"bash\">[POSTGRESQL] db_url=postgresql:\/\/my_user:my_password@172.17.0.2:5432\/my_user <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0411\u0414.<\/p>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>  \u0417\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 Python-\u0441\u043a\u0440\u0438\u043f\u0442 <b>generate_test_data<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438. \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043f\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 <b>GenerateTestData<\/b>:<\/p>\n<pre><code class=\"python\">    @m.timing     def run(self, num_rows):         \"\"\" Run the process \"\"\"         m.info('START!')         self.create_db_schema()         self.create_folder('data')         self.create_csv_file(num_rows)         self.bulk_copy_to_db()         self.random_delete_rows()         self.random_update_rows()         m.info('END!')<\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ul>\n<li>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0445\u0435\u043c \u0432 \u0411\u0414 (\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0441\u0445\u0435\u043c\u044b \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b);<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0430\u043f\u043a\u0438 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430;<\/li>\n<li>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0442\u0440\u043e\u043a;<\/li>\n<li>Bulk-insert \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 transaction_db_raw.transaction_log;<\/li>\n<li>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435;<\/li>\n<li>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. <\/li>\n<\/ul>\n<p>  \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u043c\u0435\u043b\u0438 \u0445\u043e\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435. \u0412\u0430\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0438\u0441\u043a\u0430\u0442\u044c \u044d\u0442\u0438 \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f!<\/p>\n<pre><code class=\"python\">@m.timing @m.wrapper(m.entering, m.exiting) def random_delete_rows(self):     \"\"\" Random deleting some rows from the table \"\"\"     sql_command = sql.SQL(\"\"\"                     delete from {0}.{1}                     where ctid = any(array(                       select ctid                       from {0}.{1}                       tablesample bernoulli (1)                       ))\"\"\").format(sql.Identifier(self.schema_raw),                                     sql.Identifier(self.raw_table_name))     try:         rows = self.database.execute(sql_command)         m.info('Has been deleted [%s rows] from table %s' % (rows, self.raw_table_name))     except psycopg2.Error as err:         m.error('Oops! Delete random rows has been FAILED. Reason: %s' % err.pgerror)  @m.timing @m.wrapper(m.entering, m.exiting) def random_update_rows(self):     \"\"\" Random update some rows from the table \"\"\"     sql_command = sql.SQL(\"\"\"             update {0}.{1}             set transaction_amount = round(random()::numeric, 2)             where ctid = any(array(               select ctid               from {0}.{1}               tablesample bernoulli (1) ))\"\"\").format(sql.Identifier(self.schema_raw),                                                       sql.Identifier(self.raw_table_name))     try:         rows = self.database.execute(sql_command)         m.info('Has been updated [%s rows] from table %s' % (rows, self.raw_table_name))     except psycopg2.Error as err:         m.error('Oops! Delete random rows has been FAILED. Reason: %s' % err.pgerror)<\/code><\/pre>\n<p>  \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0439 \u0444\u0430\u0439\u043b \u0444\u043e\u0440\u043c\u0430\u0442\u0435 CSV \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 UID \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438;<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 UID \u043d\u043e\u043c\u0435\u0440 \u0441\u0447\u0435\u0442\u0430 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0431\u0435\u0440\u0435\u043c \u0434\u0435\u0441\u044f\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0447\u0435\u0442\u043e\u0432, \u043d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043f\u043e\u043c\u0435\u043d\u044f\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u00abrandom_accounts\u00bb);<\/li>\n<li>\u0414\u0430\u0442\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u2013 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u0430\u044f \u0434\u0430\u0442\u0430 \u043e\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 \u0434\u0430\u0442\u044b (initial_date);<\/li>\n<li>\u0422\u0438\u043f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u0441\u0434\u0435\u043b\u043a\u0430 \/ \u043a\u043e\u043c\u0438\u0441\u0441\u0438\u044f);<\/li>\n<li>\u0421\u0443\u043c\u043c\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438;<\/li>\n<li>\u041e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <i>generate_test_data_by_chunk<\/i> \u043a\u043b\u0430\u0441\u0441\u0430 <b>TestDataCreator<\/b>:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"python\">@m.timing def generate_test_data_by_chunk(self, chunk_start, chunk_end):     \"\"\" Generating and saving to the file \"\"\"     num_rows_mp = chunk_end - chunk_start     new_rows = []      for _ in range(num_rows_mp):         transaction_uid = uuid.uuid4()         account_uid = choice(self.list_acc)         transaction_date = (self.get_random_date(self.date_in, 0)                             .__next__()                             .strftime('%Y-%m-%d %H:%M:%S'))         type_deal = choice(self.list_type_deal)         transaction_amount = randint(-1000, 1000)          new_rows.append([transaction_uid,                          account_uid,                          transaction_date,                          type_deal,                          transaction_amount])      self.write_in_file(new_rows, chunk_start, chunk_end)<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u0437\u0430\u043f\u0443\u0441\u043a \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0433\u0435\u043d\u0435\u0440\u0438\u0442 \u0441\u0432\u043e\u044e \u043f\u043e\u0440\u0446\u0438\u044e \u0438\u0437 50\u041a \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u042d\u0442\u0430 \u00ab\u0444\u0438\u0448\u043a\u0430\u00bb \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0441\u0442\u0440\u043e\u043a \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"python\">def run_csv_writing(self):     \"\"\" Writing the test data into csv file \"\"\"     pool = mp.Pool(mp.cpu_count())     jobs = []      for chunk_start, chunk_end in self.divide_into_chunks(0, self.num_rows):         jobs.append(pool.apply_async(self.generate_test_data_by_chunk,                                      (chunk_start, chunk_end)))     # wait for all jobs to finish     for job in jobs:         job.get()      # clean up     pool.close()     pool.join()<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 bulk_insert \u0438 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <b>transaction_db_raw.transaction_log.<\/b><\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435, \u0432 \u0434\u0432\u0443\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u0445 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u044f \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 CSV-\u0444\u0430\u0439\u043b \u0441 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c\u0438 \u043d\u0430 10\u041a \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"bash\">.\/generate_test_data.py 10000<\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/4c\/cp\/hm\/4ccphmc5dcjcgxuy54p_9limlz4.png\"><\/div>\n<p>  \u041d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0444\u0430\u0439\u043b \u043d\u0430 10\u041a \u0441\u0442\u0440\u043e\u043a, \u0432 \u0411\u0414 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e 10\u041a, \u043d\u043e \u0437\u0430\u0442\u0435\u043c \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u043e 112 \u0441\u0442\u0440\u043e\u043a \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e \u0435\u0449\u0435 108. \u0418\u0442\u043e\u0433: \u0444\u0430\u0439\u043b \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432 \u0411\u0414 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u043d\u0430 220 \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<p>  \u00ab\u041d\u0443 \u0438 \u0433\u0434\u0435 \u0442\u0443\u0442 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433?\u00bb, \u2014 \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b. <br \/>  \u0410 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u043f\u043e\u0431\u043e\u043b\u044c\u0448\u0435, \u043d\u0435 \u043d\u0430 10\u041a \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0430, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043d\u0430 1M. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c?<\/p>\n<pre><code class=\"bash\">.\/generate_test_data.py 1000000<\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/rw\/_a\/ne\/rw_aneqnairixqk-wglpqxgjvkc.png\"><\/div>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0432\u0438\u0434\u0438\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043e\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u044b: 19 939 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0438\u0437 \u043d\u0438\u0445 10 022 \u0443\u0434\u0430\u043b\u0435\u043d\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0430 9 917 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e).<\/p>\n<blockquote><p>\u041d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0448\u043b\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u043d\u0435\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c\u0441\u044f \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f. \u041d\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0447\u0442\u043e \u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410 \u044d\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435?<\/b><\/p>\n<div class=\"spoiler_text\">\u041e\u0434\u0438\u043d \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0441\u0442\u0440\u043e\u043a \u043d\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u0439 \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0431\u044b\u043b \u00ab\u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u00bb \u0437\u0430 15.5 \u0441\u0435\u043a\u0443\u043d\u0434 \u2014 \u0438 \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u044d\u0442\u0443 \u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0430, \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0448\u043b\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 \u0442\u0440\u0438 \u0440\u0430\u0437\u0430 (\u0441\u0432\u044b\u0448\u0435 52 \u0441\u0435\u043a\u0443\u043d\u0434 \u0432\u043c\u0435\u0441\u0442\u043e 15,5):<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/sb\/kb\/ck\/sbkbckylzluoyyslyflwak5udrq.png\"><\/div>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h2>\u0410\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u043b\u044f CSV<\/h2>\n<p>  \u042d\u0442\u043e\u0442 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0445\u044d\u0448\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u2013 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b <i>data\/ transaction_hashed.csv<\/i>. \u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b COPY \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u0445\u0435\u043c\u044b <b>reconciliation_db. <\/b><\/p>\n<p>  \u041e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u0427\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e, \u043a\u0443\u0441\u043a\u0430\u043c\u0438 \u043f\u043e 5 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442 \u043a\u0430\u0436\u0434\u044b\u0439. \u0426\u0438\u0444\u0440\u0430 \u00ab5 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442\u00bb \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u0442\u0435\u043a\u0441\u0442\u0430, \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0435\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"python\">@m.timing def process_wrapper(self, chunk_start, chunk_size):     \"\"\" Read a particular chunk \"\"\"     with open(self.file_name_raw, newline='\\n') as file:         file.seek(chunk_start)         lines = file.read(chunk_size).splitlines()         for line in lines:             self.process(line)  def chunkify(self, size=1024*1024*5):     \"\"\" Return a new chunk \"\"\"     with open(self.file_name_raw, 'rb') as file:         chunk_end = file.tell()         while True:             chunk_start = chunk_end             file.seek(size, 1)             file.readline()             chunk_end = file.tell()              if chunk_end &gt; self.file_end:                 chunk_end = self.file_end                 yield chunk_start, chunk_end - chunk_start                 break             else:                 yield chunk_start, chunk_end - chunk_start  @m.timing def run_reading(self):     \"\"\" The main method for the reading \"\"\"     # init objects     pool = mp.Pool(mp.cpu_count())     jobs = []      m.info('Run csv reading...')     # create jobs     for chunk_start, chunk_size in self.chunkify():         jobs.append(pool.apply_async(self.process_wrapper,                                      (chunk_start, chunk_size)))      # wait for all jobs to finish     for job in jobs:         job.get()      # clean up     pool.close()     pool.join()      m.info('CSV file reading has been completed')<\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0447\u0442\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 1\u041c \u0437\u0430\u043f\u0438\u0441\u0435\u0439:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/9p\/z1\/zr\/9pz1zrkzeelnep_r8oppk0sxhok.png\"><\/div>\n<p>  \u041d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u0438. \u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e \u0447\u0430\u0441\u0442\u044f\u043c \u0438 \u0432\u0437\u044f\u0442\u0438\u0435 \u0445\u044d\u0448\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0432 \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u043c.  <\/p>\n<blockquote><p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0432\u0435\u0440\u043a\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p><\/blockquote>\n<p>  <\/p>\n<h2>\u0410\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u043b\u044f PostgreSQL<\/h2>\n<p>  \u0410\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e \u0442\u043e\u0439 \u0436\u0435 \u043b\u043e\u0433\u0438\u043a\u0435, \u0447\u0442\u043e \u0438 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430:<\/p>\n<ul>\n<li>\u0447\u0442\u0435\u043d\u0438\u0435 \u043f\u043e \u0447\u0430\u0441\u0442\u044f\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b (\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f, \u0441\u0432\u044b\u0448\u0435 100\u041a \u0437\u0430\u043f\u0438\u0441\u0435\u0439) \u0438 \u0432\u0437\u044f\u0442\u0438\u0435 \u0445\u044d\u0448\u0430 \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c, \u043a\u0440\u043e\u043c\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438;<\/li>\n<li>\u0437\u0430\u0442\u0435\u043c \u0438\u0434\u0435\u0442 \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <b>reconciliation_db. storage_$(int(time.time())<\/b>.<\/li>\n<\/ul>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0443\u043b \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0445. <\/p>\n<p>  \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0434\u0435\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 10 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<pre><code class=\"python\">def read_data(self):     \"\"\"     Read the data from the postgres and shared those records with each     processor to perform their operation using threads     \"\"\"     threads_array = self.get_threads(0,                                      self.max_id_num_row,                                      self.pid_max)      for pid in range(1, len(threads_array) + 1):         m.info('Process %s' % pid)          # Getting connection from the connection pool         select_conn = self._select_conn_pool.getconn()         select_conn.autocommit = 1          # Creating 10 process to perform the operation         process = Process(target=self.process_data,                           args=(self.data_queque,                                 pid,                                 threads_array[pid-1][0],                                 threads_array[pid-1][1],                                 select_conn))          process.daemon = True         process.start()         process.join()         select_conn.close()<\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pw\/kt\/kk\/pwktkkisxg3sud4dyss_gtyi4gy.png\"><\/div>\n<p>  <\/p>\n<h2>\u041f\u043e\u0438\u0441\u043a \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439<\/h2>\n<p>  \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u0432\u0435\u0440\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0442 \u0434\u0432\u0443\u0445 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u0432.<\/p>\n<p>  \u0421\u0432\u0435\u0440\u043a\u0430 (\u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0447\u0435\u0442\u0430 \u043e \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f\u0445) \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0441\u044e \u043c\u043e\u0449\u044c \u044f\u0437\u044b\u043a\u0430 SQL.<\/p>\n<p>  SQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0439 \u2013 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0434\u0436\u043e\u0439\u043d \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e\u0442 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u0432 \u0441\u0430\u043c\u043e\u0439 \u043d\u0430 \u0441\u0435\u0431\u044f \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">sql_command = sql.SQL(\"\"\"     select         s1.adapter_name,         count(s1.transaction_uid) as tran_count     from {0}.{1} s1     full join {0}.{1} s2         on s2.transaction_uid = s1.transaction_uid         and s2.adapter_name != s1.adapter_name         and s2.hash = s1.hash     where s2.transaction_uid is null     group by s1.adapter_name;\"\"\").format(sql.Identifier(self.schema_target),                                          sql.Identifier(self.storage_table)) <\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0447\u0435\u0442:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/5c\/ou\/gy\/5cougys1gkflsplq2hvkoleooto.png\"><\/div>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0432\u0441\u0435 \u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0432\u044b\u0448\u0435. \u041c\u044b \u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0411\u0414 \u0431\u044b\u043b\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u043e 9917 \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e 10 022 \u0441\u0442\u0440\u043e\u043a. \u0418\u0442\u043e\u0433\u043e 19939 \u0441\u0442\u0440\u043e\u043a, \u0447\u0442\u043e \u0438 \u0432\u0438\u0434\u043d\u043e \u0432 \u043e\u0442\u0447\u0435\u0442\u0435.<\/p>\n<h2>\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430<\/h2>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443-\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u00ab\u0447\u0438\u0441\u0442\u044b\u0435\u00bb \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c (\u043f\u043e \u0445\u044d\u0448\u0443) \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430\u0445. \u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c:<\/p>\n<pre><code class=\"python\">sql_command = sql.SQL(\"\"\"     with reconcil_data as (         select             s1.transaction_uid         from {0}.{1} s1         join {0}.{1} s2             on s2.transaction_uid = s1.transaction_uid             and s2.adapter_name != s1.adapter_name         where s2.hash = s1.hash             and s1.adapter_name = 'postresql_adapter'     )     insert into {2}.transaction_log     select         t.transaction_uid,         t.account_uid,         t.transaction_date,         t.type_deal,         t.transaction_amount     from {3}.transaction_log t     join reconcil_data r         on t.transaction_uid = r.transaction_uid     where not exists         (             select 1             from {2}.transaction_log tl             where tl.transaction_uid = t.transaction_uid         )     \"\"\").format(sql.Identifier(self.schema_target),                 sql.Identifier(self.storage_table),                 sql.Identifier(self.schema_db_clean),                 sql.Identifier(self.schema_raw)) <\/code><\/pre>\n<p>  \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u0432, \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/uq\/sr\/te\/uqsrte2g0thu2woasaxqojdbc88.png\"><\/div>\n<p>  <\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0412 \u0445\u043e\u0434\u0435 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432: \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043a\u0443\u0448\u0435\u043d\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0442\u0438\u043f\u0430 Apache Spark \u0432\u043a\u0443\u043f\u0435 \u0441 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a \u043f\u0430\u0440\u043a\u0435\u0442\u043d\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0443, \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043c\u043e\u0432. \u041d\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0446\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u2013 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 \u00ab\u0433\u043e\u043b\u043e\u043c\u00bb Python \u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421 \u0447\u0435\u043c \u043c\u044b, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438\u0441\u044c.<\/p>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043b\u0435\u0436\u0438\u0442 <a href=\"https:\/\/github.com\/igorgorbenko\/transact_reconciliation\">\u0432 \u043c\u043e\u0435\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 GitHub<\/a>, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0441 \u043d\u0438\u043c \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  \u0421 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435\u043c \u043e\u0442\u0432\u0435\u0447\u0443 \u043d\u0430 \u0432\u0441\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u044e\u0441\u044c \u0441 \u0432\u0430\u0448\u0438\u043c\u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\u043c\u0438.<\/p>\n<p>  \u0416\u0435\u043b\u0430\u044e \u0443\u0441\u043f\u0435\u0445\u043e\u0432!<\/p><\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <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\/480076\/\"> https:\/\/habr.com\/ru\/post\/480076\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/480076\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! <\/p>\n<p>  \u0412 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043c\u043d\u043e\u0433\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432\u044b\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u044b\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u043c \u043d\u0435\u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0432\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043c\u0430\u043b\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0438 \u043c\u0435\u0442\u043e\u0434\u0438\u043a, \u0430 \u043c\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u0440\u0435\u043a\u043e\u043d\u0441\u0438\u043b\u044f\u0446\u0438\u0438, \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u044b\u043b\u0438 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b <a href=\"https:\/\/habr.com\/ru\/post\/428443\/\">\u0432\u043e\u0442 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/a> \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u0434 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u044a\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u0435\u0439\u0441 \u043d\u0430 \u0441\u0442\u0430\u0440\u043e\u043c-\u0434\u043e\u0431\u0440\u043e\u043c Python \u2014 \u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c! \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ic\/zx\/hg\/iczxhgu9zvlumwggetuoblxm1ra.jpeg\"><\/div>\n<p>  <a href=\"https:\/\/www.megapixl.com\/alexdobysh-stock-images-videos-portfolio\">(\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438)<\/a>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-296756","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296756","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=296756"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296756\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=296756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=296756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=296756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}