- Mastering Concurrency in Python
- Quan Nguyen
- 325字
- 2021-06-10 19:24:10
Avoid making a large number of requests
Each time one of the programs that we have been discussing runs, it makes HTTP requests to a server that manages the site that you'd like to extract data from. This process happens significantly more frequently and over a shorter amount of time in a concurrent program, where multiple requests are being submitted to that server.
As mentioned before, servers nowadays have the ability to handle multiple requests simultaneously with ease. However, to avoid having to overwork and overconsume resources, servers are also designed to stop answering requests that come in too frequently. Websites of big tech companies, such as Amazon or Twitter, look for large amounts of automated requests that are made from the same IP address and implement different response protocols; some requests might be delayed, some might be refused a response, or the IP address might even be banned from making further requests for a specific amount of time.
Interestingly, making repeated, heavy-duty requests to servers is actually a form of hacking a website. In Denial of Service (DoS) and Distributed Denial of Service (DDoS) attacks, a very large number of requests are made at the same time to the server, flooding the bandwidth of the targeted server with traffic, and as a result, normal, nonmalicious requests from other clients are denied because the servers are busy processing the concurrent requests, as illustrated in the following diagram:
It is therefore important to space out the concurrent requests that your application makes to a server so that the application would not be considered an attacker and be potentially banned or treated as a malicious client. This could be as simple as limiting the maximum number of threads/requests that can be implemented at a time in your program or pausing the threading for a specific amount of time (for example, using the time.sleep() function) before making a request to the server.
- SQL Server 從入門到項目實踐(超值版)
- Learning Neo4j
- Learning Spring 5.0
- 數據結構(Python語言描述)(第2版)
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第2版)
- MySQL數據庫基礎實例教程(微課版)
- Spring Boot企業級項目開發實戰
- Mastering JavaScript Design Patterns(Second Edition)
- 人工智能算法(卷1):基礎算法
- Python 3 數據分析與機器學習實戰
- Solutions Architect's Handbook
- 視窗軟件設計和開發自動化:可視化D++語言
- 從零開始構建深度前饋神經網絡:Python+TensorFlow 2.x
- HTML5+CSS3+JavaScript案例實戰
- 深入理解C++11:C++11新特性解析與應用