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

怎么通过局域网建设网站网页设计实训报告

怎么通过局域网建设网站,网页设计实训报告,衡阳市做淘宝网站建设,网站建设时间计划读、写队列 创建主题时,可以指定 writeQueueNums(写队列的个数)、readQueueNums(读队列的个数)。生产者发送消息时,使用写队列的个数返回路由信息;消费者消费消息时,使用读队列的个…

读、写队列

创建主题时,可以指定 writeQueueNums(写队列的个数)、readQueueNums(读队列的个数)。生产者发送消息时,使用写队列的个数返回路由信息;消费者消费消息时,使用读队列的个数返回路由信息。在物理文件层面,只有写队列才会创建文件。默认读、写队列的个数都是 16。

比如写队列的个数是 16,则创建 16 个文件夹,代表 0 - 15;读队列的个数是 8,则只会消费 0 - 7 这 8 个队列中的消息。

要求 readQueueNums >= writeQueueNums,最佳方案是两者相等。RocketMQ 设置读、写队列的目的是方便队列的扩容、缩容。

比如在原来指定读、写队列都是 16 的基础上进行扩容到 8 个。在不需要重启应用程序的情况下,先缩容写队列,由 0 - 15 缩容至 0 - 7。等到 8 - 15 队列中的消息全部消费完之后,再缩容读队列,由 0 - 15 缩容至 0 - 7。

队列的选择

方式一、指定 queueId 来选择具体的队列

DefaultMQProducer 的 send / sendOneway 方法中可携带 MessageQueue 参数。而 MessageQueue 可以指定 topic、queueId、brokerName 三个参数。

public MessageQueue(String topic, String brokerName, int queueId) {this.topic = topic;this.brokerName = brokerName;this.queueId = queueId;
}

方式二、根据 MessageQueueSelector 策略来选择队列

DefaultMQProducer 的 send / sendOneway 方法中可携带 MessageQueueSelector 参数。

public SendResult send(Message msg, MessageQueueSelector selector, Object arg);
public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback);

RocketMQ 内部定义了三种 MessageQueueSelector 策略。

  • SelectMessageQueueByHash:基于方法参数arg的哈希值,对队列总数取模,选择对应下标的队列。
  • SelectMessageQueueByRandom:基于队列总数生成一个随机数,选择对应下标的队列。
  • SelectMessageQueueByMachineRoom:返回空。
