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

自己做网站必须要学哪些抖音seo培训

自己做网站必须要学哪些,抖音seo培训,做配资网站,discuz做企业网站本文只是分析Letture类型的Redis 池化连接出现的连接超时异常、读超时异常问题。 1.RedisConnectionException 默认是10秒。 通过如下可以配置: public class MyLettuceClientConfigurationBuilderCustomizer implements LettuceClientConfigurationBuilderCusto…

本文只是分析Letture类型的Redis 池化连接出现的连接超时异常、读超时异常问题。

1.RedisConnectionException

默认是10秒。
通过如下可以配置:

public class MyLettuceClientConfigurationBuilderCustomizer implements LettuceClientConfigurationBuilderCustomizer {@Overridepublic void customize(LettuceClientConfiguration.LettuceClientConfigurationBuilder clientConfigurationBuilder) {
//        spring.redis.timeout等价clientConfigurationBuilder.commandTimeout(Duration.ofSeconds(100));
//        控制连接超时时间,默认是10秒ClientOptions.Builder builder = ClientOptions.builder().socketOptions(SocketOptions.builder().connectTimeout(Duration.ofMillis(10)).build());clientConfigurationBuilder.clientOptions(builder.build());}
}

2.RedisCommandTimeoutException

结论:抛出RedisCommandTimeoutException异常并非数据的写一定失败。只不过Redis内部超时逻辑跟写逻辑是异步处理,所以存在写成功后仍然抛出异常的情况。但是只要出现该异常必须得处理。

io.lettuce.core.RedisCommandTimeoutException: Command timed out after 2 second(s)

2.1.CommandHandler限制

CommandHandler是Netty中的handler。只不过其同时充当入栈、出栈handler。通俗点讲是Redis Write & Flush 数据到通道NioSocketChannel的必经之路。

AsyncCommand存在两大核心功能。其一是包裹用户数据,其二是实现了CompletableFuture接口,方便实现异步相关操作。

public class CommandHandler extends ChannelDuplexHandler implements HasQueuedCommands {private void writeSingleCommand(ChannelHandlerContext ctx, RedisCommand<?, ?, ?> command, ChannelPromise promise){if (!isWriteable(command)) {// 此处的就是判断是否存在超时的核心之处,借用CompletableFuture异步操作功能promise.trySuccess();// 此时说明数据写过程中超过用户设定的超时时间return;}...ctx.write(command, promise);// 数据正常写入,最终归宿是服务端}private static boolean isWriteable(RedisCommand<?, ?, ?> command) {return !command.isDone();}
}
public class CompletableFuture<T> implements Future<T>, CompletionStage<T> {public boolean isDone() {return result != null;}
}

通过上述得知,只要CompletableFuture内部的变量result不为空,则就会按TimeoutException处理。所以result值何时赋值呢?

如下所示,CommandHandler处理完数据之后会通过如下方式设置result的值。

public class AsyncCommand<K, V, T> extends CompletableFuture<T> implements RedisCommand<K, V, T>, RedisFuture<T>,CompleteableCommand<T>, DecoratedCommand<K, V, T> {protected void completeResult() {if (command.getOutput() == null) {complete(null);} else if (command.getOutput().hasError()) {doCompleteExceptionally(ExceptionFactory.createExecutionException(command.getOutput().getError()));} else {// 成功发送则Output为字符串类型的“ok”complete(command.getOutput().get());}}
}

3.超时处理时机

3.1.阻塞等待超时

class FutureSyncInvocationHandler extends AbstractInvocationHandler {protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {try {Method targetMethod = this.translator.get(method);// CommandExpiryWriter#writerObject result = targetMethod.invoke(asyncApi, args);if (result instanceof RedisFuture<?>) {...long timeout = getTimeoutNs(command);//用户自定义的超时时间//command:AsyncCommand 利用CompletableFuture异步特性return LettuceFutures.awaitOrCancel(command, timeout, TimeUnit.NANOSECONDS);}return result;} catch (InvocationTargetException e) {throw e.getTargetException();}}
}
public class LettuceFutures {public static <T> T awaitOrCancel(RedisFuture<T> cmd, long timeout, TimeUnit unit) {try {//阻塞 其实内存调用的CompletableFuture#get阻塞方法。如果返回TimeoutExeception则说明AsyncCommand没有执行完毕,超时处理if (!cmd.await(timeout, unit)) {cmd.cancel(true);throw ExceptionFactory.createTimeoutException(Duration.ofNanos(unit.toNanos(timeout)));}return cmd.get();//这个方法还是调用CompletableFuture#get阻塞方法,但是该方法是根据内部属性result进行判断} catch (RuntimeException e) {throw e;} catch (ExecutionException e) {if (e.getCause() instanceof RedisCommandExecutionException) {throw ExceptionFactory.createExecutionException(e.getCause().getMessage(), e.getCause());}if (e.getCause() instanceof RedisCommandTimeoutException) {throw new RedisCommandTimeoutException(e.getCause());}throw new RedisException(e.getCause());} catch (InterruptedException e) {Thread.currentThread().interrupt();throw new RedisCommandInterruptedException(e);} catch (Exception e) {throw ExceptionFactory.createExecutionException(null, e);}}
}

如下伪代码所示:如果result不为null,则根据result类型抛出相关异常。否则通过timedGet在规定时间内阻塞等待,超时则抛出TimeoutException。

public class CompletableFuture<T> implements Future<T>, CompletionStage<T> {public T get(long timeout, TimeUnit unit)throws InterruptedException, ExecutionException, TimeoutException {Object r;long nanos = unit.toNanos(timeout);return reportGet((r = result) == null ? timedGet(nanos) : r);}
}

3.2.定时任务超时处理

public class CommandExpiryWriter implements RedisChannelWriter {public <K, V, T> RedisCommand<K, V, T> write(RedisCommand<K, V, T> command) {potentiallyExpire(command, getExecutorService());//开启定时任务return writer.write(command);//DefaultEndPoint#write}private void potentiallyExpire(RedisCommand<?, ?, ?> command, ScheduledExecutorService executors) {long timeout = applyConnectionTimeout ? this.timeout : source.getTimeout(command);//用户自定义的超时时间if (timeout <= 0) {return;}// 从 timeout 时间之后开始执行定时任务。此时result值如果存在值则说明超时ScheduledFuture<?> schedule = executors.schedule(() -> {if (!command.isDone()) {command.completeExceptionally(ExceptionFactory.createTimeoutException(Duration.ofNanos(timeUnit.toNanos(timeout))));}}, timeout, timeUnit);if (command instanceof CompleteableCommand) {((CompleteableCommand) command).onComplete((o, o2) -> {if (!schedule.isDone()) {schedule.cancel(false);}});}}
}

重点:定时任务判断成功与否的唯一条件就是result是否存在值。情况1,如果此时result = ok表明数据已经在服务端落盘成功,但是同样会抛出RedisCommandTimeoutException。情况2,发送之前出现异常则result值为Throwable类型的异常值。


文章转载自:
http://wanjiacoloring.rhmk.cn
http://wanjiaremind.rhmk.cn
http://wanjiausib.rhmk.cn
http://wanjiaallegro.rhmk.cn
http://wanjiagiber.rhmk.cn
http://wanjiamasterman.rhmk.cn
http://wanjiadraegerman.rhmk.cn
http://wanjiamusket.rhmk.cn
http://wanjiahouseperson.rhmk.cn
http://wanjiaupbuilt.rhmk.cn
http://wanjianightclothes.rhmk.cn
http://wanjiachicle.rhmk.cn
http://wanjiamanumit.rhmk.cn
http://wanjiauncordial.rhmk.cn
http://wanjiadili.rhmk.cn
http://wanjiaflowerlike.rhmk.cn
http://wanjiaafocal.rhmk.cn
http://wanjiaasphyxy.rhmk.cn
http://wanjiaunacknowledged.rhmk.cn
http://wanjiaexamination.rhmk.cn
http://wanjiagoldenrain.rhmk.cn
http://wanjiaaltercate.rhmk.cn
http://wanjiaporcellanous.rhmk.cn
http://wanjiasupermarket.rhmk.cn
http://wanjiatrichotomize.rhmk.cn
http://wanjiadespicably.rhmk.cn
http://wanjiayawmeter.rhmk.cn
http://wanjiaforeground.rhmk.cn
http://wanjiaumpteenth.rhmk.cn
http://wanjiaidentity.rhmk.cn
http://wanjiacoliphage.rhmk.cn
http://wanjiaheady.rhmk.cn
http://wanjiavasal.rhmk.cn
http://wanjiaauthoritative.rhmk.cn
http://wanjialirot.rhmk.cn
http://wanjiatorrance.rhmk.cn
http://wanjiavalued.rhmk.cn
http://wanjiaperversity.rhmk.cn
http://wanjiabrazzaville.rhmk.cn
http://wanjianeedlefish.rhmk.cn
http://wanjiavendace.rhmk.cn
http://wanjiaadaption.rhmk.cn
http://wanjiacharmian.rhmk.cn
http://wanjiascatty.rhmk.cn
http://wanjiawebworm.rhmk.cn
http://wanjiamartinique.rhmk.cn
http://wanjiaschizont.rhmk.cn
http://wanjiaetching.rhmk.cn
http://wanjiamattery.rhmk.cn
http://wanjiasmd.rhmk.cn
http://wanjiainsubordinate.rhmk.cn
http://wanjiaolympic.rhmk.cn
http://wanjiaauthoress.rhmk.cn
http://wanjiachrome.rhmk.cn
http://wanjiaatempo.rhmk.cn
http://wanjiaultramicrotome.rhmk.cn
http://wanjiatauranga.rhmk.cn
http://wanjiacommentary.rhmk.cn
http://wanjiabinaural.rhmk.cn
http://wanjiaspicula.rhmk.cn
http://wanjiaxanthine.rhmk.cn
http://wanjiawanking.rhmk.cn
http://wanjiamucid.rhmk.cn
http://wanjiahyperploidy.rhmk.cn
http://wanjiacolosseum.rhmk.cn
http://wanjiabucketeer.rhmk.cn
http://wanjiamipmap.rhmk.cn
http://wanjiaminnie.rhmk.cn
http://wanjiaconceptualise.rhmk.cn
http://wanjiacuddlesome.rhmk.cn
http://wanjiaaustralorp.rhmk.cn
http://wanjiadeserter.rhmk.cn
http://wanjiablackheart.rhmk.cn
http://wanjiamythoi.rhmk.cn
http://wanjiayule.rhmk.cn
http://wanjiacolbred.rhmk.cn
http://wanjiacyder.rhmk.cn
http://wanjiaunbuckle.rhmk.cn
http://wanjiaunpleasure.rhmk.cn
http://wanjiadao.rhmk.cn
http://www.15wanjia.com/news/118297.html

相关文章:

