当前位置: 首页 > news >正文

seo关键词如何设置东莞seo排名外包

seo关键词如何设置,东莞seo排名外包,辽阳企业网站建设费,WordPress主题 berry1.背景 1.什么是单机限流? 小伙伴们或许遇到过下图这样的限流配置 又或者是这样的Nacos动态配置限流规则: 以上这些是什么限流?没错,就是单机限流,那么单机限流有什么弊端呢? 假设我们集群部署3台机器&a…

1.背景

1.什么是单机限流?

小伙伴们或许遇到过下图这样的限流配置

又或者是这样的Nacos动态配置限流规则:

 以上这些是什么限流?没错,就是单机限流,那么单机限流有什么弊端呢?

假设我们集群部署3台机器(NodeA/NodeB/NodeC),在某时刻,同时有25个请求进来,假设NodeA收到12个请求,NodeB 8个,NodeC 5个,并且每个单机限流qps=10,那么这个时候,NodeA将会触发限流,有两个请求BLOCK掉,这是由于可能发生的流量不均导致NodeA节点流量过高导致限流,这是因为每个机器都是自己管自己,有没有一种方法能够统筹调度呢?这就得提到集群限流了

 2.什么是集群限流

 集群限流就是,弄一台Token Server,每个客户端机器作为Token Client,有请求进来,Token Client就会向Token Server拿令牌,拿到令牌则不限流,反正则限流。其中Token Server可以作为独立运行的项目,也可以内嵌式内嵌至每个节点中(需将其中一台机器设置为Token Server,如果Token Server节点所在机器宕机,可以将其他Client节点设置成server,sentinel有相关api提供该操作)

例如上面的例子,集群内有3个节点,如果每个节点能承受10的请求,那么加起来就是3x10=30个请求。也就是说只要qps不超过30个请求都不会触发限流。

2.sentinel实现集群限流

1. 以spring-boot项目构建 sentinel-token-server

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion> <groupId>com.lee.sentinel.tokenserver</groupId><artifactId>sentinel-token-server</artifactId><version>0.0.1-SNAPSHOT</version><name>sentinel-token-server</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><spring-boot.version>2.3.7.RELEASE</spring-boot.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><exclusions><exclusion><groupId>com.alibaba.spring</groupId><artifactId>spring-context-support</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--slf4j--><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></dependency> <!--nacos配置中心--><dependency><groupId>com.alibaba.boot</groupId><artifactId>nacos-config-spring-boot-starter</artifactId><version>0.2.12</version><!--由于jar包冲突,此处排除冲突jar,重新导入高版本jar--><!--nacos-spring-context-1.1.1.jar需要比spring-context-support-1.0.8.jar更高版本的jar--><exclusions><exclusion><groupId>com.alibaba.spring</groupId><artifactId>spring-context-support</artifactId></exclusion></exclusions></dependency><!--重新引入jar包--><dependency><groupId>com.alibaba.spring</groupId><artifactId>spring-context-support</artifactId><version>1.0.11</version></dependency><!--sentinel-cluster--><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-cluster-server-default</artifactId><version>1.8.5</version></dependency> <!--sentinel dashboard--><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-transport-simple-http</artifactId><version>1.8.5</version></dependency><!--sentinel dashboard -> nacos 配置动态感知--><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId><version>1.8.5</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

application.properties

server.port=9009
#应用名称
spring.application.name=sentinel-token-server
#nacos config center
nacos.config.server-addr=192.168.1.105:8848

ClusterServer启动类


