In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly talks about "Rainbond's method of limiting the request rate of micro-services". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "Rainbond's method of limiting the request rate of micro-services".
Rainbond supports global rate limiting based on envoy by default. Presented in the comprehensive network governance plug-in provided by default by Rainbond. In this article, we present a use case that shows how global rate limits are used in Rainbond.
Precondition
The Rainbond platform has been deployed.
Deploy accessible Demo services in Rainbond.
A comprehensive network governance plug-in is enabled for this component.
Reference video
Https://player.bilibili.com/player.html?aid=540728010
Rainbond rate limit setting reference video
Operation flow
1. Use the Redis component to deploy the global restriction service. Use the mirror redis:alpine to create the component. After the component is created, change the alias of port 6379 to REDIS in the port setting to enable the internal service permission.
two。 Deploy the global restriction service, and deploy the global restriction service by mirroring. Use the following DockerRun command to create a component that can be deployed to the same application of the business. Add it and make it dependent on the REDIS component installed in the previous step.
Docker run-e USE_STATSD=false-e REDIS_SOCKET_TYPE=tcp-e REDIS_URL=$ {REDIS_HOST}: ${REDIS_PORT}-e RUNTIME_ROOT=/data-e RUNTIME_SUBDIRECTORY=ratelimit-v / data/-p 8081 barnett/ratelimit:v1.4.0 / bin/ratelimit
After successfully adding, switch to the component port settings page, open port 8081 to internal service, and set the port alias to RATE_LIMIT_SERVER
The default global limit service is the default implementation of envoy, and you can customize the implementation according to envoy's rate limit service API specification.
3. Add rate limit Profil
Enter the environment management of the global restriction service component and add a configuration file with the file path / data/ratelimit/config/config.yaml
Domain: limit.commondescriptors:-key: remote_address rate_limit: unit: second requests_per_unit: 10 # Black list IP-key: remote_address value: 50.0.0.5 rate_limit: unit: second requests_per_unit: 0
Restart the component after adding the configuration file.
This configuration means that the rate is limited by the request source IP. The IP limits access to 50.0.0.5, and other IP addresses limit 10 requests per second.
4. Business components rely on limiting service components and updating plug-in configuration
Edit the topology diagram to make the business component rely on the rate-limiting service component that has just been deployed, then go to the business component plug-in management, and click on the activated comprehensive governance plug-in to view the configuration entry. Make the following configuration in the configuration form:
Configure OPEN_LIMIT to yes
The configuration LIMIT_DOMAIN is limit.common, which corresponds to the configuration domain in the configuration file above.
Update the plug-in configuration after the configuration is complete.
5. Verify that the rate limit is in effect
We can use the ab command for stress testing
Ab-n 1000-c 20 http://5000.gr425688.duaqtz0k.17f4cc.grapps.cn/
The results are shown as follows:
Concurrency Level: 20
Time taken for tests: 6.132 seconds
Complete requests: 1000
Failed requests: 794
(Connect: 0, Receive: 0, Length: 794, Exceptions: 0)
Non-2xx responses: 794
It can be seen that 794 of the 1000 requests are limited, and the access code of the request rejected by the rate limit is 429.
common problem
Can you customize the development rate limit service?
Of course, the service implementation used in this article is envoy ratelimit, which you can implement independently based on the API specification.
Whether more rate limit policies are supported
Rate limiting policies can also support limits based on request headers, but currently only based on source IP addresses.
At this point, I believe you have a deeper understanding of "Rainbond's method of limiting the request rate of micro-services". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.