{"id":387836,"date":"2024-06-29T07:34:08","date_gmt":"2024-06-29T07:34:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=387836"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=387836","title":{"rendered":"<span>Real-time \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0432 \u0423\u0447\u0438.\u0440\u0443: \u043a\u0430\u043a \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043d\u0434\u0440\u0435\u0439 \u0421\u043a\u0438\u0431\u0430 \u0438 \u044f Python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 ML-\u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0423\u0447\u0438.\u0440\u0443. \u0420\u0430\u0437\u043d\u044b\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0441\u0441\u0438\u0439, DAU \u0438 \u0434\u0440\u0443\u0433\u0438\u043c) \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0432\u043e\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 real-time \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u2014 \u0431\u044b\u0441\u0442\u0440\u0443\u044e, \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0438 \u0441 \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0430\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043e\u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430.\u00a0<\/p>\n<h2>\u041f\u0440\u0438\u0447\u0438\u043d\u044b \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u044b\u043b\u0430 \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0431\u0430\u0437\u0430 Postgres. \u0412 \u043d\u0435\u0433\u043e \u043f\u0438\u0441\u0430\u043b\u0438\u0441\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0442\u0430\u043c \u0436\u0435 \u043e\u043d\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u0432 \u043e\u0442\u0447\u0435\u0442\u044b, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0442\u0440\u043e\u0438\u043b\u0438\u0441\u044c \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435.\u00a0\u041d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u043e \u043c\u0430\u043b\u043e \u0441\u0442\u0440\u043e\u043a. \u042d\u0442\u043e\u0433\u043e \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0423\u0447\u0438.\u0440\u0443 \u043d\u0435 \u0441\u0442\u0430\u043b\u0430 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u043c highload-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u2014 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0447\u0442\u0438 20 \u043c\u043b\u043d \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u0441\u0443\u0442\u043a\u0438.<\/p>\n<p>\u0420\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0438 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0431\u044b\u043b\u043e. \u0422\u0430\u043a\u0436\u0435 \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u043f\u0435\u0440\u0435\u0435\u0445\u0430\u043b\u0430 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0442\u044f\u0436\u0435\u043b\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0433\u0434\u0435 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c ClickHouse, S3, Airflow, Tableau \u0438 \u0440\u044f\u0434 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439. \u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0448\u0438\u0440\u043e\u043a\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0445, \u0435\u0436\u0435\u043c\u0435\u0441\u044f\u0447\u043d\u044b\u0445 \u0438 \u0435\u0436\u0435\u043a\u0432\u0430\u0440\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u0447\u0435\u0442\u043e\u0432 \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441\u0430, \u043d\u043e \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0434\u043b\u044f real-time \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0438 Tableau \u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u0438 \u0438\u043c\u0435\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0441\u043c\u0435\u043d\u044b \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0442\u0435\u043a\u0430, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u0421\u043e\u0431\u044b\u0442\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0435, \u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 Kafka-\u043a\u043b\u0430\u0441\u0442\u0435\u0440. \u0422\u0430\u043a \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0438 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0430\u043c\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0431\u044b\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u0445 \u0438\u0437 Kafka \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u0442 \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043c\u0435\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0443, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0443 \u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439;\u00a0<\/p>\n<\/li>\n<li>\n<p>\u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0447\u0430\u0441\u043e\u0432\u044b\u0435 \u0438 \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0430\u043a\u043e\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u0442\u043e\u0433\u0438.<\/p>\n<\/li>\n<\/ul>\n<h2>\u0421\u0442\u0435\u043a<\/h2>\n<p><strong>\u0411\u044d\u043a\u0435\u043d\u0434<\/strong> \u0443 \u043d\u0430\u0441 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e <strong>\u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Django<\/strong>. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 Django Extensions, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c, \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 django-\u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0423\u0447\u0438.\u0440\u0443 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430, \u0438 \u043b\u044e\u0431\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438\u043b\u0438 \u0432\u043e\u0440\u043a\u0435\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435. \u0412\u043e\u0440\u043a\u0435\u0440\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u0430\u043a \u0440\u0430\u0437 \u0447\u0435\u0440\u0435\u0437 Django Extensions. \u041e\u0431 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u0441\u0430\u043c\u0438\u0445 \u0432\u043e\u0440\u043a\u0435\u0440\u043e\u0432 \u043d\u0430\u043f\u0438\u0448\u0443 \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435.\u00a0<\/p>\n<p><strong>\u0421 Kafka<\/strong> \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <strong>AIOKafka<\/strong>, \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>fastavro \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong>.\u00a0<\/p>\n<p><strong>\u0414\u043b\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Svelte<\/strong>, <strong>\u0433\u0440\u0430\u0444\u0438\u043a\u0438<\/strong> \u0441\u0442\u0440\u043e\u0438\u043c <strong>\u0432 Highcharts JS<\/strong>. \u0414\u043b\u044f <strong>\u0434\u043e\u043b\u0433\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/strong> \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0432 <strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Postgres<\/strong>, \u0430 <strong>\u0432 Redis<\/strong> \u0443 \u043d\u0430\u0441 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0442\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0434\u0430\u043b\u0435\u0435.<\/p>\n<h2>\u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h2>\n<p>\u0418\u0437 Kafka \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u0440\u043a\u0435\u0440 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e KafkaWorker) \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0445, \u043e\u0431\u043e\u0433\u0430\u0449\u0430\u0435\u0442 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 Redis \u0432 \u0432\u0438\u0434\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u0440\u043a\u0435\u0440 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 Redis \u0432 \u0431\u0430\u0437\u0443 \u2014 DB Saver. \u0418 \u0443\u0436\u0435 API \u0447\u0438\u0442\u0430\u0435\u0442 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b \u0438\u0437 Redis \u0438 \u0431\u0430\u0437\u044b, \u043e\u0442\u0434\u0430\u0435\u0442 \u0438\u0445 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434. \u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c08\/730\/554\/c08730554f38e637bbb6921aaa35e1d3.png\" alt=\"\" title=\"\" width=\"771\" height=\"301\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c08\/730\/554\/c08730554f38e637bbb6921aaa35e1d3.png\"\/><\/figure>\n<h2>\u0410\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0441\u0435\u0441\u0441\u0438\u0439<\/h2>\n<p>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u0440\u0430\u0441\u0441\u043a\u0430\u0437 \u0431\u0443\u0434\u0443 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0441\u0435\u0441\u0441\u0438\u0439. \u0412 \u0423\u0447\u0438.\u0440\u0443 <strong>\u0441\u0435\u0441\u0441\u0438\u044f<\/strong> \u2014 \u044d\u0442\u043e <strong>\u0441\u043e\u0431\u044b\u0442\u0438\u0435<\/strong>, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <strong>\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u043d\u0438\u044f<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0434\u0435\u043b\u0430\u043b \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435, \u0432 Kafka \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u0441\u0435\u0441\u0441\u0438\u044f. \u0421\u0440\u0435\u0434\u0438 \u0435\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c: ID \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430, ID \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0438, \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<pre><code class=\"javascript\">{ 'student_id': 43248949, 'subject_id': 46,  'card_id': 443813,  'created_at': '2023-02-22 15:05:43.755000',  'right': 1, 'total': 1, 'spent': 5,  'part_id': 0,  'offset': 17489515 }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0435\u0433\u043e \u043e\u0431\u043e\u0433\u0430\u0442\u0438\u0442\u044c, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0440\u0443\u0433\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043d\u043e \u043d\u0435\u0442, \u043d\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0435\u0433\u043c\u0435\u043d\u0442, \u043a\u043b\u0430\u0441\u0441 \u0438\u043b\u0438 ID \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043b\u0435 <strong>subject_id<\/strong> \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 (\u043d\u043e \u0442\u0430\u043a \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430), \u0430 \u0432\u043e\u0442 <strong>\u043a\u043b\u0430\u0441\u0441<\/strong> \u0438 <strong>\u0441\u0435\u0433\u043c\u0435\u043d\u0442<\/strong> \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e\u00a0\u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c <strong>\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/strong> \u0438\u043b\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h2>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b KafkaWorker<\/h2>\n<p><strong>KafkaWorker<\/strong> \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Kafka \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0445 \u0432 Redis, \u043d\u043e \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0434\u043d\u0430 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u0430\u0445 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u0445\u0435\u043c\u0430\u043c\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432, \u0438 \u0432 \u043d\u0438\u0445 \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0446\u0438\u043a\u043b\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u0412\u043e\u0442 \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0445\u0435\u043c\u044b:\u00a0<\/p>\n<pre><code class=\"javascript\">{ \"name\": \"card_completions\", \"namespace\": \"uchiru\", \"doc\": \"Card completion event\", \"fields\": [ { \"name\": \"id\", \"type\": \"long\" }, { \"name\": \"student_id\", \"type\": \"long\" }, {       \"name\": \"last_activity\",       \"type\": [         {           \"type\": \"long\",           \"logicalType\": \"timestamp-millis\"         },         \"null\"       ] }, ... ] }<\/code><\/pre>\n<pre><code class=\"javascript\">{ \"name\": \"card_completions\", \"namespace\": \"modern_subjects\", \"doc\": \"Card completions for the Modern Subjects\", \"fields\": [ { \"name\": \"student_id\", \"type\": \"string\" }, { \"name\": \"subject_id\", \"type\": \"int\" }, {       \"name\": \"finished_at\",       \"type\": [         {           \"type\": \"long\",           \"logicalType\": \"timestamp-millis\"         },         \"null\"       ] },  ... ] }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u2014 \u044d\u0442\u043e \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u043e\u0431\u0449\u0435\u043c core-\u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435, \u043a\u0430\u0440\u0442\u043e\u0447\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u0430\u0445 \u043f\u043e \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c. \u0412\u0442\u043e\u0440\u0430\u044f \u2014 \u044d\u0442\u043e \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u0445, \u043d\u043e\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u0430\u0445. \u041c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0435\u0441\u0441\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 ID, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0435 \u0437\u0430\u0434\u0432\u0430\u0438\u0432\u0430\u043b\u0438\u0441\u044c. \u0412 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u0445 ID \u043d\u0435\u0442, \u0438 \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0443\u0431\u0438\u0440\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b \u043f\u043e \u0441\u0443\u043c\u043c\u0435 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c: \u043e\u043d\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438.\u0418\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0445\u0435\u043c\u0430\u0445 \u044d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443: \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u2014 <strong>last activity<\/strong>, \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u2014 <strong>finished at<\/strong>. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0432\u0438\u0434\u0443 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043e\u0431\u0449\u0435\u043c\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443 \u0441\u043b\u043e\u0432. \u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a \u0432\u0441\u0435\u0445 \u0441\u0435\u0441\u0441\u0438\u0439, \u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0445 \u0432\u0441\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u0438 \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u0447\u0430\u0441\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u043e\u0432.<\/p>\n<pre><code class=\"python\">topics = { 'uchiru.card_comletions': { 'session_id': 'id', 'last_activity': 'last_activity' }, 'modern_subjects.card_completions': { 'session_id': None, 'last_activity': 'finished_at' }<\/code><\/pre>\n<p>\u041e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 Kafka \u0443 \u043d\u0430\u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435, \u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0434\u043b\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u0430 \u0434\u043b\u044f<strong> <\/strong>\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430. <strong>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u043f\u043e\u043b\u0435\u0439 \u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong> \u0443\u0434\u043e\u0431\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 <strong>\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e callback-\u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/strong>, \u0430 <strong>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong> \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u043e\u0432 <strong>\u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0432 \u0435\u0434\u0438\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong>.<\/p>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0446\u0438\u044f \u0438\u043b\u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 callback-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u043c: \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043a\u044d\u0448\u0430\u0445 Redis, \u0437\u0430 \u043a\u0430\u043a\u0438\u043c\u0438-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443. \u041d\u0438\u0436\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f DAU \u2014 \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043a\u0435\u0439\u0441.\u00a0<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u044f \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0430\u0442 \u0438\u043b\u0438 \u043d\u0430\u0439\u0442\u0438 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439. <strong>\u0410\u0433\u0440\u0435\u0433\u0430\u0442<\/strong> \u2014 \u044d\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 Redis, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 <strong>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong> \u0438\u043b\u0438 <strong>\u0441\u0443\u043c\u043c\u0443<\/strong> \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439) \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0447\u0430\u0441. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044d\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f GROUP BY \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043f\u043e\u043b\u044f\u043c.\u00a0<\/p>\n<p>\u041a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0441\u0430\u043c\u0438 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b? \u0412 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u044b \u0445\u0440\u0430\u043d\u0438\u043c \u0434\u0430\u0442\u0443 \u0438 \u0447\u0430\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443 \u043d\u0430\u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0432 \u043a\u043b\u044e\u0447\u0430\u0445 \u2014 \u043d\u0430\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0441\u0430\u043c\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b\u00a0KafkaWorker.<\/p>\n<pre><code class=\"python\">async def callback_sessions(msg, topic): ...  def consumer_factory(): for topic in topics: yield AsyncKafkaConsumer( topic=t, ... callback=partial(callback_session, topic=t) )  def run(): for c in consumer_factory(): asyncio.ensure_future(c.consume())  loop = asyncio.get_event_loop() loop.run_forever()<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u0435 \u043d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Redis \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c Python. \u0417\u0434\u0435\u0441\u044c \u0434\u043b\u044f \u0441\u0435\u0441\u0441\u0438\u0439 \u0435\u0441\u0442\u044c \u043a\u043b\u044e\u0447, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0434\u0430\u0442\u0430 \u2014 22 \u0444\u0435\u0432\u0440\u0430\u043b\u044f 2023 \u0433\u043e\u0434\u0430. \u0418 14 \u0447\u0430\u0441\u043e\u0432 \u2014 \u044d\u0442\u043e \u0442\u043e\u0442 \u0447\u0430\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u0430\u0448\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0422\u0430\u043a\u0436\u0435 \u0432 \u044d\u0442\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u044f\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0438 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442. \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0438\u0436\u0435 \u043a\u043b\u044e\u0447\u0430 \u2014 \u043a\u043b\u0430\u0441\u0441, \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0438 \u043f\u0440\u0435\u0434\u043c\u0435\u0442. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u2014 \u0434\u0432\u0430.<\/p>\n<pre><code class=\"python\">>>> r.keys('sessions*') [b'sessions_2023-02-22_14', ...] >>> r.hkeys('sessions_2023-02-22_14') [b'grade_2_segment_regions_subject_other', ...] >>> r.hget( 'sessions_2023-02-22_14', 'grade_2_segment_regions_subject_other' ) b'2'<\/code><\/pre>\n<h2>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 DB Saver<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0438\u0433\u0440\u0443 \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 DB Saver. \u042d\u0442\u043e \u0432\u043e\u0440\u043a\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 Redis \u0432 \u0431\u0430\u0437\u0443.\u00a0\u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u043a \u0447\u0430\u0441\u043e\u0432\u044b\u0435, \u0442\u0430\u043a \u0438 \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u043b\u0438\u0448\u043d\u0438\u043c\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0444\u043e\u043d\u043e\u043c.<\/p>\n<p>\u041e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u2014 \u0441\u0431\u0440\u043e\u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 django.db.connection. \u041e\u043d \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043e\u0431\u0440\u044b\u0432\u0430\u043c\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0421 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c Redis \u0441 \u0431\u0430\u0437\u043e\u0439 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0447\u0430\u0441\u043e\u0432\u044b\u0435 (\u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u0434\u043d\u0435\u0432\u043d\u044b\u0435) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, interface error \u0438\u043b\u0438 operational error, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e connect, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043d\u0430\u0448\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u0418 \u043f\u043e\u043a\u0430 \u0443 \u043d\u0430\u0441 \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u0430 \u0432 \u0431\u0430\u0437\u0443, \u043c\u044b \u043d\u0435 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u044e\u0447 \u0438\u0437 Redis.<\/p>\n<pre><code class=\"python\">from django.db import connection  def run(): while True: try: time.sleep(SYNC_INTERVAL) save_redis_data_to_db() update_daily_counts() except (InterfaceError, OperationalError):  connection.connect() continue<\/code><\/pre>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u0430 \u0443\u0436\u0435 \u0432 \u0431\u0430\u0437\u0435. \u0421\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043f\u043e\u043c\u0435\u0442\u043a\u0430 frame \u043e\u00a0\u0442\u043e\u043c, \u043a\u0430\u043a\u043e\u0439 \u044d\u0442\u043e \u0430\u0433\u0440\u0435\u0433\u0430\u0442 \u2014 \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0438\u043b\u0438 \u0434\u043d\u0435\u0432\u043d\u043e\u0439. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438: \u043f\u0440\u0435\u0434\u043c\u0435\u0442, \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<pre><code class=\"python\">class SessionsEntity(models.Model): count = models.IntegerField() grade = models.IntegerField() segment = models.CharField(max_length=10) subject = models.CharField(max_length=25) frame = models.CharField(max_length=10) ts = models.DateTimeField(db_index=True) created_at = models.DateTimeField()  objects = DBManager()  class Meta: db_table = 'session_entities'<\/code><\/pre>\n<h2>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f API<\/h2>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0438\u0437 \u0431\u0430\u0437\u044b, \u0442\u0430\u043a \u0438 \u0438\u0437 Redis. \u0421\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 Kafka \u043c\u043e\u0433\u0443\u0442 \u0434\u043e\u043b\u0435\u0442\u0430\u0442\u044c \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 (\u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439). \u041f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u043d\u0435\u043b\u044c\u0437\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0430\u043c\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0448 DB Saver \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u043b\u0435\u043a\u043e\u0435 \u043f\u0440\u043e\u0448\u043b\u043e\u0435: \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0434\u043d\u044f\u043c\u0438 \u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u0434\u0435\u043b\u044f\u043c\u0438. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0437\u0430\u043f\u043e\u0437\u0434\u0430\u0432\u0448\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 \u0432 Redis, DB Saver \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0431\u0430\u0437\u0443.<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u0435\u0441\u0442\u044c:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u043a;\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0433\u0440\u0430\u0444\u0438\u043a \u043d\u0430\u043a\u043e\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439;\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0431\u043b\u043e\u043a, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u044b;\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0438 \u043e\u0431\u0449\u0438\u0439 \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u043e \u0433\u043e\u0434\u0443, \u0433\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b. <\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6c6\/a18\/c7a\/6c6a18c7a86c812bdd55dcd4883fefae.png\" alt=\"\" title=\"\" width=\"830\" height=\"565\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6c6\/a18\/c7a\/6c6a18c7a86c812bdd55dcd4883fefae.png\"\/><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0ec\/bb3\/332\/0ecbb3332839ac034b825a39267e3b79.png\" alt=\"\" title=\"\" width=\"825\" height=\"456\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ec\/bb3\/332\/0ecbb3332839ac034b825a39267e3b79.png\"\/><\/figure>\n<h2>\u041a\u0430\u043a \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 DAU<\/h2>\n<p>\u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0437\u043d\u0435\u0441 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u043d\u0435\u0432\u043d\u044b\u0445 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u0435\u0439. \u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0431\u044b\u043b\u043e \u0440\u0430\u043d\u0435\u0435 \u0441 \u0441\u0435\u0441\u0441\u0438\u044f\u043c\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0421 \u0441\u0435\u0441\u0441\u0438\u044f\u043c\u0438 \u043d\u0430\u043c \u043d\u0435 \u0431\u044b\u043b\u0430 \u043d\u0443\u0436\u043d\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0430 \u0438\u043b\u0438 \u0434\u043d\u044f \u2014 \u0441 DAU \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0441 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u043e\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e.\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0423 \u043d\u0430\u0441 \u043d\u0435\u0442 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u043e\u043f\u0438\u043a\u0430 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438, \u043d\u043e \u0435\u0441\u0442\u044c pageviews \u2014 \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0418 \u0432\u0441\u0435 \u0431\u044b \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0442\u043e\u043f\u0438\u043a\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 15 \u0440\u0430\u0437 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0442\u043e \u0435\u0441\u0442\u044c, \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 1500 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 (\u0432 \u0441\u0435\u0441\u0441\u0438\u044f\u0445 \u0443 \u043d\u0430\u0441 \u043e\u043a\u043e\u043b\u043e 100 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443).\u00a0<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430, \u043c\u044b \u0443\u0436\u0435 \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0442\u0430\u043a, \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0440\u0430\u043d\u044c\u0448\u0435.\u00a0<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0432\u0438\u0434\u0443 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0447\u0430\u0441\u043e\u0432\u044b\u043c \u0438 \u0434\u043d\u0435\u0432\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0430\u043c \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u0438 \u043a\u0443\u043c\u0443\u043b\u044f\u0442\u0438\u0432\u043d\u044b\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b. \u041d\u0430\u0448\u0438 \u0432\u043e\u0440\u043a\u0435\u0440\u044b \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u044e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0438\u0445 \u0431\u0430\u0437\u0443 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u0441\u0438\u043b\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043c\u044b \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 Redis \u0438 \u0438\u0441\u043a\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u0431\u0430\u0437\u0435 \u0431\u0430\u0442\u0447\u0430\u043c\u0438 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0432 DAU \u0432 Redis:\u00a0<\/p>\n<ul>\n<li>\n<p>KafkaWorker \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432 Redis, \u0430 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c;<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437 \u044d\u0442\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432\u043e\u0440\u043a\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0438\u0449\u0443\u0442 \u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b;<\/p>\n<\/li>\n<li>\n<p>\u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0430\u0439\u0434\u0435\u043d\u044b, \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 Redis;<\/p>\n<\/li>\n<li>\n<p>\u0434\u0430\u043b\u0435\u0435 \u0432\u043e\u0440\u043a\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Redis, \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u044e\u0442 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442 \u0438\u0445 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b4e\/96f\/119\/b4e96f119f2efcfa698e2ddb7b5778d5.png\" alt=\"\" title=\"\" width=\"781\" height=\"341\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b4e\/96f\/119\/b4e96f119f2efcfa698e2ddb7b5778d5.png\"\/><\/figure>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 DAU \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438 \u043f\u043e \u0431\u0430\u0437\u0435: <\/p>\n<pre><code class=\"sql\">    select st.id as student_id, cb.parallel as parallel     from students st     join class_books cb on st.class_book_id = cb.id     where st.id=any(%(student_ids)s)<\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a ID \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432, \u0434\u0430\u043b\u0435\u0435 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c any. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e ID \u0435\u0441\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u2014 100, 1000 \u2014 \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c.<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>\u041d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u043b\u043b\u0435\u043d\u0434\u0436\u0435\u0439:\u00a0<\/p>\n<ul>\n<li>\n<p>\u0421\u043b\u043e\u0432\u0430\u0440\u0438 \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u043e\u0432 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u2014 \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u043e \u044f\u0432\u043d\u043e \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043c\u044b \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u043c, \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c trade-off \u043c\u0435\u0436\u0434\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 \u043a\u044d\u0448\u0430 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437 \u043a\u044d\u0448\u0430 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0438, \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u0443\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u044d\u0448\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u044f \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441 \u044d\u0442\u0438\u043c \u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c.\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0418, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0432 \u043b\u044e\u0431\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0435\u0441\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f: \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u043d\u0435\u0442 \u0432 10, 100 \u0438\u043b\u0438 1000 \u0440\u0430\u0437 \u0431\u043e\u043b\u044c\u0448\u0435? \u0412\u0440\u0435\u043c\u044f \u043f\u043e\u043a\u0430\u0436\u0435\u0442! \ud83d\ude42\u00a0 <\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u0425\u043e\u0447\u0435\u0448\u044c \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u0439 EdTech \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0430\u043c\u0438 \u2014<a href=\"https:\/\/careers.uchi.ru\/?utm_source=habr&amp;utm_medium=links&amp;utm_campaign=pr_real_time_analitics\">\u00a0\u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0441\u044f<\/a>\u00a0\u043a \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0423\u0447\u0438.\u0440\u0443!<\/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\/730330\/\"> https:\/\/habr.com\/ru\/articles\/730330\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043d\u0434\u0440\u0435\u0439 \u0421\u043a\u0438\u0431\u0430 \u0438 \u044f Python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 ML-\u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0423\u0447\u0438.\u0440\u0443. \u0420\u0430\u0437\u043d\u044b\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0441\u0441\u0438\u0439, DAU \u0438 \u0434\u0440\u0443\u0433\u0438\u043c) \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0432\u043e\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 real-time \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u2014 \u0431\u044b\u0441\u0442\u0440\u0443\u044e, \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0438 \u0441 \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0430\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043e\u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430.\u00a0<\/p>\n<h2>\u041f\u0440\u0438\u0447\u0438\u043d\u044b \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u044b\u043b\u0430 \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0431\u0430\u0437\u0430 Postgres. \u0412 \u043d\u0435\u0433\u043e \u043f\u0438\u0441\u0430\u043b\u0438\u0441\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0442\u0430\u043c \u0436\u0435 \u043e\u043d\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u0432 \u043e\u0442\u0447\u0435\u0442\u044b, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0442\u0440\u043e\u0438\u043b\u0438\u0441\u044c \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435.\u00a0\u041d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0431\u044b\u043b\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0430\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432 \u0431\u0430\u0437\u0435 \u0431\u044b\u043b\u043e \u043c\u0430\u043b\u043e \u0441\u0442\u0440\u043e\u043a. \u042d\u0442\u043e\u0433\u043e \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0423\u0447\u0438.\u0440\u0443 \u043d\u0435 \u0441\u0442\u0430\u043b\u0430 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u043c highload-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u2014 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0447\u0442\u0438 20 \u043c\u043b\u043d \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u0441\u0443\u0442\u043a\u0438.<\/p>\n<p>\u0420\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0438 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0431\u044b\u043b\u043e. \u0422\u0430\u043a\u0436\u0435 \u0441 \u0440\u043e\u0441\u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u043f\u0435\u0440\u0435\u0435\u0445\u0430\u043b\u0430 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0442\u044f\u0436\u0435\u043b\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0433\u0434\u0435 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c ClickHouse, S3, Airflow, Tableau \u0438 \u0440\u044f\u0434 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439. \u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0448\u0438\u0440\u043e\u043a\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0445, \u0435\u0436\u0435\u043c\u0435\u0441\u044f\u0447\u043d\u044b\u0445 \u0438 \u0435\u0436\u0435\u043a\u0432\u0430\u0440\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u0447\u0435\u0442\u043e\u0432 \u0434\u043b\u044f \u0431\u0438\u0437\u043d\u0435\u0441\u0430, \u043d\u043e \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0434\u043b\u044f real-time \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0438 Tableau \u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u0438 \u0438\u043c\u0435\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0441\u043c\u0435\u043d\u044b \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0442\u0435\u043a\u0430, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u0421\u043e\u0431\u044b\u0442\u0438\u044f \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0435, \u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 Kafka-\u043a\u043b\u0430\u0441\u0442\u0435\u0440. \u0422\u0430\u043a \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0438 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0430\u043c\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0431\u044b\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u0445 \u0438\u0437 Kafka \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u0442 \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043c\u0435\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0443, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0443 \u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439;\u00a0<\/p>\n<\/li>\n<li>\n<p>\u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0447\u0430\u0441\u043e\u0432\u044b\u0435 \u0438 \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0433\u0440\u0430\u0444\u0438\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0430\u043a\u043e\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u0442\u043e\u0433\u0438.<\/p>\n<\/li>\n<\/ul>\n<h2>\u0421\u0442\u0435\u043a<\/h2>\n<p><strong>\u0411\u044d\u043a\u0435\u043d\u0434<\/strong> \u0443 \u043d\u0430\u0441 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e <strong>\u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Django<\/strong>. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 Django Extensions, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c, \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 django-\u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0423\u0447\u0438.\u0440\u0443 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430, \u0438 \u043b\u044e\u0431\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438\u043b\u0438 \u0432\u043e\u0440\u043a\u0435\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435. \u0412\u043e\u0440\u043a\u0435\u0440\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u0430\u043a \u0440\u0430\u0437 \u0447\u0435\u0440\u0435\u0437 Django Extensions. \u041e\u0431 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u0441\u0430\u043c\u0438\u0445 \u0432\u043e\u0440\u043a\u0435\u0440\u043e\u0432 \u043d\u0430\u043f\u0438\u0448\u0443 \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435.\u00a0<\/p>\n<p><strong>\u0421 Kafka<\/strong> \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <strong>AIOKafka<\/strong>, \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>fastavro \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong>.\u00a0<\/p>\n<p><strong>\u0414\u043b\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Svelte<\/strong>, <strong>\u0433\u0440\u0430\u0444\u0438\u043a\u0438<\/strong> \u0441\u0442\u0440\u043e\u0438\u043c <strong>\u0432 Highcharts JS<\/strong>. \u0414\u043b\u044f <strong>\u0434\u043e\u043b\u0433\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/strong> \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0432 <strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Postgres<\/strong>, \u0430 <strong>\u0432 Redis<\/strong> \u0443 \u043d\u0430\u0441 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0442\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0434\u0430\u043b\u0435\u0435.<\/p>\n<h2>\u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h2>\n<p>\u0418\u0437 Kafka \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u0440\u043a\u0435\u0440 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e KafkaWorker) \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0445, \u043e\u0431\u043e\u0433\u0430\u0449\u0430\u0435\u0442 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 Redis \u0432 \u0432\u0438\u0434\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u0440\u043a\u0435\u0440 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 Redis \u0432 \u0431\u0430\u0437\u0443 \u2014 DB Saver. \u0418 \u0443\u0436\u0435 API \u0447\u0438\u0442\u0430\u0435\u0442 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b \u0438\u0437 Redis \u0438 \u0431\u0430\u0437\u044b, \u043e\u0442\u0434\u0430\u0435\u0442 \u0438\u0445 \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434. \u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"bordered full-width\"><\/figure>\n<h2>\u0410\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430 \u0441\u0435\u0441\u0441\u0438\u0439<\/h2>\n<p>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u0440\u0430\u0441\u0441\u043a\u0430\u0437 \u0431\u0443\u0434\u0443 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0441\u0435\u0441\u0441\u0438\u0439. \u0412 \u0423\u0447\u0438.\u0440\u0443 <strong>\u0441\u0435\u0441\u0441\u0438\u044f<\/strong> \u2014 \u044d\u0442\u043e <strong>\u0441\u043e\u0431\u044b\u0442\u0438\u0435<\/strong>, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <strong>\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u043d\u0438\u044f<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0434\u0435\u043b\u0430\u043b \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435, \u0432 Kafka \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u0441\u0435\u0441\u0441\u0438\u044f. \u0421\u0440\u0435\u0434\u0438 \u0435\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c: ID \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u0430, ID \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0438, \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<pre><code class=\"javascript\">{ 'student_id': 43248949, 'subject_id': 46,  'card_id': 443813,  'created_at': '2023-02-22 15:05:43.755000',  'right': 1, 'total': 1, 'spent': 5,  'part_id': 0,  'offset': 17489515 }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0435\u0433\u043e \u043e\u0431\u043e\u0433\u0430\u0442\u0438\u0442\u044c, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0440\u0443\u0433\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0434\u0435\u0441\u044c \u044f\u0432\u043d\u043e \u043d\u0435\u0442, \u043d\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0435\u0433\u043c\u0435\u043d\u0442, \u043a\u043b\u0430\u0441\u0441 \u0438\u043b\u0438 ID \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043b\u0435 <strong>subject_id<\/strong> \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0438 (\u043d\u043e \u0442\u0430\u043a \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430), \u0430 \u0432\u043e\u0442 <strong>\u043a\u043b\u0430\u0441\u0441<\/strong> \u0438 <strong>\u0441\u0435\u0433\u043c\u0435\u043d\u0442<\/strong> \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e\u00a0\u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c <strong>\u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/strong> \u0438\u043b\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h2>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b KafkaWorker<\/h2>\n<p><strong>KafkaWorker<\/strong> \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Kafka \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0445 \u0432 Redis, \u043d\u043e \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0434\u043d\u0430 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u0430\u0445 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u0445\u0435\u043c\u0430\u043c\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432, \u0438 \u0432 \u043d\u0438\u0445 \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u0446\u0438\u043a\u043b\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u0412\u043e\u0442 \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0445\u0435\u043c\u044b:\u00a0<\/p>\n<pre><code class=\"javascript\">{ \"name\": \"card_completions\", \"namespace\": \"uchiru\", \"doc\": \"Card completion event\", \"fields\": [ { \"name\": \"id\", \"type\": \"long\" }, { \"name\": \"student_id\", \"type\": \"long\" }, {       \"name\": \"last_activity\",       \"type\": [         {           \"type\": \"long\",           \"logicalType\": \"timestamp-millis\"         },         \"null\"       ] }, ... ] }<\/code><\/pre>\n<pre><code class=\"javascript\">{ \"name\": \"card_completions\", \"namespace\": \"modern_subjects\", \"doc\": \"Card completions for the Modern Subjects\", \"fields\": [ { \"name\": \"student_id\", \"type\": \"string\" }, { \"name\": \"subject_id\", \"type\": \"int\" }, {       \"name\": \"finished_at\",       \"type\": [         {           \"type\": \"long\",           \"logicalType\": \"timestamp-millis\"         },         \"null\"       ] },  ... ] }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u2014 \u044d\u0442\u043e \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u043e\u0431\u0449\u0435\u043c core-\u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435, \u043a\u0430\u0440\u0442\u043e\u0447\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u0430\u0445 \u043f\u043e \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c. \u0412\u0442\u043e\u0440\u0430\u044f \u2014 \u044d\u0442\u043e \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u0445, \u043d\u043e\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043a\u0443\u0440\u0441\u0430\u0445. \u041c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0435\u0441\u0441\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 ID, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0435 \u0437\u0430\u0434\u0432\u0430\u0438\u0432\u0430\u043b\u0438\u0441\u044c. \u0412 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u0445 ID \u043d\u0435\u0442, \u0438 \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0443\u0431\u0438\u0440\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b \u043f\u043e \u0441\u0443\u043c\u043c\u0435 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c: \u043e\u043d\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438.\u0418\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0445\u0435\u043c\u0430\u0445 \u044d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443: \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u2014 <strong>last activity<\/strong>, \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u2014 <strong>finished at<\/strong>. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0432\u0438\u0434\u0443 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043e\u0431\u0449\u0435\u043c\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443 \u0441\u043b\u043e\u0432. \u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a \u0432\u0441\u0435\u0445 \u0441\u0435\u0441\u0441\u0438\u0439, \u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0445 \u0432\u0441\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432\u0438\u0434\u0443 \u0438 \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u0447\u0430\u0441\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u043e\u0432.<\/p>\n<pre><code class=\"python\">topics = { 'uchiru.card_comletions': { 'session_id': 'id', 'last_activity': 'last_activity' }, 'modern_subjects.card_completions': { 'session_id': None, 'last_activity': 'finished_at' }<\/code><\/pre>\n<p>\u041e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 Kafka \u0443 \u043d\u0430\u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435, \u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0434\u043b\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u0430 \u0434\u043b\u044f<strong> <\/strong>\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430. <strong>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u043f\u043e\u043b\u0435\u0439 \u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/strong> \u0443\u0434\u043e\u0431\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 <strong>\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e callback-\u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/strong>, \u0430 <strong>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong> \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u043e\u0432 <strong>\u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0432 \u0435\u0434\u0438\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong>.<\/p>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0446\u0438\u044f \u0438\u043b\u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 callback-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u043e\u043f\u0438\u043a\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u043c: \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043a\u044d\u0448\u0430\u0445 Redis, \u0437\u0430 \u043a\u0430\u043a\u0438\u043c\u0438-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0431\u0430\u0437\u0443. \u041d\u0438\u0436\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f DAU \u2014 \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043a\u0435\u0439\u0441.\u00a0<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u044f \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0430\u0442 \u0438\u043b\u0438 \u043d\u0430\u0439\u0442\u0438 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439. <strong>\u0410\u0433\u0440\u0435\u0433\u0430\u0442<\/strong> \u2014 \u044d\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 Redis, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 <strong>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/strong> \u0438\u043b\u0438 <strong>\u0441\u0443\u043c\u043c\u0443<\/strong> \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439) \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0447\u0430\u0441. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u044d\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f GROUP BY \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043f\u043e\u043b\u044f\u043c.\u00a0<\/p>\n<p>\u041a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0441\u0430\u043c\u0438 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b? \u0412 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u044b \u0445\u0440\u0430\u043d\u0438\u043c \u0434\u0430\u0442\u0443 \u0438 \u0447\u0430\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443 \u043d\u0430\u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0432 \u043a\u043b\u044e\u0447\u0430\u0445 \u2014 \u043d\u0430\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0441\u0430\u043c\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b\u00a0KafkaWorker.<\/p>\n<pre><code class=\"python\">async def callback_sessions(msg, topic): ...  def consumer_factory(): for topic in topics: yield AsyncKafkaConsumer( topic=t, ... callback=partial(callback_session, topic=t) )  def run(): for c in consumer_factory(): asyncio.ensure_future(c.consume())  loop = asyncio.get_event_loop() loop.run_forever()<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u0435 \u043d\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Redis \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c Python. \u0417\u0434\u0435\u0441\u044c \u0434\u043b\u044f \u0441\u0435\u0441\u0441\u0438\u0439 \u0435\u0441\u0442\u044c \u043a\u043b\u044e\u0447, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0434\u0430\u0442\u0430 \u2014 22 \u0444\u0435\u0432\u0440\u0430\u043b\u044f 2023 \u0433\u043e\u0434\u0430. \u0418 14 \u0447\u0430\u0441\u043e\u0432 \u2014 \u044d\u0442\u043e \u0442\u043e\u0442 \u0447\u0430\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u0430\u0448\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0422\u0430\u043a\u0436\u0435 \u0432 \u044d\u0442\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u044f\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0438 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442. \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0438\u0436\u0435 \u043a\u043b\u044e\u0447\u0430 \u2014 \u043a\u043b\u0430\u0441\u0441, \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0438 \u043f\u0440\u0435\u0434\u043c\u0435\u0442. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u2014 \u0434\u0432\u0430.<\/p>\n<pre><code class=\"python\">>>> r.keys('sessions*') [b'sessions_2023-02-22_14', ...] >>> r.hkeys('sessions_2023-02-22_14') [b'grade_2_segment_regions_subject_other', ...] >>> r.hget( 'sessions_2023-02-22_14', 'grade_2_segment_regions_subject_other' ) b'2'<\/code><\/pre>\n<h2>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 DB Saver<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432 \u0438\u0433\u0440\u0443 \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 DB Saver. \u042d\u0442\u043e \u0432\u043e\u0440\u043a\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 Redis \u0432 \u0431\u0430\u0437\u0443.\u00a0\u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u043a \u0447\u0430\u0441\u043e\u0432\u044b\u0435, \u0442\u0430\u043a \u0438 \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u044b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u043b\u0438\u0448\u043d\u0438\u043c\u0438 \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0444\u043e\u043d\u043e\u043c.<\/p>\n<p>\u041e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u2014 \u0441\u0431\u0440\u043e\u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 django.db.connection. \u041e\u043d \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043e\u0431\u0440\u044b\u0432\u0430\u043c\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439. \u0421 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c Redis \u0441 \u0431\u0430\u0437\u043e\u0439 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0447\u0430\u0441\u043e\u0432\u044b\u0435 (\u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u0434\u043d\u0435\u0432\u043d\u044b\u0435) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, interface error \u0438\u043b\u0438 operational error, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e connect, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043d\u0430\u0448\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u0418 \u043f\u043e\u043a\u0430 \u0443 \u043d\u0430\u0441 \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u0430 \u0432 \u0431\u0430\u0437\u0443, \u043c\u044b \u043d\u0435 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u044e\u0447 \u0438\u0437 Redis.<\/p>\n<pre><code class=\"python\">from django.db import connection  def run(): while True: try: time.sleep(SYNC_INTERVAL) save_redis_data_to_db() update_daily_counts() except (InterfaceError, OperationalError):  connection.connect() continue<\/code><\/pre>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u0430 \u0443\u0436\u0435 \u0432 \u0431\u0430\u0437\u0435. \u0421\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0447\u0435\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043f\u043e\u043c\u0435\u0442\u043a\u0430 frame \u043e\u00a0\u0442\u043e\u043c, \u043a\u0430\u043a\u043e\u0439 \u044d\u0442\u043e \u0430\u0433\u0440\u0435\u0433\u0430\u0442 \u2014 \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0438\u043b\u0438 \u0434\u043d\u0435\u0432\u043d\u043e\u0439. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438: \u043f\u0440\u0435\u0434\u043c\u0435\u0442, \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<pre><code class=\"python\">class SessionsEntity(models.Model): count = models.IntegerField() grade = models.IntegerField() segment = models.CharField(max_length=10) subject = models.CharField(max_length=25) frame =<\/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-387836","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/387836","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=387836"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/387836\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=387836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=387836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=387836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}