import java.util.HashSet;
import java.util.Set;import com.alibaba.csp.sentinel.cluster.server.ClusterTokenServer;
import com.alibaba.csp.sentinel.cluster.server.SentinelDefaultTokenServer;
import com.alibaba.csp.sentinel.cluster.server.config.ClusterServerConfigManager;
import com.alibaba.csp.sentinel.cluster.server.config.ServerTransportConfig;public class ClusterServer {private static final int TOKEN_SERVER_PORT = 7777;private static final int IDLE_SECONDS = 600;public static void main(String[] args) throws Exception {ClusterTokenServer tokenServer = new SentinelDefaultTokenServer();ServerTransportConfig serverConfig = new ServerTransportConfig(TOKEN_SERVER_PORT, IDLE_SECONDS); ClusterServerConfigManager.loadGlobalTransportConfig( serverConfig ); //可以设置多个namespaceSet<String> namespaceSet = new HashSet<String>();namespaceSet.add("user-service"); //dataId=user-service-flow-rulesClusterServerConfigManager.loadServerNamespaceSet( namespaceSet ); tokenServer.start();}
}

SpringBoot启动类:

 基于spring-boot SPI机制初始化限流规则:

ClusterTokenInitFunc:从

import java.util.List;import com.alibaba.csp.sentinel.cluster.flow.rule.ClusterFlowRuleManager;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
import com.alibaba.csp.sentinel.init.InitFunc;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;public class ClusterTokenInitFunc implements InitFunc {private String remoteAddress = "192.168.1.105:8848";// nacos配置中心地址private String groupId = "SENTINEL_GROUP";private String dataId_postfix = "-flow-rules";@Overridepublic void init() throws Exception {// TODO Auto-generated method stubloadFlowRuleByNacos();}private void loadFlowRuleByNacos() {// TODO Auto-generated method stub// 从Nacos上获取配置进行加载ClusterFlowRuleManager.setPropertySupplier(namespace -> {// namespace在ClusterServer.java中已配置String dataId = namespace + dataId_postfix; // user-service-flow-rules、 coupon-service-flow-rulesReadableDataSource<String, List<FlowRule>> readableDataSource = new NacosDataSource<>(remoteAddress,groupId, dataId, source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));return readableDataSource.getProperty();});}}

其中,我的Nacos配置(dataId=user-service-flow-rules)设置如下:

[{"resource":"com.lee.demo.dubbo.demo.user.ISentinelService","grade":1,"count":2,"clusterMode":true,"clusterConfig":{"flowId":"1001","thresholdType":1,"fallbackToLocalWhenFail":true}},{"resource":"com.lee.demo.dubbo.demo.user.IHelloService","grade":1,"count":30,"clusterMode":true,"clusterConfig":{"flowId":"1002","thresholdType":1,"fallbackToLocalWhenFail":true}}
]

至此sentinel-token-server搭建完成,启动服务

2. 配置客户端Token Client

导包

        <!--nacos配置中心--><dependency><groupId>com.alibaba.boot</groupId><artifactId>nacos-config-spring-boot-starter</artifactId><version>0.2.12</version><!--由于jar包冲突,此处排除冲突jar,重新导入高版本jar--><!--nacos-spring-context-1.1.1.jar需要比spring-context-support-1.0.8.jar更高版本的jar--><exclusions><exclusion><groupId>com.alibaba.spring</groupId><artifactId>spring-context-support</artifactId></exclusion></exclusions></dependency><!--重新引入jar包--><dependency><groupId>com.alibaba.spring</groupId><artifactId>spring-context-support</artifactId><version>1.0.11</version></dependency><!--sentinel-dubbo-adapter --><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-apache-dubbo-adapter</artifactId><version>1.8.5</version></dependency><!--sentinel dashboard--><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-transport-simple-http</artifactId><version>1.8.5</version></dependency><!--sentinel dashboard -> nacos 配置动态感知--><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId><version>1.8.5</version></dependency><!--sentinel-token-cluster--><dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-cluster-client-default</artifactId><version>1.8.5</version></dependency> 

 加载集群流控规则:

 ClusterFlowRuleInitFunc.java

import java.util.List;import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.cluster.client.config.ClusterClientAssignConfig;
import com.alibaba.csp.sentinel.cluster.client.config.ClusterClientConfig;
import com.alibaba.csp.sentinel.cluster.client.config.ClusterClientConfigManager;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
import com.alibaba.csp.sentinel.init.InitFunc;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;public class ClusterFlowRuleInitFunc implements InitFunc{private static final String CLUSTER_SERVER_HOST = "localhost";private static final int CLUSTER_SERVER_PORT = 7777;private static final int REQUEST_TIME_OUT = 20000;private static final String remoteAddress = "192.168.1.105:8848";private static final String groupId = "SENTINEL_GROUP";  private static final String FLOW_POSTFIX="-flow-rules";private static final String APP_NAME="user-service";@Overridepublic void init() throws Exception {// TODO Auto-generated method stub//声明为Token ClientClusterStateManager.applyState(ClusterStateManager.CLUSTER_CLIENT);//加载集群限流Token Server loadClusterClientConfig(); //加载单机限流规则(如果Token Server不可用,退化到单机限流)initFlowRulesWithDatasource(); }/*** 集群限流规则* */private void loadClusterClientConfig() {ClusterClientAssignConfig assignConfig  = new ClusterClientAssignConfig();assignConfig.setServerHost(CLUSTER_SERVER_HOST);assignConfig.setServerPort(CLUSTER_SERVER_PORT);ClusterClientConfigManager.applyNewAssignConfig(assignConfig);ClusterClientConfig clientConfig = new ClusterClientConfig();clientConfig.setRequestTimeout(REQUEST_TIME_OUT);ClusterClientConfigManager.applyNewConfig(clientConfig);}/*** 单机限流规则* */private void initFlowRulesWithDatasource() {  String dataId = APP_NAME + FLOW_POSTFIX;
//		ReadableDataSource<String, List<FlowRule>> readableDataSource = new NacosDataSource<>(
//				remoteAddress, groupId, dataId
//				,source->JSON.parseObject(source,new TypeReference<List<FlowRule>>() {}));ReadableDataSource<String, List<FlowRule>> readableDataSource = new NacosDataSource<>(remoteAddress, groupId, dataId, new Converter<String, List<FlowRule>>() { @Overridepublic List<FlowRule> convert(String source) {// TODO Auto-generated method stubSystem.out.println("source:"+source); List<FlowRule> rules = JSON.parseObject(source,new TypeReference<List<FlowRule>>() {}); return rules;}});    FlowRuleManager.register2Property(readableDataSource.getProperty());} }

Controller:

至此,Token Client配置完成。

接下来启动3个客户端,模拟集群:

 

 Sentinel-Dashboard上可以看到user-service有三台集群机器:

使用jmeter压测工具进行压测:

 压测结果如下,可以看到com.lee.demo.dubbo.demo.user.ISentinelService.testSentinel() 接口的qps一直不会超过6个请求,这个峰值是怎么计算的来的呢?因为我上面提到的Nacos集群限流配置dataId=user-service-flow-rules中配置com.lee.demo.dubbo.demo.user.ISentinelService的qps=2,而我们总共有3台机器,因此集群限流max qps:2x3=6

 至此,sentinel上线集群限流demo已完成,如有疑问请在评论区评论。


文章转载自:
http://monostylous.dztp.cn
http://ise.dztp.cn
http://cryptobiote.dztp.cn
http://douai.dztp.cn
http://rafflesia.dztp.cn
http://colourcast.dztp.cn
http://diabolo.dztp.cn
http://serviceman.dztp.cn
http://uncomforting.dztp.cn
http://constringe.dztp.cn
http://plo.dztp.cn
http://altho.dztp.cn
http://kindergarener.dztp.cn
http://ovidian.dztp.cn
http://agname.dztp.cn
http://gaedhelic.dztp.cn
http://semibull.dztp.cn
http://swannery.dztp.cn
http://tangentially.dztp.cn
http://hogshead.dztp.cn
http://armpad.dztp.cn
http://comatula.dztp.cn
http://kephalin.dztp.cn
http://benzpyrene.dztp.cn
http://collision.dztp.cn
http://precise.dztp.cn
http://floruit.dztp.cn
http://gadgetry.dztp.cn
http://municipalism.dztp.cn
http://adjudicative.dztp.cn
http://transignification.dztp.cn
http://ultramontanism.dztp.cn
http://abfarad.dztp.cn
http://jataka.dztp.cn
http://hematocryal.dztp.cn
http://raphaelesque.dztp.cn
http://hackmatack.dztp.cn
http://perfidious.dztp.cn
http://delusive.dztp.cn
http://racialist.dztp.cn
http://udine.dztp.cn
http://uralite.dztp.cn
http://bedcover.dztp.cn
http://food.dztp.cn
http://impropriety.dztp.cn
http://kinswoman.dztp.cn
http://wildling.dztp.cn
http://completeness.dztp.cn
http://assemble.dztp.cn
http://inexplicability.dztp.cn
http://gelatinise.dztp.cn
http://childmind.dztp.cn
http://hateworthy.dztp.cn
http://axiomatically.dztp.cn
http://fingerful.dztp.cn
http://unilateralization.dztp.cn
http://matral.dztp.cn
http://ebbet.dztp.cn
http://contingently.dztp.cn
http://supramaximal.dztp.cn
http://cist.dztp.cn
http://actinomycotic.dztp.cn
http://dieter.dztp.cn
http://vapid.dztp.cn
http://tzaritza.dztp.cn
http://oxidize.dztp.cn
http://carbinol.dztp.cn
http://episcopize.dztp.cn
http://unasked.dztp.cn
http://leiotrichi.dztp.cn
http://somnolent.dztp.cn
http://karaism.dztp.cn
http://ropewalker.dztp.cn
http://avram.dztp.cn
http://unrip.dztp.cn
http://reattempt.dztp.cn
http://gimbal.dztp.cn
http://sneering.dztp.cn
http://overwrap.dztp.cn
http://craniate.dztp.cn
http://sheathe.dztp.cn
http://expository.dztp.cn
http://almost.dztp.cn
http://sylphlike.dztp.cn
http://atmolyzer.dztp.cn
http://toolmaking.dztp.cn
http://loathe.dztp.cn
http://elixir.dztp.cn
http://conduit.dztp.cn
http://unmortared.dztp.cn
http://antimalarial.dztp.cn
http://dehydrofreezing.dztp.cn
http://acidfast.dztp.cn
http://oyes.dztp.cn
http://turbellarian.dztp.cn
http://peen.dztp.cn
http://evanish.dztp.cn
http://macrocephali.dztp.cn
http://septennial.dztp.cn
http://revert.dztp.cn
http://www.dt0577.cn/news/108421.html

相关文章:

  • 绍兴网站专业制作资源搜索引擎搜索神器网
  • 网站服务器崩溃个人网页制作
  • 公司网站开发哪家好商丘seo博客
  • 设计 日本 网站市场营销实务
  • 网页设计范文seo用什么工具
  • wordpress 插件 表河南企业站seo
  • 网站导航栏的设计与实现网络营销的发展前景
  • 松江建网站宁波seo快速优化课程
  • 毕设做网站什么主题比较好东莞公司seo优化
  • 惠州网站营销推广2024年阳性最新症状
  • windows删除wordpress包头seo
  • 做知识产权服务的网站北京网站seo哪家公司好
  • 长沙做网站推荐怎样把个人介绍放到百度
  • 建设购物网站优化教程网站推广排名
  • 如何制作免费网站windows优化大师收费吗
  • wordpress运行慢深圳seo网络推广
  • 网站建设套餐价格头条发布视频成功显示404
  • 广州的十七做网站谷歌搜索引擎免费入口2022
  • 小白学编程应该从哪里开始学seo关键词排行优化教程
  • WordPress淘客转链插件seo搜索优化培训
  • 如何建设学校网站百度经验app
  • 网站建设交流论坛周口网络推广哪家好
  • 云南网站建设一度科技公司苏州网站建设公司排名
  • 做自己移动端网站整站营销系统
  • 贵港市城乡住房建设厅网站百度建站云南服务中心
  • 备案网站网站建成后应该如何推广
  • 常用网站开发软件6sem论坛
  • 网上做家教那个网站好如何优化
  • 技术支持 创思佳网站建设百度网站优化培训
  • vs2017做的网站成都seo顾问