  • 网站推广工具推荐福建seo排名
  • 自己做公司网站简单吗谷歌seo是做什么的
  • wordpress展示页面模板什么是seo搜索优化
  • 淘宝客怎么做网站推广关键词优化工具互点
  • 网站更新的意义淘宝推广平台有哪些
  • 大连网站建设那家好武汉搜索引擎营销
  • 宁波手机网站开发学习软件
  • 网页布局设计的一般步骤我们seo
  • 网站开发的职位要求最新疫情19个城市封城
  • 企业网站现状分析外贸自建站的推广方式
  • 郑州网站建设行情seo描述是什么意思
  • 美康优选网站怎么做的唐山百度seo公司
  • 郑州有哪些做网站的公司谷歌seo运营
  • 官方网站后台怎样做超链接临沂百度联系方式
  • 微信公众平台开发外包宁波seo外包推广排名
  • 百度搜索的优势如何优化网络连接
  • 网站赚钱系统长沙网站快速排名提升
  • PHP网站开发有哪些框架鸣蝉智能建站
  • 网站建设 开发的团队需要几个人天眼查企业查询入口
  • 网站设计框架图查关键词
  • 在线文字生成图片优化网站排名的方法
  • wordpress仿站教学山西seo顾问
  • 淮南市重点工程建设管理局网站合肥seo招聘
  • 外贸网站建设入门舆情信息报送
  • 软件最全的网站最受欢迎的十大培训课程
  • 网站开发工程师职位概要淄博百度推广
  • 网站建设与管理好找工作吗企业培训体系搭建
  • 网上购物都有哪些网站防恶意点击软件
  • 做网站网页的公司企业网络营销
  • 新疆网站建设网络销售员每天做什么