public class SelectMessageQueueByHash implements MessageQueueSelector {@Overridepublic MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {// 取arg方法参数的哈希值,再对队列总数取模int value = arg.hashCode() % mqs.size();if (value < 0) {value = Math.abs(value);}// 选择对应的队列return mqs.get(value);}
}
public class SelectMessageQueueByRandom implements MessageQueueSelector {private Random random = new Random(System.currentTimeMillis());@Overridepublic MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {// 基于队列总数生成一个随机数int value = random.nextInt(mqs.size());// 选择对应的队列return mqs.get(value);}
}

方式三、基于Broker的可用性采取轮询的策略选择队列

DefaultMQProducer 的 send / sendOneway 方法可以不携带 MessageQueue、MessageQueueSelector,简单看下这种方式的队列是如何选择。

这种方式下的 send / sendOneway 方法中内部会调用如下方法:

MessageQueue mqSelected = this.selectOneMessageQueue(topicPublishInfo, lastBrokerName);

进入方法内部,看一下处理逻辑。

public MessageQueue selectOneMessageQueue(final TopicPublishInfo tpInfo, final String lastBrokerName) {return this.mqFaultStrategy.selectOneMessageQueue(tpInfo, lastBrokerName);
}

MQFaultStrategy

public MessageQueue selectOneMessageQueue(final TopicPublishInfo tpInfo, final String lastBrokerName) {// 如果开启了发送延迟规避机制,默认falseif (this.sendLatencyFaultEnable) {try {int index = tpInfo.getSendWhichQueue().incrementAndGet();for (int i = 0; i < tpInfo.getMessageQueueList().size(); i++) {int pos = Math.abs(index++) % tpInfo.getMessageQueueList().size();if (pos < 0)pos = 0;// 获取指定下标的队列MessageQueue mq = tpInfo.getMessageQueueList().get(pos);// 如果队列对应的Broker判定为可用,则返回该队列;否则基于轮询的策略选择下一个队列重复上述步骤进行判断if (latencyFaultTolerance.isAvailable(mq.getBrokerName()))return mq;}final String notBestBroker = latencyFaultTolerance.pickOneAtLeast();// 根据BrokerName获取存储的写队列的总数int writeQueueNums = tpInfo.getQueueIdByBroker(notBestBroker);if (writeQueueNums > 0) {final MessageQueue mq = tpInfo.selectOneMessageQueue();if (notBestBroker != null) {mq.setBrokerName(notBestBroker);mq.setQueueId(tpInfo.getSendWhichQueue().incrementAndGet() % writeQueueNums);}return mq;} else {latencyFaultTolerance.remove(notBestBroker);}} catch (Exception e) {log.error("Error occurred when selecting message queue", e);}return tpInfo.selectOneMessageQueue();}return tpInfo.selectOneMessageQueue(lastBrokerName);
}

LatencyFaultToleranceImpl

@Override
public boolean isAvailable(final String name) {// 从缓存中获取指定brokerName对应的FaultItem实例final FaultItem faultItem = this.faultItemTable.get(name);// 如果缓存命中if (faultItem != null) {// 判断是否可用,即当前时间-startTimestamp是否>=0return faultItem.isAvailable();}return true;
}@Override
public String pickOneAtLeast() {final Enumeration<FaultItem> elements = this.faultItemTable.elements();List<FaultItem> tmpList = new LinkedList<FaultItem>();while (elements.hasMoreElements()) {final FaultItem faultItem = elements.nextElement();tmpList.add(faultItem);}if (!tmpList.isEmpty()) {Collections.sort(tmpList);final int half = tmpList.size() / 2;if (half <= 0) {return tmpList.get(0).getName();} else {final int i = this.whichItemWorst.incrementAndGet() % half;return tmpList.get(i).getName();}}return null;
}@Override
public void remove(final String name) {this.faultItemTable.remove(name);
}

TopicPublishInfo

public MessageQueue selectOneMessageQueue(final String lastBrokerName) {if (lastBrokerName == null) {return selectOneMessageQueue();} else {for (int i = 0; i < this.messageQueueList.size(); i++) {int index = this.sendWhichQueue.incrementAndGet();int pos = Math.abs(index) % this.messageQueueList.size();if (pos < 0)pos = 0;MessageQueue mq = this.messageQueueList.get(pos);if (!mq.getBrokerName().equals(lastBrokerName)) {return mq;}}return selectOneMessageQueue();}
}public MessageQueue selectOneMessageQueue() {int index = this.sendWhichQueue.incrementAndGet();int pos = Math.abs(index) % this.messageQueueList.size();if (pos < 0)pos = 0;return this.messageQueueList.get(pos);
}

额外分析一下 DefaultMQProducerImpl 的 updateFaultItem 方法。

public void updateFaultItem(final String brokerName, final long currentLatency, boolean isolation) {this.mqFaultStrategy.updateFaultItem(brokerName, currentLatency, isolation);
}

接着看下 MQFaultStrategy 的 updateFaultItem 方法。

private long[] latencyMax = {50L, 100L, 550L, 1000L, 2000L, 3000L, 15000L};
private long[] notAvailableDuration = {0L, 0L, 30000L, 60000L, 120000L, 180000L, 600000L};public void updateFaultItem(final String brokerName, final long currentLatency, boolean isolation) {// 如果开启了发送延迟规避机制if (this.sendLatencyFaultEnable) {// 根据延迟时间计算不可用的时间long duration = computeNotAvailableDuration(isolation ? 30000 : currentLatency);// 更新faultItemTable缓存this.latencyFaultTolerance.updateFaultItem(brokerName, currentLatency, duration);}
}private long computeNotAvailableDuration(final long currentLatency) {for (int i = latencyMax.length - 1; i >= 0; i--) {// 根据延迟时间计算不可用的时间if (currentLatency >= latencyMax[i])return this.notAvailableDuration[i];}return 0;
}

接着分析 LatencyFaultToleranceImpl 的 updateFaultItem 方法的处理逻辑。

@Override
public void updateFaultItem(final String name, final long currentLatency, final long notAvailableDuration) {// 从缓存中获取指定BrokerName对应的FaultItem实例FaultItem old = this.faultItemTable.get(name);// 如果缓存未命中if (null == old) {// 构造 FaultItem 实例final FaultItem faultItem = new FaultItem(name);// 更新 currentLatecy、startTimestamp 属性faultItem.setCurrentLatency(currentLatency);faultItem.setStartTimestamp(System.currentTimeMillis() + notAvailableDuration);// 更新缓存old = this.faultItemTable.putIfAbsent(name, faultItem);if (old != null) {// 更新 currentLatecy、startTimestamp 属性old.setCurrentLatency(currentLatency);old.setStartTimestamp(System.currentTimeMillis() + notAvailableDuration);}// 如果缓存命中  } else {// 更新 currentLatecy、startTimestamp 属性old.setCurrentLatency(currentLatency);old.setStartTimestamp(System.currentTimeMillis() + notAvailableDuration);}
}

文章转载自:
http://dinncootp.stkw.cn
http://dinncobrevier.stkw.cn
http://dinncotardily.stkw.cn
http://dinncosenatorian.stkw.cn
http://dinncomisspeak.stkw.cn
http://dinncobarrable.stkw.cn
http://dinncofilopodium.stkw.cn
http://dinncoorrin.stkw.cn
http://dinncogummy.stkw.cn
http://dinncoliquidate.stkw.cn
http://dinncoanterolateral.stkw.cn
http://dinncobrightsome.stkw.cn
http://dinncowhaleback.stkw.cn
http://dinncopropane.stkw.cn
http://dinncomesaxon.stkw.cn
http://dinncodipetalous.stkw.cn
http://dinncotenonitis.stkw.cn
http://dinncorearrest.stkw.cn
http://dinncocontrabass.stkw.cn
http://dinncorallicart.stkw.cn
http://dinncounforested.stkw.cn
http://dinncossa.stkw.cn
http://dinncoswahili.stkw.cn
http://dinncoascosporic.stkw.cn
http://dinncotrot.stkw.cn
http://dinncoautophagy.stkw.cn
http://dinncobasinful.stkw.cn
http://dinncoconfident.stkw.cn
http://dinncohetman.stkw.cn
http://dinncorepugnant.stkw.cn
http://dinncobiparietal.stkw.cn
http://dinncosothiac.stkw.cn
http://dinncoversemonger.stkw.cn
http://dinncorealisation.stkw.cn
http://dinncoangiocarpy.stkw.cn
http://dinncomillesimal.stkw.cn
http://dinncosioux.stkw.cn
http://dinncolegendary.stkw.cn
http://dinncodomesday.stkw.cn
http://dinncorevulse.stkw.cn
http://dinncomallemuck.stkw.cn
http://dinncocategory.stkw.cn
http://dinncogeum.stkw.cn
http://dinncolymphad.stkw.cn
http://dinncocarlet.stkw.cn
http://dinncodewy.stkw.cn
http://dinncotreescape.stkw.cn
http://dinncograptolite.stkw.cn
http://dinncolectuer.stkw.cn
http://dinncogeneral.stkw.cn
http://dinncoindonesia.stkw.cn
http://dinncoskippable.stkw.cn
http://dinncopiper.stkw.cn
http://dinncoinsider.stkw.cn
http://dinncovinsanto.stkw.cn
http://dinncoduodenary.stkw.cn
http://dinncorequested.stkw.cn
http://dinncorevitalization.stkw.cn
http://dinnconomarch.stkw.cn
http://dinncoruga.stkw.cn
http://dinncounslumbering.stkw.cn
http://dinncotarsus.stkw.cn
http://dinncoreliquary.stkw.cn
http://dinncosoberano.stkw.cn
http://dinncophotopia.stkw.cn
http://dinncocriminological.stkw.cn
http://dinncoidentically.stkw.cn
http://dinncogasconade.stkw.cn
http://dinncoangolese.stkw.cn
http://dinncopehlevi.stkw.cn
http://dinncomachinist.stkw.cn
http://dinncoinhibition.stkw.cn
http://dinncoundissembling.stkw.cn
http://dinncounwit.stkw.cn
http://dinncopouf.stkw.cn
http://dinnconipponian.stkw.cn
http://dinncounremunerative.stkw.cn
http://dinncoinfantilism.stkw.cn
http://dinncocoffeepot.stkw.cn
http://dinncocostermonger.stkw.cn
http://dinncolithonephrotomy.stkw.cn
http://dinncogozitan.stkw.cn
http://dinncodyeable.stkw.cn
http://dinncoconfabulate.stkw.cn
http://dinncomysticlsm.stkw.cn
http://dinncocryotron.stkw.cn
http://dinncosuitable.stkw.cn
http://dinncoinglenook.stkw.cn
http://dinncoswabber.stkw.cn
http://dinncototipotency.stkw.cn
http://dinncotungstenic.stkw.cn
http://dinncopolymerization.stkw.cn
http://dinncopurificator.stkw.cn
http://dinnconudey.stkw.cn
http://dinncotridactylous.stkw.cn
http://dinncofabled.stkw.cn
http://dinncoacer.stkw.cn
http://dinncoliar.stkw.cn
http://dinncobrickwork.stkw.cn
http://dinncohankow.stkw.cn
http://www.dinnco.com/news/103706.html

相关文章:

  • 阿里云部署一个自己做的网站吗抖音搜索seo代理
  • 做视频网站多少钱360免费建站
  • 仪陇建设局网站百度人工服务热线
  • 什么样的公司开做网站baiduseoguide
  • 有什么好的网站厦门seo排名收费
  • 百度竞价推广出价技巧北京搜索引擎优化
  • 怎么查找网站黑马教育培训官网
  • 网站代码在哪里写网络营销推广服务
  • 海南网站优化网络销售工资一般多少
  • 做网站一年多少钱如何制作网站教程
  • 禹城做网站江苏seo技术教程
  • 五金件外发加工网淘宝seo排名优化
  • 网页设计实验报告摘要合肥网站推广优化公司
  • vps搭建个人网站视频剪辑培训
  • 上海品牌网站建设公司旺道seo优化软件怎么用
  • 可以做推广的网站有哪些站长工具ip地址查询域名
  • 创建一个企业网站流程的步骤今日最新闻
  • 郑州疫情最新消息今天seo服务外包费用
  • 提供网站制作手机优化大师官方免费下载
  • 黄岛做网站的公司手机制作网站的软件
  • 做网站送商标邯郸seo
  • 时时彩网站建设teafly最好的推广平台是什么软件
  • 昆明网站推广哪家好百度文库账号登录入口
  • 青岛建站模板制作seovip培训
  • 网站的css文件夹性能优化大师
  • 射阳做网站公司百度网站官网
  • 深圳app开发公司前十名seo黑帽有哪些技术
  • 网页制作与网站开发...门户网站推广方案
  • 根路径 网站产品推广公司
  • 做视频赚钱的国外网站温州seo结算