Xx CGI traffic control and xxcgi Traffic Control

Source: Internet
Author: User

Xx CGI traffic control and xxcgi Traffic Control
Traffic control is divided into two steps. First, the user's ip address is restricted in the CGI framework, and second, the traffic of each CGI is restricted. 1. IP-based traffic control saves ip-based access information using shared memory (shm. In the configuration file, <variable name = "ip_limit_default" limit_int = "60" shm_key = "1653" recal_int = "300" max_count = "600"> shm_key is the id of the shared memory, limit_int is the frozen time after the user exceeds the limit, recal_int is the statistical time, max_count is the maximum number of requests allowed in the statistical time. After httpd is started, the first accessed cgi is initialized for shm, applying for a continuous space and initializing it to 0. as shown in the shm structure: when a request arrives, hash is performed based on the user's ip address. Our algorithm is simple, and the last byte of the ip address is obtained, the ip address is hashed to 256 segments (as shown in), and then queried sequentially based on the key (ip address) in each segment. The minimum count of the over-node is counted during the search. If no node is found, empty nodes are used first, unupdated nodes are used for 24 hours, and the minimum number of accesses is used (that is, the minimum count node ). In this way, a node is always returned. Reset count and time for each recal_int time. If count exceeds max_count, the user will be frozen for the limit_int time, and reset the time and count after the limit_int time. All updates here are based on the arrival of user requests. The system does not aging shm Nodes Based on time. 2. CGI-based traffic control uses CKV timeout to count CGI traffic. Create two keys in CKV. The LockKey is used to calculate the time, and the LimitKey is used to calculate the number of times. LockKey automatically expires Based on the specified expire time. When each request arrives, get Limitkey and 1. If the upper limit is not reached, check whether the LockKey has expired. If the upper limit is reached, reset the LimitKey and allow the access. If the upper limit is not reached, the access is restricted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.