{"id":323224,"date":"2021-05-17T09:00:20","date_gmt":"2021-05-17T09:00:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=323224"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=323224","title":{"rendered":"\u041a\u0430\u043a \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u044d\u0448\u0430: \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/au\/ng\/sr\/aungsr-qqzesfc3ob8jf8jutzu8.jpeg\"><br \/>  <a href=\"https:\/\/www.deviantart.com\/bisbiswas\/art\/To-Destination-874249730\">To Destination by BisBiswas<\/a><\/p>\n<p>  <\/p>\n<p>\u041c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0437\u0432\u0443\u0447\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435, \u043d\u043e \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435 \u2014 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u0430. <\/p>\n<p>  <\/p>\n<p>\u042f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0431\u0435\u0437 \u0437\u0430\u0442\u0435\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445. <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u044d\u0448\u0430. <\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 Python 3 + FastApi, \u044d\u0442\u043e \u043d\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043b\u044e\u0431\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u0418, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0432\u044b\u0431\u043e\u0440 \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u2014 \u0437\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u2014 \u043d\u0430 GitHub<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0430 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b <a href=\"https:\/\/mcs.mail.ru\/\">Mail.ru Cloud Solutions<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dw\/15\/2t\/dw152tz1h4tulaxo9ntrfcqidaq.jpeg\"><\/p>\n<p>  <\/p>\n<h2 id=\"chto-ya-budu-ispolzovat\">\u0427\u0442\u043e \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u0433\u043e\u0432\u043e\u0440\u044e, \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e Docker Compose \u2014 \u043e\u043d\u0438 \u0443\u0436\u0435 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u044b \u0432 Docker-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043b\u044e\u0431\u043e\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435, \u043d\u043e \u0438 <a href=\"https:\/\/mcs.mail.ru\/solutions\/vps-vds\/\">\u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u043d\u0430 VPS\/VDS<\/a>. \u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Python 3 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/docs.python.org\/3\/library\/asyncio.html\">asyncio<\/a> \u0438 <a href=\"https:\/\/www.python-httpx.org\/\">HTTPX<\/a>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043f\u043e\u0433\u043e\u0434\u044b \u0441 <a href=\"https:\/\/pogoda.mail.ru\/\">pogoda.mail.ru<\/a>.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 API, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/openweathermap.org\/\">openweathermap.org<\/a>. \u041d\u043e \u0442\u043e\u0433\u0434\u0430 \u0431\u044b \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c API-\u043a\u043b\u044e\u0447. \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u2014 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043b\u0438\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u0442\u0440\u0435\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0433\u043e\u0440\u043e\u0434\u043e\u0432, \u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u0431\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c 18 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432: \u0441\u0435\u0440\u0432\u0435\u0440 <a href=\"https:\/\/pogoda.mail.ru\/\">pogoda.mail.ru<\/a> \u0431\u0430\u043d\u0438\u0442 \u043d\u0430 10-20 \u0441\u0435\u043a\u0443\u043d\u0434, \u0435\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 20 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0434\u0440\u044f\u0434. <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 18-\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430\u043c \u0445\u0432\u0430\u0442\u0438\u0442. \u041d\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 API <a href=\"https:\/\/openweathermap.org\/\">openweathermap.org<\/a>, \u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 60 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443 (\u0441\u043c. <a href=\"https:\/\/openweathermap.org\/price\">Free Subscription<\/a>). \u0422\u043e \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c\u044b\u0435.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/client.py\">client.py<\/a>:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import asyncio import httpx import time  async def get_data_api(city):     url = f'http:\/\/127.0.0.1:8000\/api\/weather\/{city}'      for i in range(6):         async with httpx.AsyncClient() as client:             response = await client.get(url)             response.raise_for_status()          data = response.json()         print('city: {}, temperature: {}, source: {}'.format(             data.get('city'), data.get('temperature'), data.get('source')))  tasks = [     asyncio.ensure_future(get_data_api('moskva')),     asyncio.ensure_future(get_data_api('tokyo')),     asyncio.ensure_future(get_data_api('london')) ]  start = time.time()  loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.gather(*tasks)) loop.close()  end = time.time() - start print(f'time {end:0.2f} seconds') print(f'mean time for 1 request: {end\/18:0.2f} seconds')<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"shag-1-razvorachivayu-prostoy-mikroservis\">\u0428\u0430\u0433 1. \u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441<\/h2>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ed\/yk\/5k\/edyk5khgsgtqnru9e6wtyxfoky8.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/tree\/main\/1-simple-microservice\">1-simple-microservice<\/a>. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u2014 \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/1-simple-microservice\/microservice\/simple-microservice.py\">simple-microservice.py<\/a>, \u043e\u043d \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0430 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 <a href=\"https:\/\/fastapi.tiangolo.com\/\">FastApi<\/a>. <\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0432\u0445\u043e\u0434 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0433\u043e\u0440\u043e\u0434\u0430, \u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0440\u0435\u0441\u0443\u0440\u0441, \u043f\u0430\u0440\u0441\u0438\u0442 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0432 \u0433\u043e\u0440\u043e\u0434\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b. \u042d\u0442\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0443\u0441\u043a\u043e\u0440\u044f\u0442\u044c.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/1-simple-microservice\/microservice\/simple-microservice.py\">simple-microservice.py<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import fastapi import httpx from scrapy.selector import Selector  api = fastapi.FastAPI()  @api.get('\/api\/weather\/{city}') def weather(city: str):     url = f'https:\/\/pogoda.mail.ru\/prognoz\/{city}\/'      with httpx.Client() as client:         response = client.get(url)         response.raise_for_status()      selector = Selector(text=response.text)     t = selector.xpath('\/\/div[@class=&quot;information__content__temperature&quot;]\/text()').getall()[1].strip()      return {'city':city, 'temperature':t, 'source':'pogoda.mail.ru'}<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/1-simple-microservice\/microservice\/Dockerfile\">Dockerfile<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">FROM python:3.7  RUN python -m pip install fastapi httpx scrapy gunicorn uvicorn uvloop httptools  WORKDIR \/app  ADD simple-microservice.py simple-microservice.py<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/1-simple-microservice\/docker-compose.yml\">docker-compose.yml<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">version: '3.7'  services:     microservice:         build:             context: .\/microservice         image: simple-microservice         container_name: simple-microservice         restart: unless-stopped         ports:             - &quot;8000:8000&quot;         command: gunicorn -b 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker simple-microservice:api<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru time 1.22 seconds mean time for 1 request: 0.07 seconds<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 \u043e\u0431\u0449\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 <strong>1.22<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0430 \u043d\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c <strong>0.07<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<p>  <\/p>\n<h2 id=\"shag-2-dobavlyayu-v-mikroservis-mnogopotochnost\">\u0428\u0430\u0433 2. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g8\/23\/ej\/g823ejmbgy0thuc652qfrfy3lw4.png\"><\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0444\u0430\u0439\u043b\u044b \u2014 \u0432 \u043f\u0430\u043f\u043a\u0435 <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/tree\/main\/2-few-threads-microservice\">2-few-threads-microservice<\/a>. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0442\u0440\u0430\u0444\u0438\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043f\u043e\u0439\u0434\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0443\u0442\u0435\u043c. \u0420\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Gunicorn \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/2-few-threads-microservice\/docker-compose.yml\">docker-compose.yml<\/a> \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 <code>command: gunicorn -b 0.0.0.0:8000<\/code>\u2026 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>--workers=n<\/code>, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e <code>n<\/code> \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0440\u0438. <\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Nginx-\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a, \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 <a href=\"https:\/\/habr.com\/ru\/post\/548910\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041a \u043f\u043b\u044e\u0441\u0430\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435, \u043a \u043c\u0438\u043d\u0443\u0441\u0430\u043c \u2014 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0440\u043e\u0441\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u043b 100 MB \u043f\u0430\u043c\u044f\u0442\u0438, \u0442\u043e, \u0440\u0430\u0431\u043e\u0442\u0430\u044f \u0432 \u0442\u0440\u0438 \u043f\u043e\u0442\u043e\u043a\u0430, \u043e\u043d \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 300 MB. \u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043d\u0438\u0437\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0448\u0430\u0440\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043a\u044d\u0448.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/2-few-threads-microservice\/microservice\/few-threads-microservice.py\">few-threads-microservice.py<\/a>:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import fastapi import httpx from scrapy.selector import Selector  api = fastapi.FastAPI()  @api.get('\/api\/weather\/{city}') def weather(city: str):     url = f'https:\/\/pogoda.mail.ru\/prognoz\/{city}\/'      with httpx.Client() as client:         response = client.get(url)         response.raise_for_status()      selector = Selector(text=response.text)     t = selector.xpath('\/\/div[@class=&quot;information__content__temperature&quot;]\/text()').getall()[1].strip()      return {'city':city, 'temperature':t, 'source':'pogoda.mail.ru'}<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/2-few-threads-microservice\/microservice\/Dockerfile\">Dockerfile<\/a>:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">FROM python:3.7  RUN python -m pip install fastapi httpx scrapy gunicorn uvicorn uvloop httptools  WORKDIR \/app  ADD few-threads-microservice.py few-threads-microservice.py<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/2-few-threads-microservice\/docker-compose.yml\">docker-compose.yml<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">version: '3.7'  services:     microservice:         build:             context: .\/microservice         image: few-threads-microservice         container_name: few-threads-microservice         restart: unless-stopped         ports:             - &quot;8000:8000&quot;         # work in few threads         command: gunicorn --workers=3 -b 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker few-threads-microservice:api<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru time 1.15 seconds mean time for 1 request: 0.06 seconds<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0440\u043e\u0441\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0435\u0441\u0442\u044c: \u043e\u0431\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u2014 <strong>1.15<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434, \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 <strong>0.06<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434. \u0422\u0443\u0442 \u043d\u0443\u0436\u043d\u043e \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u044f, \u0438 \u0435\u0441\u043b\u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0439, \u0442\u043e \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439. \u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u0442\u044f\u0436\u0435\u043b\u044b\u0439, \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"shag-3-dobavlyayu-asinhronnoe-ispolnenie\">\u0428\u0430\u0433 3. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yw\/3v\/2g\/yw3v2gn0dfvanq0e0-bpzdgrsv0.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0412 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043e\u043d \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043e\u0436\u0438\u0434\u0430\u044f \u043e\u0442\u0432\u0435\u0442\u0430. \u041f\u0440\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043d\u044f\u0442 \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u2014 \u0437\u0430 \u0441\u0447\u0435\u0442 \u044d\u0442\u043e\u0433\u043e \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u2014 \u0432 \u043f\u0430\u043f\u043a\u0435 <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/tree\/main\/3-async-few-threads-microservice\">3-async-few-threads-microservice<\/a>. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043c\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u043b\u0438 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a <a href=\"https:\/\/fastapi.tiangolo.com\/\">FastApi<\/a> \u0438 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 <a href=\"https:\/\/gunicorn.org\/\">Gunicorn<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/asgi.readthedocs.io\/en\/latest\/\">ASGI<\/a>-\u0432\u043e\u0440\u043a\u0435\u0440 <a href=\"https:\/\/www.uvicorn.org\/\">Uvicorn<\/a>. \u0417\u043d\u0430\u0447\u0438\u0442, \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c async \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f await.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0437\u0430 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u043c \u043f\u043e\u0433\u043e\u0434\u044b \u2014 \u044d\u0442\u043e \u043d\u0430\u0448\u0430 await \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u043b\u044e\u0441 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043a \u043c\u0438\u043d\u0443\u0441\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0431\u00f3\u043b\u044c\u0448\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u043e \u0441 <a href=\"https:\/\/fastapi.tiangolo.com\/\">FastApi<\/a> \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/3-async-few-threads-microservice\/microservice\/async-few-threads-microservice.py\">async-few-threads-microservice.py<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import fastapi import httpx from scrapy.selector import Selector  api = fastapi.FastAPI()  @api.get('\/api\/weather\/{city}') async def weather(city: str):     url = f'https:\/\/pogoda.mail.ru\/prognoz\/{city}\/'      # asynchronous implementation     async with httpx.AsyncClient() as client:         response = await client.get(url)         response.raise_for_status()      selector = Selector(text=response.text)     t = selector.xpath('\/\/div[@class=&quot;information__content__temperature&quot;]\/text()').getall()[1].strip()      return {'city':city, 'temperature':t, 'source':'pogoda.mail.ru'}<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/3-async-few-threads-microservice\/microservice\/Dockerfile\">Dockerfile<\/a>:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">FROM python:3.7  RUN python -m pip install fastapi httpx scrapy gunicorn uvicorn uvloop httptools  WORKDIR \/app  ADD async-few-threads-microservice.py async-few-threads-microservice.py<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/3-async-few-threads-microservice\/docker-compose.yml\">docker-compose.yml<\/a>:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">version: '3.7'  services:     microservice:         build:             context: .\/microservice         image: async-few-threads-microservice         container_name: async-few-threads-microservice         restart: unless-stopped         ports:             - &quot;8000:8000&quot;         # work in few threads         command: gunicorn --workers=3 -b 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker async-few-threads-microservice:api<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430: <\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru time 0.88 seconds mean time for 1 request: 0.05 seconds<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043d\u043e\u0432\u0430 \u0432\u044b\u0440\u043e\u0441\u043b\u0430: \u043e\u0431\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u2014 <strong>0.88<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434, \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 <strong>0.05<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434. \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <a href=\"https:\/\/fastapi.tiangolo.com\/\">FastApi<\/a> \u0434\u0430\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442\u0430\u0445. \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0435\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u043f\u043e\u0442\u043e\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a \u0432\u043d\u0435\u0448\u043d\u0438\u043c API \u0438 \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"shag-4-dobavlyayu-k-mikroservisu-kesh\">\u0428\u0430\u0433 4. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043a \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043a\u044d\u0448<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0431\u0449\u0435\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0440\u0435\u0437\u043e\u043d\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 4 Redis <a href=\"https:\/\/redis.io\/topics\/faq#redis-is-single-threaded-how-can-i-exploit-multiple-cpu--cores\">\u0441\u0442\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u043c<\/a>, \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0443\u0436\u0435 \u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u0432\u0435\u0436\u0435\u043c Redis 6. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0432 \u043a\u044d\u0448 \u043d\u0435\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. <\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u044f\u0434\u0440\u0430 Redis \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u043c (\u043f\u0440\u0443\u0444\u044b <a href=\"https:\/\/redislabs.com\/blog\/diving-into-redis-6\/\">\u0437\u0434\u0435\u0441\u044c<\/a>). \u0417\u043d\u0430\u0447\u0438\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b \u043a\u043e\u043c\u0430\u043d\u0434 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c\/\u0447\u0442\u0435\u043d\u0438\u0435 \u043c\u044b \u043d\u0435 \u043f\u043e\u0441\u043b\u0430\u043b\u0438, \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/redis.io\">Redis<\/a> \u2014 in-memory data structure store, \u043e\u043d \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0418 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u0435\u0442 \u043a\u043e\u043b\u043e\u0441\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u0434\u0430\u0436\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043e\u0442 100 \u0442\u044b\u0441\u044f\u0447 get\/set \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u2014 <a href=\"https:\/\/redis.io\/topics\/benchmarks\">\u0437\u0434\u0435\u0441\u044c<\/a>) \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u044d\u0448\u0430.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pp\/ep\/oe\/ppepoe2tkdp1blqfsumhcjaa0rm.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u044f \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043b Redis \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u044d\u0448\u0430 \u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u0430\u043b \u0435\u0433\u043e \u0432 Docker-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 \u0444\u0430\u0439\u043b <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/4-cache-async-few-threads-microservice\/redis\/redis.conf\">redis.conf<\/a>:<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>bind 0.0.0.0<\/strong> \u2014 \u0437\u0430\u043c\u0430\u043f\u0438\u043b Redis \u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 localhost Docker-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.<\/li>\n<li><strong>maxmemory 100mb<\/strong> \u2014 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u044d\u0448\u0430.<\/li>\n<li><strong>maxmemory-policy volatile-ttl<\/strong> \u2014 \u044d\u0442\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u0435\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u043b\u0438\u043c\u0438\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u2014 <a href=\"https:\/\/redis.io\/topics\/lru-cache\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/strong>: \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 redis.conf \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/redis.io\/topics\/config\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>, \u0442\u0430\u043c \u0436\u0435 \u0435\u0441\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 Redis \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u044d\u0448\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b Redis \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0430\u043c\u0438 \u0438 \u0441\u0432\u044f\u0437\u0430\u043b \u043f\u0430\u043f\u043a\u0443 <code>.\/redis\/data<\/code> \u0441 \u043f\u0430\u043f\u043a\u043e\u0439 <code>data<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 Docker-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438\u0441\u044c \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0434\u0438\u0441\u043a (\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/4-cache-async-few-threads-microservice\/docker-compose.yml\">docker-compose.yml<\/a>).<\/p>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u043d\u0443\u0436\u043d\u0430 \u043e\u0433\u043e\u0432\u043e\u0440\u043a\u0430: \u0445\u043e\u0442\u044f \u043a\u044d\u0448 \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0435\u0433\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0443\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0441\u0445\u0435\u043c\u0430, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043f\u043e\u0433\u043e\u0434\u044b (\u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0432 \u0433\u043e\u0440\u043e\u0434\u0435) \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u044d\u0448\u0435 1 \u0447\u0430\u0441. \u0414\u043b\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u0430 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  <\/p>\n<p>\u0424\u0430\u0439\u043b\u044b \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u2014 \u0432 \u043f\u0430\u043f\u043a\u0435 <a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/tree\/main\/4-cache-async-few-threads-microservice\">4-cache-async-few-threads-microservice<\/a>. \u0412 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043d\u0435\u0442: \u0441\u043f\u0435\u0440\u0432\u0430 \u0447\u0438\u0442\u0430\u0435\u043c \u043a\u044d\u0448 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c \u2014 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0442\u0432\u0435\u0442\u0430. \u0417\u0430\u0442\u0435\u043c \u043a\u043b\u0430\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u044d\u0448 \u043d\u0430 1 \u0447\u0430\u0441 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442. \u0418\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u2014 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f. \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u044d\u0448 \u2014 \u044d\u0442\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0440\u0435\u0441\u0443\u0440\u0441.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/4-cache-async-few-threads-microservice\/microservice\/cache-async-few-threads-microservice.py\">cache-async-few-threads-microservice.py<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import fastapi import httpx from scrapy.selector import Selector import aioredis  api = fastapi.FastAPI()  @api.get('\/api\/weather\/{city}') async def weather(city: str):     redis = await aioredis.create_redis(address=('redis', 6379))      # get cache from memory     cache = await redis.get(city)      # check value from cache, if exists return it     if cache is not None:         return {'city':city, 'temperature':cache, 'source':'cache'}      url = f'https:\/\/pogoda.mail.ru\/prognoz\/{city}\/'      # asynchronous implementation     async with httpx.AsyncClient() as client:         response = await client.get(url)         response.raise_for_status()      selector = Selector(text=response.text)     t = selector.xpath('\/\/div[@class=&quot;information__content__temperature&quot;]\/text()').getall()[1].strip()      # save cache in memory for 1 hour     await redis.set(city, t, expire=3600)      return {'city':city, 'temperature':t, 'source':'pogoda.mail.ru'}<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/4-cache-async-few-threads-microservice\/microservice\/Dockerfile\">Dockerfile<\/a> (\u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0442\u043e\u043b\u044c\u043a\u043e <a href=\"https:\/\/aioredis.readthedocs.io\/en\/v1.3.0\/\">aioredis<\/a> \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438 \u0432 Redis):<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">FROM python:3.7  RUN python -m pip install fastapi httpx scrapy gunicorn uvicorn uvloop httptools aioredis  WORKDIR \/app  ADD cache-async-few-threads-microservice.py cache-async-few-threads-microservice.py<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/cdies\/microservice_acceleration\/blob\/main\/4-cache-async-few-threads-microservice\/docker-compose.yml\">docker-compose.yml<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">version: '3.7'  services:     microservice:         build:             context: .\/microservice         image: cache-async-few-threads-microservice         container_name: cache-async-few-threads-microservice         restart: unless-stopped         ports:             - &quot;8000:8000&quot;         # work in few threads         command: gunicorn --workers=3 -b 0.0.0.0:8000 -k uvicorn.workers.UvicornWorker cache-async-few-threads-microservice:api      redis:         image: redis         container_name: redis         restart: unless-stopped         volumes:             - .\/redis\/data:\/data             - .\/redis\/redis.conf:\/usr\/local\/etc\/redis\/redis.conf         expose:             - 6379         command: redis-server \/usr\/local\/etc\/redis\/redis.conf<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c&#8230;<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">city: moskva, temperature: +16\u00b0, source: pogoda.mail.ru city: moskva, temperature: +16\u00b0, source: cache city: moskva, temperature: +16\u00b0, source: cache city: moskva, temperature: +16\u00b0, source: cache city: moskva, temperature: +16\u00b0, source: cache city: moskva, temperature: +16\u00b0, source: cache city: tokyo, temperature: +11\u00b0, source: pogoda.mail.ru city: london, temperature: +8\u00b0, source: pogoda.mail.ru city: tokyo, temperature: +11\u00b0, source: cache city: london, temperature: +8\u00b0, source: cache city: tokyo, temperature: +11\u00b0, source: cache city: london, temperature: +8\u00b0, source: cache city: tokyo, temperature: +11\u00b0, source: cache city: london, temperature: +8\u00b0, source: cache city: tokyo, temperature: +11\u00b0, source: cache city: london, temperature: +8\u00b0, source: cache city: tokyo, temperature: +11\u00b0, source: cache city: london, temperature: +8\u00b0, source: cache time 0.48 seconds mean time for 1 request: 0.03 seconds<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043a\u044d\u0448 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043e\u0442\u043b\u0438\u0447\u043d\u043e. \u0411\u044b\u043b\u043e \u0432\u0441\u0435\u0433\u043e \u0442\u0440\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u044d\u0448. \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u043e\u0437\u0440\u043e\u0441\u043b\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e: \u043e\u0431\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u2014 <strong>0.48<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434, \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 <strong>0.03<\/strong> \u0441\u0435\u043a\u0443\u043d\u0434\u044b.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0438\u0436\u0435 \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. <\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f. \u041d\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u0434\u0430\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u0430\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441<\/th>\n<th>\u041e\u0431\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f<\/th>\n<th>\u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u043f\u0440\u043e\u0441\u0442\u043e\u0439<\/td>\n<td>1.22<\/td>\n<td>0.07<\/td>\n<\/tr>\n<tr>\n<td>+ \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/td>\n<td>1.15<\/td>\n<td>0.06<\/td>\n<\/tr>\n<tr>\n<td>+ \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c<\/td>\n<td>0.88<\/td>\n<td>0.05<\/td>\n<\/tr>\n<tr>\n<td>+ \u043a\u044d\u0448<\/td>\n<td>0.48<\/td>\n<td>0.03<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p><strong>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/strong>:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=hRecenOBYlE\">Caching API Responses with Redis<\/a>.<\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=BmOjeVM0w1U&amp;list=PLJcqk6mrJtxCo_KqHV2rM2_a3Z8qoE5Gk&amp;index=1\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0435\u0449\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/490362\/\">Kubernetes \u0432 \u0434\u0443\u0445\u0435 \u043f\u0438\u0440\u0430\u0442\u0441\u0442\u0432\u0430: \u043d\u0430\u0448 \u043f\u0443\u0442\u044c \u043a \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f<\/a>.<\/li>\n<li><a href=\"https:\/\/mcs.mail.ru\/blog\/populjarnye-jazyki-i-frejmvorki-dlja-razrabotki-mikroservisov\">\u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432: \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a<\/a>.<\/li>\n<li><a href=\"https:\/\/t.me\/k8s_mail\">\u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b \u0412\u043e\u043a\u0440\u0443\u0433 Kubernetes<\/a>.<\/li>\n<\/ol>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/557232\/\"> https:\/\/habr.com\/ru\/company\/mailru\/blog\/557232\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/au\/ng\/sr\/aungsr-qqzesfc3ob8jf8jutzu8.jpeg\"><br \/>  <a href=\"https:\/\/www.deviantart.com\/bisbiswas\/art\/To-Destination-874249730\">To Destination by BisBiswas<\/a><\/p>\n<p>  <\/p>\n<p>\u041c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0437\u0432\u0443\u0447\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435, \u043d\u043e \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435 \u2014 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u0430. <\/p>\n<p>  <\/p>\n<p>\u042f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0431\u0435\u0437 \u0437\u0430\u0442\u0435\u0439 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u043e\u043f\u0443\u0442\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-323224","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323224","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=323224"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323224\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}