{"id":335130,"date":"2022-06-29T21:00:27","date_gmt":"2022-06-29T21:00:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=335130"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=335130","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u043f\u0438\u0441\u0430\u043b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u0435\u0431-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 Python, \u0438\u043b\u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u044f \u0431\u0430\u043d\u0434\u0438\u0442<\/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>\u041d\u0430 \u0434\u043d\u044f\u0445 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u044f\u043c\u043e \u0432\u043e\u0442 \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0445\u043e\u0434\u0438\u0442 \u0432 \u0430\u043f\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0443\u0434 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u0431\u0435\u0440\u0435\u0442 \u043e\u0442\u0442\u0443\u0434\u0430 \u043a\u043e\u0435-\u043a\u0430\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0447\u0442\u043e \u0438 \u0437\u0430\u0447\u0435\u043c &#8212; \u0432\u043d\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430. \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0434\u0435\u0441\u044c \u0434\u0440\u0443\u0433\u043e\u0439 &#8212; \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c. \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0432\u0430\u0436\u043d\u0430 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 &#8212; \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0438 \u0441\u043e\u0442\u043d\u0438). \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0436\u0434\u0430\u0442\u044c &#8212; \u043d\u0435 \u043a\u0430\u0439\u0444.<br \/>\u0417\u0434\u0435\u0441\u044c \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u0440\u0435\u0441\u0451\u0440\u0447\u0435\u043c \u043d\u0430 \u0442\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0440\u0443\u0442\u043e, \u0430 \u043a\u0430\u043a \u043d\u0435\u0442. \u0421 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e. \u0410 \u0442\u0430\u043a \u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u044f \u0442\u0443\u043f\u0438\u043b. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/450\/69f\/920\/45069f92087ceb9b2e4635e289376562.jpg\" alt=\"\u0415\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044f \u0438 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0441\u0442\u0438\" title=\"\u0415\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044f \u0438 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0441\u0442\u0438\" width=\"837\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/450\/69f\/920\/45069f92087ceb9b2e4635e289376562.jpg\" data-blurred=\"true\"\/><figcaption>\u0415\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044f \u0438 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0441\u0442\u0438<\/figcaption><\/figure>\n<h2>\u041d\u0430\u0447\u043d\u0435\u043c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0438 <\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u043b\u0438\u0431\u0443 <strong>requests<\/strong> \u0438 <strong>tqdm<\/strong> \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0435\u0440\u0432\u0443\u044e-\u043f\u043e\u043f\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u0430\u043f\u0438\u0448\u043a\u0443: <code>https:\/\/catfact.ninja\/<\/code>. \u041c\u0435\u0442\u0440\u0438\u043a\u043e\u0439 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 RPS (<em>Request per second<\/em>). \u0427\u0435\u043c \u0432\u044b\u0448\u0435 &#8212; \u0442\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043b\u0443\u0447\u0448\u0435.<\/p>\n<pre><code class=\"python\">import time import requests from tqdm import tqdm  URL = 'https:\/\/catfact.ninja\/'   class Api:     def __init__(self, url: str):         self.url = url      def http_get(self, path: str, times: int):         content = []         for _ in tqdm(range(times), desc='Fetching data...', colour='GREEN'):             response = requests.get(self.url + path)             content.append(response.json())         return content   if __name__ == '__main__':     N = 10     api = Api(URL)      start_timestamp = time.time()     print(api.http_get(path='fact\/', times=N))      task_time = round(time.time() - start_timestamp, 2)     rps = round(N \/ task_time, 1)     print(         f\"| Requests: {N}; Total time: {task_time} s; RPS: {rps}. |\\n\"     )<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"bash\">Fetching data...: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 10\/10 [00:06&lt;00:00,  1.52it\/s] [{'fact': 'Despite imagery of cats happily drinking milk from saucers, studies indicate that cats are actually lactose intolerant and should avoid it entirely.', 'length': 148}, {'fact': 'The smallest pedigreed cat is a Singapura, which can weigh just 4 lbs (1.8 kg), or about five large cans of cat food. The largest pedigreed cats are Maine Coon cats, which can weigh 25 lbs (11.3 kg), or nearly twice as much as an average cat weighs.', 'length': 249}, {'fact': 'A cat has 230 bones in its body. A human has 206. A cat has no collarbone, so it can fit through any opening the size of its head.', 'length': 130}, {'fact': \"Cats' hearing is much more sensitive than humans and dogs.\", 'length': 58}, {'fact': 'The first formal cat show was held in England in 1871; in America, in 1895.', 'length': 75}, {'fact': 'In contrast to dogs, cats have not undergone major changes during their domestication process.', 'length': 94}, {'fact': 'Ginger tabby cats can have freckles around their mouths and on their eyelids!', 'length': 77}, {'fact': 'Cats bury their feces to cover their trails from predators.', 'length': 59}, {'fact': 'While it is commonly thought that the ancient Egyptians were the first to domesticate cats, the oldest known pet cat was recently found in a 9,500-year-old grave on the Mediterranean island of Cyprus. This grave predates early Egyptian art depicting cats by 4,000 years or more.', 'length': 278}, {'fact': 'Relative to its body size, the clouded leopard has the biggest canines of all animals\u2019 canines. Its dagger-like teeth can be as long as 1.8 inches (4.5 cm).', 'length': 156}] | Requests: 10; Total time: 6.61 s; RPS: 1.5. | <\/code><\/pre>\n<p>RPS &#8212; 1.5. \u041e\u0447\u0435\u043d\u044c \u0433\u0440\u0443\u0441\u0442\u043d\u043e. \u0423 \u043c\u0435\u043d\u044f \u0435\u0449\u0435 \u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u043e\u043c\u0430. \u041d\u0443 \u0442\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e.<\/p>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441? \u041e\u0442\u0432\u0435\u0442: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>requests.Session<\/strong> <br \/>E\u0441\u043b\u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0445\u043e\u0441\u0442\u0443, \u0431\u0430\u0437\u043e\u0432\u043e\u0435 TCP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. (\u0446\u0438\u0442\u0430\u0442\u0430 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <strong>requests<\/strong>)<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044e<\/h2>\n<pre><code>    def http_get_with_session(self, path: str, times: int):         content = []         with requests.session() as session:             for _ in tqdm(range(times), desc='Fetching data...', colour='GREEN'):                 response = session.get(self.url + path)                 content.append(response.json())         return content<\/code><\/pre>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0432 \u043c\u0435\u0442\u043e\u0434, \u0438 \u0432\u044b\u0437\u0432\u0430\u0432 \u0435\u0433\u043e, \u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"bash\">Fetching data...: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 10\/10 [00:02&lt;00:00,  3.88it\/s] [{'fact': 'Cats purr at the same frequency as an idling diesel engine, about 26 cycles per second.', 'length': 87}, {'fact': 'Cats eat grass to aid their digestion and to help them get rid of any fur in their stomachs.', 'length': 92}, {'fact': 'A cat\u2019s heart beats nearly twice as fast as a human heart, at 110 to 140 beats a minute.', 'length': 88}, {'fact': 'The world\u2019s rarest coffee, Kopi Luwak, comes from Indonesia where a wildcat known as the luwak lives. The cat eats coffee berries and the coffee beans inside pass through the stomach. The beans are harvested from the cat\u2019s dung heaps and then cleaned and roasted. Kopi Luwak sells for about $500 for a 450 g (1 lb) bag.', 'length': 319}, {'fact': 'There are more than 500 million domestic cats in the world, with approximately 40 recognized breeds.', 'length': 100}, {'fact': 'Cats sleep 16 to 18 hours per day. When cats are asleep, they are still alert to incoming stimuli. If you poke the tail of a sleeping cat, it will respond accordingly.', 'length': 167}, {'fact': 'Since cats are so good at hiding illness, even a single instance of a symptom should be taken very seriously.', 'length': 109}, {'fact': 'At 4 weeks, it is important to play with kittens so that they do not develope a fear of people.', 'length': 95}, {'fact': 'The technical term for a cat\u2019s hairball is a \u201cbezoar.\u201d', 'length': 54}, {'fact': 'Baking chocolate is the most dangerous chocolate to your cat.', 'length': 61}] | Requests: 10; Total time: 2.58 s; RPS: 3.9. | <\/code><\/pre>\n<p>\u041f\u043e\u0447\u0442\u0438 4 RPS, \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 1.5 \u0443\u0436\u0435 \u043f\u0440\u043e\u0440\u044b\u0432.<br \/>\u041d\u043e \u043d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f i\/o time \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u0445\u043d\u0440\u043e\u043d\u043d\u044b\u0445\/\u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c. \u042d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0445\u043e\u0442\u044f \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0430 \u043f\u043e\u0442\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0438 \u0442.\u0434. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043a\u0435\u0439\u0441\u0430.<\/p>\n<h2>async \/ await<\/h2>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"python\">def run_case(func, path, times):     start_timestamp = time.time()          asyncio.run(func(path, times))      task_time = round(time.time() - start_timestamp, 2)     rps = round(times \/ task_time, 1)     print(         f\"| Requests: {times}; Total time: {task_time} s; RPS: {rps}. |\\n\"     )<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 (\u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c <strong>aiohttp, <\/strong>\u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0440\u0435\u043a\u0432\u0435\u0441\u0442\u044b \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435):<\/p>\n<pre><code class=\"python\">    async def async_http_get(self, path: str, times: int):         async with aiohttp.ClientSession() as session:             content = []             for _ in tqdm(range(times), desc='Async fetching data...', colour='GREEN'):                 response = await session.get(url=self.url + path)                 content.append(await response.text(encoding='UTF-8'))             return content<\/code><\/pre>\n<pre><code class=\"python\">if __name__ == '__main__': N = 50     api = Api(URL)     run_case(api.async_http_get, path='fact\/', times=N)<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c:<\/p>\n<pre><code>Async fetching data...: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 50\/50 [00:12&lt;00:00,  3.99it\/s] | Requests: 50; Total time: 12.55 s; RPS: 4.0. | <\/code><\/pre>\n<p>\u0423\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0441\u043e\u0431\u043e \u043d\u0435\u0442. \u042f \u0434\u0443\u043c\u0430\u044e \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0432 i\/o \u0442\u0430\u0439\u043c\u0435 \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0430\u043c\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443 (\u0441\u043b\u044b\u0448\u0430\u043b \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0440\u0443\u0433\u0430\u044e\u0442 \u044d\u0442\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432 python). \u041a\u0430\u043a \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e.<\/p>\n<p>\u041d\u0430 \u0441\u043b\u043e\u0432\u0430\u0445 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0442\u0430\u043a. <br \/>&#8212; \u0412 \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441.<br \/>&#8212; \u041d\u0435 \u0434\u043e\u0436\u0438\u0434\u0430\u044f\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0430, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u043e\u0442\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043d\u043e\u0432\u0430 event loop&#8217;\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u043e &#171;for \u0446\u0438\u043a\u043b\u0443&#187; \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u043e\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441.<br \/>&#8212; \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043e\u0442\u0434\u0430\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u0432\u0435\u043d\u0442 \u043b\u0443\u043f\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0430 (\u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441), \u0442\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0435\u0439, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0441\u043c. \u043f\u0443\u043d\u043a\u0442 2.<br \/>&#8212; \u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043a\u043e\u0434-\u0442\u043e \u0432\u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0430\u0441\u0438\u0445\u043d\u0440\u043e\u043d\u043d\u044b\u0439, \u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f &#171;\u0440\u0430\u0437\u043e\u043c&#187;. \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u0434\u043e\u0439\u0442\u0438 \u043a \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 <strong>asyncio.gather.<\/strong><\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c asyncio.gather<\/h2>\n<p>Gather &#8212; \u043a\u0430\u043a \u043d\u0438 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e \u0441 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c. \u041c\u0435\u0442\u043e\u0434 gather \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438\u0445 \u0440\u0430\u0437\u043e\u043c (\u0442\u043e\u0436\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e). \u0422\u043e \u0435\u0441\u0442\u044c, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f, \u043c\u044b \u0432 \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0445 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c.<\/p>\n<p>\u0411\u044b\u043b\u043e:<br \/>[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -><br \/>[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] ->[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443]<\/p>\n<p>\u0410 \u0441\u0442\u0430\u043b\u043e:<br \/>[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] ->[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -><br \/>[\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443]<\/p>\n<pre><code class=\"python\">    async def async_gather_http_get(self, path: str, times: int):         async with aiohttp.ClientSession() as session:             tasks = []             for _ in tqdm(range(times), desc='Async gather fetching data...', colour='GREEN'):                 tasks.append(asyncio.create_task(session.get(self.url + path)))              responses = await asyncio.gather(*tasks)             return [await r.json() for r in responses]<\/code><\/pre>\n<pre><code class=\"python\">if __name__ == '__main__': N = 50     api = Api(URL)     run_case(api.async_gather_http_get, path='fact\/', times=N)<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c&#8230; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c&#8230; \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c. \u041a\u0443\u0440\u0441\u043e\u0440 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0438\u0433\u0430\u0442\u044c \u0432 \u043e\u043a\u043d\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0430. \u041d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 &#8212; \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u0428\u0442\u0438\u0440\u043b\u0438\u0446.<\/p>\n<p>\u041f\u0443\u0442\u0435\u043c \u043c\u0443\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0435\u0431\u0430\u0433\u0430 \u0438 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u044f \u043f\u043e\u043d\u044f\u043b &#8212; \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432 \u043c\u043e\u0435\u043c VPN. \u0415\u0433\u043e \u0443\u0437\u043b\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0433\u0434\u0435-\u0442\u043e \u0432 \u044e\u0440\u0438\u0441\u0434\u0438\u043a\u0446\u0438\u0438 Cloudflare. \u0410 \u043e\u043d\u0438 \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u043e\u0449\u0440\u044f\u044e\u0442, \u0441\u0447\u0438\u0442\u0430\u044f, \u0447\u0442\u043e \u044f \u0431\u043e\u0442. \u041d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b&#8230;\u0442\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u0433\u0434\u0435-\u0442\u043e \u0432 \u043f\u0443\u0447\u0438\u043d\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430. \u041e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u043d\u0438\u0445 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u041d\u0438\u043a\u043e\u0433\u0434\u0430. \u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>\u041e\u043a\u0435\u0439, \u043f\u043e\u043d\u044f\u0432 \u043e\u0442\u043a\u0443\u0434\u0430 \u043d\u043e\u0433\u0438 \u0440\u0430\u0441\u0442\u0443\u0442, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0434:<\/p>\n<pre><code>Async gather fetching data...: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 50\/50 [00:00&lt;00:00, 106834.03it\/s] | Requests: 50; Total time: 2.38 s; RPS: 21.0. |<\/code><\/pre>\n<p>\u0426\u0438\u0444\u0440\u044b \u0432\u044b\u0440\u043e\u0441\u043b\u0438, \u043a\u0440\u0443\u0442\u043e, 21 \u043d\u0435 1.5 &#8212; \u044d\u0442\u043e \u0443\u0436 \u0442\u043e\u0447\u043d\u043e.<br \/>\u041e\u0434\u043d\u0430\u043a\u043e \u0436\u0435 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0435\u0434\u0435\u043b, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043c N (\u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432) \u0434\u043e 200.<\/p>\n<pre><code>| Requests: 200; Total time: 2.97 s; RPS: 67.3. |<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0447\u0442\u043e \u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043c\u043e\u0436\u043d\u043e \u0438 \u0442\u0430\u043a? \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442. \u0415\u0441\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u0436\u0435 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043d\u0430\u043c \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440, \u0442\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u044d\u0442\u043e <code>{'message': 'Rate Limit Exceeded', 'code': 429}<br \/><\/code><br \/>\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043b\u0438\u043c\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u0432 \u0445\u043e\u0434\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430 \u0441 \u044d\u0442\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c &#8212; \u044d\u0442\u043e \u043e\u043a\u043e\u043b\u043e 60 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0437\u0430 \u0440\u0430\u0437, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043d \u043d\u0435 \u043f\u0435\u0440\u0435\u0432\u0430\u0440\u0438\u0432\u0430\u0435\u0442. \u0422\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u0442\u0430\u043a \u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0442\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442\u0435 \u043a \u044d\u0442\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u043e\u0431\u0434\u0443\u043c\u0430\u043d\u043d\u043e, \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u043c\u043e\u043a.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043c \u0441 threading?<\/h2>\n<p>\u0422\u0443\u0442 \u043e\u0441\u043e\u0431\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435\u0442 &#8212; \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e threading \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b (\u043f\u043b\u044e\u0441 &#8212; \u043c\u0438\u043d\u0443\u0441), \u043a\u0430\u043a \u0430\u0441\u0438\u0445\u043d\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u0437 \u043f\u0443\u043d\u043a\u0442\u0430 3. <\/p>\n<h2>multiprocessing<\/h2>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0432\u0440\u0430\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043a\u0430\u043a \u043d\u0435\u0447\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u0434\u0435\u043b\u0430\u043b \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u043d\u0434\u0443\u0441 \u0441 \u042e\u0442\u0443\u0431\u0430. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0438\u043b\u044c\u043d\u043e \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432. \u0414\u0430 \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 &#8212; \u044d\u0442\u043e \u043d\u0430\u0441\u0438\u043b\u0438\u0435 \u043d\u0430\u0434 \u0441\u0432\u043e\u0435\u0439 \u043f\u0441\u0438\u0445\u0438\u043a\u043e\u0439. \u0410 \u044f \u0441\u0432\u043e\u044e \u043f\u0441\u0438\u0445\u0438\u043a\u0443 \u0431\u0435\u0440\u0435\u0433\u0443.<\/p>\n<h2>\u041f\u043e\u0434\u0432\u0435\u0434\u0443 \u0438\u0442\u043e\u0433\u0438:<\/h2>\n<ul>\n<li>\n<p>\u041d\u0430 \u0434\u043d\u044f\u0445 \u0443\u043f\u0430\u043b Cloudlfare &#8212; \u0438\u0437\u0432\u0438\u043d\u0438\u0442\u0435, \u044d\u0442\u043e \u0438\u0437-\u0437\u0430 \u043c\u0435\u043d\u044f, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0425\u043e\u0442\u0438\u0442\u0435 \u0431\u044b\u0442\u044c \u0447\u0435\u043c\u043f\u0438\u043e\u043d\u043e\u043c \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 asyncio.gather, \u043d\u043e \u0441 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u043c\u0438 \u043b\u0438\u043c\u0438\u0442\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0435 \u043d\u0430 \u043e\u0434\u0438\u043d \u0445\u043e\u0441\u0442, \u0430 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438, \u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0441\u0442\u0435\u0441\u0442\u044f\u0439\u0442\u0435\u0441\u044c.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/674150\/\"> https:\/\/habr.com\/ru\/post\/674150\/<\/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>\u041d\u0430 \u0434\u043d\u044f\u0445 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0442\u0438\u043b\u0438\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u044f\u043c\u043e \u0432\u043e\u0442 \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0445\u043e\u0434\u0438\u0442 \u0432 \u0430\u043f\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0443\u0434 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u0431\u0435\u0440\u0435\u0442 \u043e\u0442\u0442\u0443\u0434\u0430 \u043a\u043e\u0435-\u043a\u0430\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0447\u0442\u043e \u0438 \u0437\u0430\u0447\u0435\u043c &#8212; \u0432\u043d\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430. \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0437\u0434\u0435\u0441\u044c \u0434\u0440\u0443\u0433\u043e\u0439 &#8212; \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c. \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0432\u0430\u0436\u043d\u0430 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 &#8212; \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0438 \u0441\u043e\u0442\u043d\u0438). \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0436\u0434\u0430\u0442\u044c &#8212; \u043d\u0435 \u043a\u0430\u0439\u0444.<br \/>\u0417\u0434\u0435\u0441\u044c \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u0440\u0435\u0441\u0451\u0440\u0447\u0435\u043c \u043d\u0430 \u0442\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0440\u0443\u0442\u043e, \u0430 \u043a\u0430\u043a \u043d\u0435\u0442. \u0421 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e. \u0410 \u0442\u0430\u043a \u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u044f \u0442\u0443\u043f\u0438\u043b. <\/p>\n<figure class=\"full-width\"><figcaption>\u0415\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u044f \u0438 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0441\u0442\u0438<\/figcaption><\/figure>\n<h2>\u041d\u0430\u0447\u043d\u0435\u043c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0438 <\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u043b\u0438\u0431\u0443 <strong>requests<\/strong> \u0438 <strong>tqdm<\/strong> \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0435\u0440\u0432\u0443\u044e-\u043f\u043e\u043f\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u0430\u043f\u0438\u0448\u043a\u0443: <code>https:\/\/catfact.ninja\/<\/code>. \u041c\u0435\u0442\u0440\u0438\u043a\u043e\u0439 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 RPS (<em>Request per second<\/em>). \u0427\u0435\u043c \u0432\u044b\u0448\u0435 &#8212; \u0442\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043b\u0443\u0447\u0448\u0435.<\/p>\n<pre><code class=\"python\">import time import requests from tqdm import tqdm  URL = 'https:\/\/catfact.ninja\/'   class Api:     def __init__(self, url: str):         self.url = url      def http_get(self, path: str, times: int):         content = []         for _ in tqdm(range(times), desc='Fetching data...', colour='GREEN'):             response = requests.get(self.url + path)             content.append(response.json())         return content   if __name__ == '__main__':     N = 10     api = Api(URL)      start_timestamp = time.time()     print(api.http_get(path='fact\/', times=N))      task_time = round(time.time() - start_timestamp, 2)     rps = round(N \/ task_time, 1)     print(         f\"| Requests: {N}; Total time: {task_time} s; RPS: {rps}. |\\n\"     )<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0432\u043e\u0434 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"bash\">Fetching data...: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 10\/10 [00:06&lt;00:00,  1.52it\/s] [{'fact': 'Despite imagery of cats happily drinking milk from saucers, studies indicate that cats are actually lactose intolerant and should avoid it entirely.', 'length': 148}, {'fact': 'The smallest pedigreed cat is a Singapura, which can weigh just 4 lbs (1.8 kg), or about five large cans of cat food. The largest pedigreed cats are Maine Coon cats, which can weigh 25 lbs (11.3 kg), or nearly twice as much as an average cat weighs.', 'length': 249}, {'fact': 'A cat has 230 bones in its body. A human has 206. A cat has no collarbone, so it can fit through any opening the size of its head.', 'length': 130}, {'fact': \"Cats' hearing is much more sensitive than humans and dogs.\", 'length': 58}, {'fact': 'The first formal cat show was held in England in 1871; in America, in 1895.', 'length': 75}, {'fact': 'In contrast to dogs, cats have not undergone major changes during their domestication process.', 'length': 94}, {'fact': 'Ginger tabby cats can have freckles around their mouths and on their eyelids!', 'length': 77}, {'fact': 'Cats bury their feces to cover their trails from predators.', 'length': 59}, {'fact': 'While it is commonly thought that the ancient Egyptians were the first to domesticate cats, the oldest known pet cat was recently found in a 9,500-year-old grave on the Mediterranean island of Cyprus. This grave predates early Egyptian art depicting cats by 4,000 years or more.', 'length': 278}, {'fact': 'Relative to its body size, the clouded leopard has the biggest canines of all animals\u2019 canines. Its dagger-like teeth can be as long as 1.8 inches (4.5 cm).', 'length': 156}] | Requests: 10; Total time: 6.61 s; RPS: 1.5. | <\/code><\/pre>\n<p>RPS &#8212; 1.5. \u041e\u0447\u0435\u043d\u044c \u0433\u0440\u0443\u0441\u0442\u043d\u043e. \u0423 \u043c\u0435\u043d\u044f \u0435\u0449\u0435 \u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u043e\u043c\u0430. \u041d\u0443 \u0442\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0447\u0435\u0433\u043e.<\/p>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441? \u041e\u0442\u0432\u0435\u0442: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>requests.Session<\/strong> <br \/>E\u0441\u043b\u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0445\u043e\u0441\u0442\u0443, \u0431\u0430\u0437\u043e\u0432\u043e\u0435 TCP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. (\u0446\u0438\u0442\u0430\u0442\u0430 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <strong>requests<\/strong>)<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044e<\/h2>\n<pre><code>    def http_get_with_session(self, path: str, times: int):         content = []         with requests.session() as session:             for _ in tqdm(range(times), desc='Fetching data...', colour='GREEN'):                 response = session.get(self.url + path)                 content.append(response.json())         return content<\/code><\/pre>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0432 \u043c\u0435\u0442\u043e\u0434, \u0438 \u0432\u044b\u0437\u0432\u0430\u0432 \u0435\u0433\u043e, \u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"bash\">Fetching data...: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 10\/10 [00:02&lt;00:00,  3.88it\/s] [{'fact': 'Cats purr at the same frequency as an idling diesel engine, about 26 cycles per second.', 'length': 87}, {'fact': 'Cats eat grass to aid their digestion and to help them get rid of any fur in their stomachs.', 'length': 92}, {'fact': 'A cat\u2019s heart beats nearly twice as fast as a human heart, at 110 to 140 beats a minute.', 'length': 88}, {'fact': 'The world\u2019s rarest coffee, Kopi Luwak, comes from Indonesia where a wildcat known as the luwak lives. The cat eats coffee berries and the coffee beans inside pass through the stomach. The beans are harvested from the cat\u2019s dung heaps and then cleaned and roasted. Kopi Luwak sells for about $500 for a 450 g (1 lb) bag.', 'length': 319}, {'fact': 'There are more than 500 million domestic cats in the world, with approximately 40 recognized breeds.', 'length': 100}, {'fact': 'Cats sleep 16 to 18 hours per day. When cats are asleep, they are still alert to incoming stimuli. If you poke the tail of a sleeping cat, it will respond accordingly.', 'length': 167}, {'fact': 'Since cats are so good at hiding illness, even a single instance of a symptom should be taken very seriously.', 'length': 109}, {'fact': 'At 4 weeks, it is important to play with kittens so that they do not develope a fear of people.', 'length': 95}, {'fact': 'The technical term for a cat\u2019s hairball is a \u201cbezoar.\u201d', 'length': 54}, {'fact': 'Baking chocolate is the most dangerous chocolate to your cat.', 'length': 61}] | Requests: 10; Total time: 2.58 s; RPS: 3.9. | <\/code><\/pre>\n<p>\u041f\u043e\u0447\u0442\u0438 4 RPS, \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 1.5 \u0443\u0436\u0435 \u043f\u0440\u043e\u0440\u044b\u0432.<br \/>\u041d\u043e \u043d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f i\/o time \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u0445\u043d\u0440\u043e\u043d\u043d\u044b\u0445\/\u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c. \u042d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0445\u043e\u0442\u044f \u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0430 \u043f\u043e\u0442\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0438 \u0442.\u0434. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043a\u0435\u0439\u0441\u0430.<\/p>\n<h2>async \/ await<\/h2>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"python\">def run_case(func, path, times):     start_timestamp = time.time()          asyncio.run(func(path, times))      task_time = round(time.time() - start_timestamp, 2)     rps = round(times \/ task_time, 1)     print(         f\"| Requests: {times}; Total time: {task_time} s; RPS: {rps}. |\\n\"     )<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 (\u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c <strong>aiohttp, <\/strong>\u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0440\u0435\u043a\u0432\u0435\u0441\u0442\u044b \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0435):<\/p>\n<pre><code class=\"python\">    async def async_http_get(self, path: str, times: int):         async with aiohttp.ClientSession() as session:             content = []             for _ in tqdm(range(times), desc='Async fetching data...', colour='GREEN'):                 response = await session.get(url=self.url + path)                 content.append(await response.text(encoding='UTF-8'))             return content<\/code><\/pre>\n<pre><code class=\"python\">if __name__ == '__main__': N = 50     api = Api(URL)     run_case(api.async_http_get, path='fact\/', times=N)<\/code><\/pre>\n<p>\u0412\u0438\u0434\u0438\u043c:<\/p>\n<pre><code>Async fetching data...: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 50\/50 [00:12&lt;00:00,  3.99it\/s] | Requests: 50; Total time: 12.55 s; RPS: 4.0. | <\/code><\/pre>\n<p>\u0423\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0441\u043e\u0431\u043e \u043d\u0435\u0442. \u042f \u0434\u0443\u043c\u0430\u044e \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0432 i\/o \u0442\u0430\u0439\u043c\u0435 \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0430\u043c\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443 (\u0441\u043b\u044b\u0448\u0430\u043b \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0440\u0443\u0433\u0430\u044e\u0442 \u044d\u0442\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432 python). \u041a\u0430\u043a \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e.<\/p>\n<p>\u041d\u0430 \u0441\u043b\u043e\u0432\u0430\u0445 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0442\u0430\u043a. <br \/>&#8212; \u0412 \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441.<br \/>&#8212; \u041d\u0435 \u0434\u043e\u0436\u0438\u0434\u0430\u044f\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0430, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u043e\u0442\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043d\u043e\u0432\u0430 event loop&#8217;\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u043e &#171;for \u0446\u0438\u043a\u043b\u0443&#187; \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u043e\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441.<br \/>&#8212; \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043e\u0442\u0434\u0430\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u0432\u0435\u043d\u0442 \u043b\u0443\u043f\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b. \u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0430 (\u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441), \u0442\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0435\u0439, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0441\u043c. \u043f\u0443\u043d\u043a\u0442 2.<br \/>&#8212; \u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043a\u043e\u0434-\u0442\u043e \u0432\u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0430\u0441\u0438\u0445\u043d\u0440\u043e\u043d\u043d\u044b\u0439, \u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f &#171;\u0440\u0430\u0437\u043e\u043c&#187;. \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u0434\u043e\u0439\u0442\u0438 \u043a \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 <strong>asyncio.gather.<\/strong><\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c asyncio.gather<\/h2>\n<p>Gather &#8212; \u043a\u0430\u043a \u043d\u0438 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e \u0441 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c. \u041c\u0435\u0442\u043e\u0434 gather \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438\u0445 \u0440\u0430\u0437\u043e\u043c (\u0442\u043e\u0436\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e). \u0422\u043e \u0435\u0441\u0442\u044c, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f, \u043c\u044b \u0432 \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0445 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c.<\/p>\n<p>\u0411\u044b\u043b\u043e:<br \/>[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -><br \/>[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] ->[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443]<\/p>\n<p>\u0410 \u0441\u0442\u0430\u043b\u043e:<br \/>[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] ->[c\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -><br \/>[\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443] -> [\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0443]<\/p>\n<pre><code class=\"python\">    async def async_gather_http_get(self, path: str, times: int):         async with aiohttp.ClientSession() as session:             tasks = []             for _ in tqdm(range(times), desc='Async gather fetching data...', colour='GREEN'):                 tasks.append(asyncio.create_task(session.get(self.url + path)))              responses = await asyncio.gather(*tasks)             return [await r.json() for r in responses]<\/code><\/pre>\n<pre><code class=\"python\">if __name__ == '__main__': N = 50     api = Api(URL)     run_case(api.async_gather_http_get, path='fact\/', times=N)<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c&#8230; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c&#8230; \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c. \u041a\u0443\u0440\u0441\u043e\u0440 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0438\u0433\u0430\u0442\u044c \u0432 \u043e\u043a\u043d\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0430. \u041d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 &#8212; \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u0428\u0442\u0438\u0440\u043b\u0438\u0446.<\/p>\n<p>\u041f\u0443\u0442\u0435\u043c \u043c\u0443\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0435\u0431\u0430\u0433\u0430 \u0438 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u044f \u043f\u043e\u043d\u044f\u043b &#8212; \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432 \u043c\u043e\u0435\u043c VPN. \u0415\u0433\u043e \u0443\u0437\u043b\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0433\u0434\u0435-\u0442\u043e \u0432 \u044e\u0440\u0438\u0441\u0434\u0438\u043a\u0446\u0438\u0438 Cloudflare. \u0410 \u043e\u043d\u0438<\/p>\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-335130","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335130","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=335130"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335130\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}